开发者

GWT file upload java.security.AccessControlException: access denied (java.io.FilePermission

I have a file upload Servlet and try to store some files as:

try{
    File uploadedFile = new File(UPLOAD_DIRECTORY + fileName);
    File uploadedFile = new File("/"+fileName);
    item.write(uploadedFile);
}
catch (Exception e) {
    e.printStackTrace();
}

After that I get the following error:

java.security.AccessControlException: 开发者_开发知识库access denied (java.io.FilePermission /untitled.html write)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
    at java.security.AccessController.checkPermission(AccessController.java:546)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)

How can I fix it?


You could either make / writable by your app server (which doesn't seem like a great idea to me) or store your uploaded files in another writable location.

File uploadedFile = new File(UPLOAD_DIRECTORY + fileName);
File uploadedFile = new File("/"+fileName);

You also appear to be trying to declare uploadedFile twice. From the error, it looks like either UPLOAD_DIRECTORY is / or you're actually using the second line. Perhaps you just need to supply the right location in UPLOAD_DIRECTORY?

To answer your comment-question about Java policy files:

From Security and Permissions on java.sun.com:

There is one policy file for Java platform installation (system) and an optional policy file for each user. The system policy file is in {java.home}/lib/security/java.policy, and the user policy file is in each user's home directory. The system and user policy files are combined. So for example,there could be a system policy file with very few permissions granted to all users on the system, and individual policy files granting additional permissions to certain users.

See the File Permission section for setting file system permissions in the policy file.

And to reiterate my own comment, you'll also want to pay attention to file system permissions in the OS, control of which will depend on the OS you're using.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜