简体   繁体   English

Applet中的Java安全性AccessControlException

[英]Java Security AccessControlException in Applet

I'm running into an issue with my applet. 我的小程序遇到问题。 It's supposed to take a url and parse the html there to construct an image. 应该使用一个URL并在那里解析html来构建图像。 I've gotten it to work on my eclipse debugger. 我已经将其用于我的Eclipse调试器。 However, when I try to use it on a web browser I get an AccessControlException. 但是,当我尝试在Web浏览器上使用它时,会出现AccessControlException。 I'm using the jEditorPane.setPage(url) method. 我正在使用jEditorPane.setPage(url)方法。 Currently both the applet and url are hosted on my localhost and I did self sign the applet. 当前,小程序和URL都托管在我的本地主机上,并且我对小程序进行了自签名。

java.lang.RuntimeException: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:80 connect,resolve)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown Source)
    at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    at javax.swing.JEditorPane.getStream(Unknown Source)
    at javax.swing.JEditorPane.setPage(Unknown Source)
    at javax.swing.JEditorPane.setPage(Unknown Source)
    at com.mindbody.printer.PrinterApplet.print(PrinterApplet.java:24)
    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.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.JSClassLoader.invoke(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass$MethodInfo.invoke(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass$MemberBundle.invoke(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass.invoke0(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass.invoke(Unknown Source)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$DefaultInvocationDelegate.invoke(Unknown Source)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

An unsigned applet is only allowed to connect to the host it came from. 未签名的小程序仅允许连接到它来自的主机。 And even for signed applets, in methods invoked from code less trusted (like the javascript code here), it has only the rights of this code (or more exactly, the intersection of all rights). 甚至对于签名的applet,在从不太受信任的代码(例如此处的javascript代码)调用的方法中,它也仅具有此代码的权限(或更确切地说,是所有权限的交集)。

To be able to do everything for which your applet has the rights, wrap your rights-needing code with AccessController.doPrivileged(...) . 为了能够执行您的小程序所拥有的所有权限,请使用AccessController.doPrivileged(...)包装需要权限的代码。 (But make sure that this can not do dangerous things when given malicious arguments from outside.) (但请确保从外部给出恶意论点时,这样做不会做危险的事情。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM