AccessControlException when attempting to delete a

2019-06-06 18:09发布

问题:

We have a java web service application that uses log4j to do logging. An exception gets thrown when log4j tries to delete its rolling log files

Exception:java.security.AccessControlException: access denied
(java.io.FilePermission /var/opt/SUNWappserver/domains/domain1/
applications/j2ee-modules/ourwebservice/WEB-INF/logs/IMWrapper.log.10 delete)

When we do an ls in the directory the service account does have access to read and write to the files and the directory.

From some initial Googling it seems we may have to change the security.policy file to allow the service to delete files. Any suggestions?

回答1:

As a quickfix you can start the application using a policy file with the following content:

grant {
    permission java.security.AllPermission;
};

using the command line option:

-Djava.security.policy=file:<your_policy_file>

See this link for more info how to configure your policy file to get the required access rights.

EDIT: I'm sorry, but I don't know how to configure your web application how to use that policy file, but at least the link should hint you towards getting the required rights...