访问被拒绝(java.net.SocketPermission 127.0.0.1:8080连接,解决) [英] access denied (java.net.SocketPermission 127.0.0.1:8080 connect,resolve)

查看:2981
本文介绍了访问被拒绝(java.net.SocketPermission 127.0.0.1:8080连接,解决)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java小程序插入位于 HTTP一个简单的HTML页面上://本地主机:8080 / index.html的

I have a Java Applet inserted on a simple HTML page located at http://localhost:8080/index.html:

<applet id="applet" code="SomeCode.class" archive="lib.jar" Width="1" Height="1"></applet>

Java小程序,其外观类似于下面的code的方法:

The Java Applet has a method that looks similar to the code below:

public void PostStuffToServer() {
  String server = "http://localhost:8080/PostHandler.ashx";
  URL u = new URL(server);
  URLConnection con = u.openConnection();
  con.setDoOutput(true);
  con.getOutputStream().write(stream.toByteArray());
  con.connect();
}

当我从JavaScript执行的applet code,像这样:

When I execute the applet code from JavaScript like so:

obj = document.getElementById('applet');
obj.getClipboardImageURL();

我收到以下错误:

I get the following error:

访问被拒绝(java.net.SocketPermission 127.0.0.1:8080连接,解决)

这似乎是Java的code解析域名的本地主机的为它的等效IP地址,并因此引发跨域安全约束。它工作正常,当我从 http://127.0.0.1:8080/index.html 执行相同的code 。该lib.jar文件进行签名。

It seems like the Java code resolves the domain localhost to its equivalent IP address and therefore raises a cross domain security restrain. It works fine when I execute the same code from http://127.0.0.1:8080/index.html. The lib.jar file is signed.

反正有没有避免这种情况?

Is there anyway to avoid this?

推荐答案

我安装Java 6更新22.我的小程序已经在线了好几年,没有报告的错误后遇到同样的问题。当我降级到版本6更新21,一切都运行完美。我的小程序未签名。

I encountered the same problem after installing Java 6 Update 22. My applet has been online for several years with no reported errors. When I downgrade to version 6 Update 21, everything works perfect. My applet is not signed.

解决方案:
我花了哈,同时查找问题的原因。其实在我的情况有导致安全错误几个因素。这个问题是由crossdomain.xml文件解决。 Java小程序试图下载跨域文件,失败,甚至没有理会在java控制台(调试级别5)显示错误。 Java的试图从我的域名的IP地址下载文件(HTTP://ip-address/crossdomain.xml),而不是我的网站的根目录下(HTTP://domain-name/crossdomain.xml)。我想这是安全方面的更好吗?然后我不得不配置Web服务器暴露的IP地址crossdomainfile。在我的情况我已删除出于安全原因,在国际空间站的默认网站,必须创建一个新的网站。后来我发现,Java小程序没有与跨域文件,我带闪光灯使用工作:

SOLUTION: It took me ha while to find the cause of the problem. Actually in my case there were several factors causing the security error. The problem was solved by the crossdomain.xml file. The Java applet tried to download the crossdomain file, failed, and did not even bother to display an error in the java console (debug level 5). Java tried to download the file from the ip adress of my domain (http://ip-address/crossdomain.xml), and not the root of my website (http://domain-name/crossdomain.xml). I guess it is better for the security aspect? I then had to configure the webserver to expose the crossdomainfile on the IP address. In my case I have removed the default website in ISS for security reasons, and had to create a new website. I then discovered that the java applet did not work with the crossdomain files i use with flash:

<?xml version="1.0"?>
<cross-domain-policy>
   <site-control permitted-cross-domain-policies="master-only"/>
   <allow-http-request-headers-from domain="*" headers="*"/>
   <allow-access-from domain="*" />
</cross-domain-policy>

我不得不删除站点控制和允许-http请求报头 - 从xml文件节点,以使该小程序的工作。

I had to remove the site-control and allow-http-request-headers-from nodes from the xml file in order to make the applet work.

这篇关于访问被拒绝(java.net.SocketPermission 127.0.0.1:8080连接,解决)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆