java.security.AccessControlException:使用 Java Web Start 访问被拒绝
我在使用 JWS (Java Web Start) 访问文件时遇到一些问题。该程序添加了新的标签和图像。该程序在我的本地计算机上运行良好,但当我使用 JWS 在远程服务器上运行该程序时,会出现错误页面。以下是错误示例:
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)
即使在确保图像具有读取访问权限后也会发生这种情况。
有想法吗?
I am having some issues with accessing files using 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. 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
与小程序一样,JNLP(Webstart)在客户端计算机上运行,而不是在服务器计算机上运行。客户端从网页下载程序并在本地计算机上运行。 java.io 中的任何引用都将指向本地磁盘文件系统(代码运行的地方),而不是远程磁盘文件系统(代码下载的地方),正如您所看到的那样预计。
您有 2 个选择:
将映像打包到 JAR 中并使用
ClassLoader#getResourceAsStream()
来从中获取InputStream
。将图像放在网络服务器中的公共位置,以便您可以通过 URL 访问它(仅比类路径中慢一点)。
也就是说,无论如何,在 java.io 中使用相对路径而不是绝对路径都是一个坏主意。永远不要这样做。它将依赖于当前的工作目录,您无法控制该目录。
Like applets, JNLP (webstart) runs at client machine, not at server machine. 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.You have 2 options:
Pack the image in the JAR and use
ClassLoader#getResourceAsStream()
instead to obtain anInputStream
from it.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).
That said, regardless of all, using relative paths instead of absolute paths in java.io stuff is a bad idea. Never do this. It will be dependent on the current working directory, which you have no control over.
add2.png
在哪里?如果它位于您的本地文件系统上(而不是具有.jnlp
文件的服务器),则不允许这样做,以保护用户的隐私。此外,也不允许从其他 Web 服务器获取资源。请记住,JWS 和小程序代码通常是不受信任的(除非它经过数字签名并被用户接受)。因此,适用于它们的默认权限必须相当严格。
编辑添加:从堆栈跟踪看来,您的程序仍在尝试读取本地文件,而不是使用远程服务器的 URL。确保您的代码没有对 java.io.File 进行任何引用;这将帮助您查明任何有问题的代码区域。
Where is
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. Also, getting the resource from another web server is not allowed either.Remember that JWS and applet code is generally untrusted (unless it's been digitally signed, and accepted by the user). 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. Make sure your code does not make any references to
java.io.File
; this will help you pinpoint any problematic areas of code.您的 JAR 必须签名。阅读本教程:
http://www.mobilefish.com/tutorials/java/java_quickguide_keytool。 html
http://www- Personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html
http://faq.javaranch.com/java/HowCanAnAppletReadFilesOnTheLocalFileSystem
Your JAR must be signed. Read this tutorials:
http://www.mobilefish.com/tutorials/java/java_quickguide_keytool.html
http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html
http://faq.javaranch.com/java/HowCanAnAppletReadFilesOnTheLocalFileSystem
面临类似的问题。
通过从控制面板 -> 删除临时 Internet 文件来解决爪哇
Faced similar issue.
Resolved by removing Temporary Internet Files from Control Panel -> Java