简体   繁体   English

Java安全访问控制异常

[英]Java security access control exception

I am trying to execute this program, http://java.sun.com/developer/technicalArticles/ThirdParty/WebCrawler/WebCrawler.java The program compiles without any error after i referred this page, http://www.velocityreviews.com/forums/t146972-web-crawler.html 我正在尝试执行此程序, http://java.sun.com/developer/technicalArticles/ThirdParty/WebCrawler/WebCrawler.java在我引用此页面http://www.velocityreviews.com之后,该程序编译无误/forums/t146972-web-crawler.html

But while executing using the command "appletviewer WebCrawler.html" i get this exception.. 但是在使用命令“ appletviewer WebCrawler.html”执行时,出现此异常。

Exception in thread "Thread-4" 
java.security.AccessControlException:access denied(java.net.SocketPermission java.sun.com:80 connect,resolve)

at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)

at java.security.AccessController.checkPermission(AccessController.java:546)

at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)

at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)

at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)

at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)

at sun.net.www.http.HttpClient.New(HttpClient.java:306)

at sun.net.www.http.HttpClient.New(HttpClient.java:323)

at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:860)

at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)

at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:726)

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)

at java.net.URL.openStream(URL.java:1010)

at WebCrawler.robotSafe(WebCrawler.java:139)

at WebCrawler.run(WebCrawler.java:235)

at java.lang.Thread.run(Thread.java:619)

How do i make it work.? 我如何使其工作。

By default, an applet may only connect to the same server + port from which it is located. 默认情况下,小程序只能连接到它所在的同一服务器+端口。 You could do one of the following: 您可以执行以下操作之一:

  1. Convert the app into an application, removng the security restriction 将应用程序转换为应用程序,消除安全限制
  2. Use a trusted/signed applet 使用受信任/已签名的小程序

Also you could have a look at configuring the crossdomain for the applet, see: 您也可以看看如何为applet配置跨域,请参阅:

http://weblogs.java.net/blog/2008/05/28/java-doodle-crossdomainxml-support http://weblogs.java.net/blog/2008/05/28/java-doodle-crossdomainxml-support

It's pretty straight forward to self-sign an applet (which you can do for free). 自签名小程序非常简单(您可以免费签名)。 If you don't sign the applet you'll only get bare minimum security access and won't give access to the sockets. 如果不对小程序进行签名,则只会获得最低限度的安全性访问权限,并且不会授予套接字访问权限。

Simple 3 step guide is here: 简单的3步指南在这里:

http://www.narendranaidu.com/2007/11/3-easy-steps-to-self-sign-applet-jar.html http://www.narendranaidu.com/2007/11/3-easy-steps-to-self-sign-applet-jar.html

or a more in-depth explination: http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html 或更深入的探讨: http : //java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html

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

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