[opencms-dev] Access denied on writeFile() - prior solutions ineffective

Kenny MacLeod kenny.mcleod at kizoom.com
Tue Apr 20 19:14:00 CEST 2004


Hi folks,

I found this same problem detailed in two previous posts to this list, but
the suggested solutions do not work (nor did they work for the original
posters).

The problem concerns Access Denied exceptions being thrown by the
writeFile() method of the CmsObject class.  An example code fragment (where
"cms" is the CmsObject) would be:

  cms.getRequestContext().setCurrentProject(4);
  CmsFile cmsFile = (CmsFile) cms.createResource(folderPath, fileName,
"plain");
  cmsFile.setContents(fileData);        
  cms.writeFile(cmsFile);

The final line throws the following exception:

    [exec] com.opencms.core.CmsException: 1 Access denied. Detailed error:
[com.opencms.file.mySql.CmsResourceBroker] /test/file.txt
    [exec]      at
com.opencms.file.genericSql.CmsResourceBroker.writeFile(CmsResourceBroker.ja
va:7475)
    [exec]      at com.opencms.file.CmsObject.writeFile(CmsObject.java:3863)


As you can see, I can create the CmsResource OK - if I go to the OpenCMS
explorer at this point, and select the Offline project, I can see the file
there, marked as locked, as expected.  But writeFile() still throws that
exception.

The previous suggested solution was to incorporate the call to
setCurrentProject(), but as you can see, that's what I've done, and it
doesn't fix the problem.  If setCurrentProject() is removed, then the code
fails during createResource() instead, which is what I would expect.

So, my question is, what other changes do I have to make to the code to
allow writeFile() to succeed?  I notice from the source of the
com.opencms.workplace.CmsEditor class that writeFile() is used successfully.
So what's the secret?

Regards,


Kenny




More information about the opencms-dev mailing list