我有一个签名的java小程序(使用自签名证书),它必须访问用户的文件系统。我必须这样做,所以请不要回复“你不应该这样做”:)
问题是,当我从 Firefox 3.0/Mac 执行 Applet 时,一切都按预期工作,我获得了应有的所有访问权限。
当我使用 Safar 4/Mac 时,我无法访问。我特别遇到问题的行是 System.getProperty() (尽管当我将其 stub 时,FS 访问也不起作用)
String home = System.getProperty("user.home");
我得到的异常如下:
java.security.AccessControlException: access denied (java.util.PropertyPermission user.home read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
at java.security.AccessController.checkPermission(AccessController.java:427)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
at java.lang.System.getProperty(System.java:628)
at de.samedi.searcher.Searcher.<init>(Searcher.java:49)
at de.samedi.searcher.Applet.getSearcher(Applet.java:193)
at de.samedi.searcher.Applet.getSearcher(Applet.java:187)
at de.samedi.searcher.Applet.addPatient(Applet.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.plugin.javascript.invoke.JSInvoke.invoke(JSInvoke.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.plugin.javascript.JSClassLoader.invoke(JSClassLoader.java:44)
at sun.plugin.liveconnect.PrivilegedCallMethodAction.run(SecureInvocation.java:658)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation$2.run(SecureInvocation.java:214)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation.CallMethod(SecureInvocation.java:192)
at sun.plugin.liveconnect.SecureInvocation.access$300(SecureInvocation.java:52)
at sun.plugin.liveconnect.SecureInvocation$CallMethodThread.run(SecureInvocation.java:123)
正如我所说,这在 Firefox 上完美运行。今天得检查一下 Windows 浏览器...
有什么想法吗?
最佳答案
编译并签名 jar 后,您应该运行 -verify 选项以确保其正确签名。
如果验证正常,请查看浏览器上安装的证书。 我没有在 Safari 中只对 IE 做过任何事情,但我想有一个类似于 IE 的地方。您至少可以在其中查看已安装的证书。我将验证证书是否已安装。
还要确保您的代码在特权 block 中运行。
String home = System.getProperty("user.home");
在 1.4 或更高版本中总是会抛出错误。除非您已经编辑了所有权限的 java.policy 文件
尝试将其与您签名的 jar 结合使用。
String home = (String) AccessController.doPrivileged(new PrivilegedAction()
{
public Object run()
{
return System.getProperty("user.home");
}
});
关于java - 签名的 Java 小程序在 Safari 中未获得权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1211342/