简体   繁体   English

java.security.AccessControlException:使用Java Web Start拒绝访问

[英]java.security.AccessControlException: access denied using Java Web Start

I am having some issues with accessing files using JWS (Java Web Start). 使用JWS(Java Web Start)访问文件时遇到一些问题。 The program adds a new label and image. 该程序将添加新的标签和图像。 The program runs fine on my local computer but gives me pages of errors when I run the program on my remote server using JWS. 该程序可以在本地计算机上很好地运行,但是当我使用JWS在远程服务器上运行该程序时,却显示错误页面。 Here's a sample of the error: 这是错误的示例:

Exception in thread "AWT-EventQueue-0" java.security.AccessControlException: access denied (java.io.FilePermission add2.png read)
 at java.security.AccessControlContext.checkPermission(Unknown Source)
 at java.security.AccessController.checkPermission(Unknown Source)
 at java.lang.SecurityManager.checkPermission(Unknown Source)

This occurs even after making sure the images have read access. 即使在确保图像具有读取权限之后,也会发生这种情况。

Ideas? 有想法吗?

Like applets, JNLP (webstart) runs at client machine, not at server machine. 像小应用程序一样,JNLP(Webstart)在客户端计算机上运行,​​而不是在服务器计算机上运行。 The client downloads the program from a webpage and runs it at local machine. 客户端从网页下载程序,然后在本地计算机上运行它。 Any references in java.io stuff will point to the local disk file system (there where the code runs), not the remote disk file system (there where the code is been downloaded from) as you seem to expect. 像您期望的那样, java.io所有引用都将指向本地磁盘文件系统(在其中运行代码),而不是远程磁盘文件系统(在其中下载代码的位置)。

You have 2 options: 您有2个选择:

  1. Pack the image in the JAR and use ClassLoader#getResourceAsStream() instead to obtain an InputStream from it. 将图像打包到JAR中,并改用ClassLoader#getResourceAsStream()从中获取InputStream

     ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); BufferedImage image = ImageIO.read(classLoader.getResourceAsStream("add2.png")); 
  2. Put the image in public location in the webserver, so that you can access it by URL (is only a tad slower than having in classpath). 将图像放在Web服务器中的公共位置,以便您可以通过URL访问它(仅比在classpath中慢一点)。

     BufferedImage image = ImageIO.read(new URL("http://example.com/add2.png")); 

That said, regardless of all, using relative paths instead of absolute paths in java.io stuff is a bad idea. 也就是说,无论如何,在java.io中使用相对路径而不是绝对路径是一个坏主意。 Never do this. 永远不要这样做。 It will be dependent on the current working directory, which you have no control over. 它将取决于您无法控制的当前工作目录。

Where is add2.png ? add2.png在哪里? If it's on your local filesystem (as opposed to the server that has the .jnlp file), then this is not allowed, to protect the user's privacy. 如果它在您的本地文件系统上(而不是具有.jnlp文件的服务器),则不允许这样做,以保护用户的隐私。 Also, getting the resource from another web server is not allowed either. 同样,也不允许从另一台Web服务器获取资源。

Remember that JWS and applet code is generally untrusted (unless it's been digitally signed, and accepted by the user). 请记住,JWS和applet代码通常是不受信任的(除非已进行数字签名并为用户所接受)。 So, the default permissions applying to them have to be fairly restrictive. 因此,应用于它们的默认权限必须相当严格。


Edited to add: It seems from the stacktrace that your program is still trying to read the local file, rather than using the URL to the remote server. 编辑添加:从stacktrace看来,您的程序仍在尝试读取本地文件,而不是使用远程服务器的URL。 Make sure your code does not make any references to java.io.File ; 确保您的代码未对java.io.File进行任何引用; this will help you pinpoint any problematic areas of code. 这将帮助您查明任何有问题的代码区域。

Faced similar issue. 面临类似的问题。

Resolved by removing Temporary Internet Files from Control Panel -> Java 通过从控制面板-> Java中删除Internet临时文件来解决

暂无
暂无

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

相关问题 JSP-java.security.AccessControlException:拒绝访问 - JSP - java.security.AccessControlException: access denied 错误:java.security.AccessControlException:访问被拒绝 - Error: java.security.AccessControlException: Access denied java.security.AccessControlException:访问被拒绝的异常 - java.security.AccessControlException: access denied Exception java.security.AccessControlException: 访问被拒绝 (java.io.FilePermission - java.security.AccessControlException: Access denied (java.io.FilePermission java.security.AccessControlException:Java RMI电话目录中的访问被拒绝 - java.security.AccessControlException: access denied in Java RMI Telephone Directory “java.security.AccessControlException:access denied”执行签名的Java Applet - “java.security.AccessControlException: access denied” executing a signed Java Applet Java RMI java.security.AccessControlException:访问被拒绝 - Java RMI java.security.AccessControlException: access denied 具有JDBC的Applet-java.security.AccessControlException:访问被拒绝 - Applet with JDBC - java.security.AccessControlException: access denied 继续得到“java.security.AccessControlException访问被拒绝:”错误 - Keep getting “java.security.AccessControlException access denied:” error 如何解决 Exception::java.security.AccessControlException: access denied in HttpServlet - How to resolve Exception::java.security.AccessControlException: access denied in HttpServlet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM