列出已签名小程序的本地目录
以下小程序被编译并打包到 jar 中,然后使用自签名证书进行签名。
import java.applet.Applet;
import java.io.File;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
public class Test extends Applet {
private static final long serialVersionUID = -3127185193501384816L;
private final class DirectoryLister implements PrivilegedAction<File[]> {
private final String attachmentsFolder;
private DirectoryLister(String attachmentsFolder) {
this.attachmentsFolder = attachmentsFolder;
}
public File[] run() {
return new File(attachmentsFolder).listFiles();
}
}
public File[] getFiles() throws PrivilegedActionException {
String attachmentsFolder = getParameter("attachmentsFolder");
if (attachmentsFolder != null) {
return AccessController.doPrivileged(new DirectoryLister(
attachmentsFolder));
}
return null;
}
}
Applet 实例化如下:
<applet id="applet"
code="Test"
archive="applet.jar">
<param name="attachmentsFolder"
value="c:/test" />
</applet>
Applet 使用如下:
var files = applet.getFiles();
for (var file in files) {
// Do something to file.
}
ff。 遇到错误:
java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation.CallMethod(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
at sun.plugin.liveconnect.PrivilegedCallMethodAction.run(Unknown Source)
... 4 more
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission c:\test read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.list(Unknown Source)
at java.io.File.listFiles(Unknown Source)
at Test$DirectoryLister.run(Test.java:20)
at Test$DirectoryLister.run(Test.java:1)
at java.security.AccessController.doPrivileged(Native Method)
at Test.getFiles(Test.java:28)
... 14 more
这导致我询问是否仍然需要在 Java 主目录中的配置文件之一中显式授予权限才能读取 c:/test? 如果是这样,有人能给我指点如何执行此操作的指南吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然是缓存问题。 清除所有缓存并重新构建/重新部署解决了问题。 即,不需要额外的权限设置。
Caching problem apparently. Clearing all caches and re-building/re-deploying solved the problem. I.e., no additional perms set-up needed.