java.security.AccessControlException:unsigned applet中的访问被拒绝(java.io.FilePermission)

时间:2015-03-22 07:43:12

标签: java security applet local-files

我在使用未签名的applet访问本地文件时遇到问题。我已经阅读了很多不同的资源(oracle,sun文档,论坛,包括stackoverflow),他们都告诉我,我可以修复安全策略,而不是签署applet。

我想做的是播放.wav文件。为简化起见,我已将所有文件放在同一目录中:

D:\<username>\IdeaProjects\SimpleAppletTest\out\production\SimpleAppletTest

在这个目录中我有下一个文件:

01.wav
SimpleApplet.class
SimpleApplet.html
.java.policy

我使用.java.policy创建的文件policytool具有以下内容:

/* AUTOMATICALLY GENERATED ON Fri Mar 13 20:44:28 MSK 2015*/
/* DO NOT EDIT */

grant codeBase "file:/D:/<username>/IdeaProjects/-" {
  permission java.io.FilePermission "<<ALL FILES>>", "read";
};

此外,我已将下一个字符串(第三个)添加到位于java.security的{​​{1}}:

${java.home}/lib/security/

但是当我在Internet Explorer中启动我的applet时(请不要开玩笑,我只是用它来测试我的applet)我在java-console中有下一个stacktrace:

policy.url.1=file:${java.home}/lib/security/java.policy
policy.url.2=file:${user.home}/.java.policy
policy.url.3=file:/D:/<username>/IdeaProjects/SimpleAppletTest/out/production/SimpleAppletTest/.java.policy

...

Java Plug-in 11.31.2.13
Using JRE version 1.8.0_31-b13 Java HotSpot(TM) Client VM
User home directory = D:\<username>

applet的代码:

Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied ("java.io.FilePermission" "D:\<username>\IdeaProjects\SimpleAppletTest\out\production\SimpleAppletTest\01.wav" "read")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
    at SimpleApplet$1$1.run(SimpleApplet.java:56)
    at java.security.AccessController.doPrivileged(Native Method)
    at SimpleApplet$1.run(SimpleApplet.java:33)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

我的JDK和JRE版本:

 AccessController.doPrivileged(new PrivilegedAction() {
                    public Object run() {
                        File audioSource = new File(
                                "D:\\<username>\\IdeaProjects\\SimpleAppletTest\\out\\production\\SimpleAppletTest",
                                "01.wav");

                        FilePermission perm = new FilePermission(audioSource.getAbsolutePath(), "read");

                        SecurityManager appsm = System.getSecurityManager();
                        appsm.checkPermission(perm);

                        return null;
                    }
                });

实际上我有Windows 7。而且,我只是尝试播放.wav文件没有签名我的applet。

0 个答案:

没有答案