1
我有以下HTTPGET()函數:Java小程序的AccessControlException(Apache的HttpClient的)
HttpGet request = new HttpGet(url);
request.setHeader("User-Agent", userAgent);
request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
request.setHeader("Accept-Language", "en-US,en;q=0.5");
if (!cookies.equals(""))
request.setHeader("Cookie", this.cookies);
for (Map.Entry<String, String> header : tempHeaders.entrySet())
{
request.setHeader(header.getKey(), header.getValue());
}
tempHeaders.clear();
HttpResponse response = client.execute(request);
此功能是一個瀏覽器()類的一部分,它包裝了Apache的HttpClient的。當我在Applet查看器中運行Applet時,一切正常。然而,當我嵌入小程序插入到頁面中,我得到以下異常:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:80" "connect,resolve")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at sun.plugin2.applet.SecurityManagerHelper.checkConnectHelper(Unknown Source)
at sun.plugin2.applet.AWTAppletSecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:178)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
**at vidinstant.HttpBrowser.Get(HttpBrowser.java:60)**
at vidinstant.ServerThread$1.run(ServerThread.java:201)
at vidinstant.ServerThread$1.run(ServerThread.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at vidinstant.ServerThread.GetLink(ServerThread.java:196)
at vidinstant.ServerThread.run(ServerThread.java:95)
你可以看到異常的「源」是在瀏覽器的班線60,更確切地說,它是該從代碼上面摘錄行:
HttpResponse response = client.execute(request);
我有自簽名的.jar和清單文件具有行「權限:所有的權限」的小程序在裏面。
爲什麼我得到這個異常,爲什麼拒絕訪問?運行applet的用戶在瀏覽器中單擊允許並不阻止,但它仍然不起作用。 Apache的庫.jars是否也必須簽名?他們是否需要在他們的清單中擁有「全能」?如何獲得運行這些功能的權限,而不需要用戶不得不擺弄他們的Java策略文件?