2011-03-16 59 views
0

我遇到了一個問題,我的小程序。它應該採取一個網址並解析那裏的html來構建一個圖像。我已經得到它在我的eclipse調試器上工作。但是,當我嘗試在Web瀏覽器上使用它時,我得到一個AccessControlException。我正在使用jEditorPane.setPage(url)方法。目前,applet和url都託管在我的本地主機上,並且我自己對applet進行了簽名。Java安全AccessControlException在Applet中

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) 

回答

0

的簽名Applet只允許連接到它來自主機。甚至對於已簽名的applet,在從不太可信的代碼(如JavaScript代碼)中調用的方法中,它只具有此代碼的權限(更確切地說,是所有權利的交集)。

爲了能夠完成小程序擁有的所有權利,請將您的權限編碼包含在AccessController.doPrivileged(...)中。 (但要確保在外部發出惡意論點時不會做危險的事情。)

+0

真棒,工作,謝謝。 – Acquire 2011-03-17 16:41:04

相關問題