签名的 Java 小程序在 Safari 中没有获得权限 [英] Signed Java applet doesnt get permissions in Safari

查看:31
本文介绍了签名的 Java 小程序在 Safari 中没有获得权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个签名的 Java 小程序(使用自签名证书),它必须访问用户的文件系统.我必须这样做,所以请不要回复你不应该这样做":)

I've got a signed java applet (using a self-signed-certificate) which has to access the user's file system. I have to do it, so please no replies ala "you shouldn't do it" :)

问题是,当我从 Firefox 3.0/Mac 执行 Applet 时,一切都按预期工作,我可以正常访问所有内容.

The thing is, when I execute the Applet from Firefox 3.0 / Mac, everything works as desired, I get all access just as it should.

当我使用 Safar 4/Mac 时,我无法访问.我特别有问题的那一行是 System.getProperty() (虽然当我把它存根时,FS 访问也不起作用)

When I use Safar 4 / Mac, I don't get access. The line I especially have problems with is System.getProperty() (although when I stub that out, the FS access doesn't work either)

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 浏览器...

As I said, this works perfectly on Firefox. Gotta check Windows Browser today...

有什么想法吗?

推荐答案

编译 jar 并对其进行签名后,您应该运行 -verify 选项以确保其正确签名.

Once you have your jar compiled and signed you should run the -verify option to ensure its signed properly.

如果验证没问题,请查看浏览器上安装的证书.我没有在 Safari only IE 中做过任何事情,但我想有一个类似于 IE 的地方.您至少可以在其中查看已安装的证书.我会验证证书是否已安装.

If the verification is ok look at the installed certificates on your browsers. I haven't done anything in Safari only IE, but I imagine there is a place similar to I.E. where you can at least view the installed certificates. I would verify the certificate is installed.

还要确保您的代码在特权块中运行.

Also make sure your code is running in a privileged block.

 String home = System.getProperty("user.home");

在 1.4 或更高版本中总是会抛出错误.除非您已编辑所有权限的 java.policy 文件

will always throw an error in 1.4 or higher. Unless you have edited the java.policy file for All Permissions

尝试将它与您签名的 jar 结合使用.

Try using this in combination with your signed jar.

 String home = (String) AccessController.doPrivileged(new PrivilegedAction() 
 {
      public Object run() 
      {
     return System.getProperty("user.home");
      }
 });

这篇关于签名的 Java 小程序在 Safari 中没有获得权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆