Java小程序的权限 [英] Java Applet Permissions

查看:400
本文介绍了Java小程序的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把那里的用户从他们的硬盘驱动器文件中的基本小程序,它读取该文件的第一行,并将其关闭给JavaScript的一些额外的preprocessing,然后当你点击一个按钮,它试图通过HTTP POST请求上传该文件。我发现了一个很基本的开源的小程序上传,我复制和修改,对于最后的位文件。

I've put together a basic applet where the user selects a file from their hard drive, it reads the first line of this file and passes that off to JavaScript for some additional preprocessing, and then when you click a button it tries to upload that file through an HTTP POST request. I found a very basic open source applet for uploading files that I copied and modified for this last bit.

麻烦的是,虽然,它完全不是那么回事。现在看来似乎很好运行,但后来我碰到与权限有关两方面的障碍。 Java控制台的消息说,该小程序已经拒绝访问在以下两个权限错误:

The trouble is, though, it doesn't quite work. It seems like it's running fine, but then I run into two snags related to permissions. The messages in the Java Console say that the applet had access denied errors on the following two permissions:

java.lang.RuntimePermission setFactory
java.io.FilePermission read

我觉得这是奇怪,因为我以为我已经获准的小程序已经在我的自签名选项,在NetBeans检查建造它,然后点击确认在浏览器中的小安全弹出。

I find this strange, because I thought I had granted permission to the applet already when I built it with the "self-signed" option checked in NetBeans, and then clicked to confirm the little security pop-up in the browser.

同样,我codeD自己,它读取该文件,传递给JavaScript正常工作的第一行的一部分。这是一个pretty明确的指标,该小程序能够从本地文件系统读取!麻烦不启动,直到我真正尝试启动上传。有一点要注意,我想,在上传过程似乎在一个新的线程中运行,而它的其余部分,而无需创建线程的主类所有运行。

Also, the part that I coded myself, where it reads the file and passes the first line on to JavaScript works fine. This is a pretty clear indicator that the applet is able to read from the local file system! The trouble doesn't start until I actually try to start the upload. One thing to note, I suppose, is that the upload process seems to run in a new thread, whereas the rest of it all runs in the main class without creating threads.

我是新手总Java和所知甚少在Java线程;我需要的权限传递到这个新的线程不知何故?或东西的效果呢?
先谢谢了。

I am a total novice to Java and know very little about threads in Java; do I need to pass the permissions onto this new thread somehow? Or something to that effect? Thanks in advance.

推荐答案

您可能要问了安全管理器(code,而不是管理员)允许做一个特权操作。由于各种原因,它不是一般的小程序,以便能够打开本地文件好事,所以它的守卫pretty严重。

You probably need to ask the security manager (code, not administrator) for permission to do a privileged operation. For various reasons, it's not generally a good thing for an applet to be able to open a local file, so it's guarded pretty heavily.

基本的关键是要叫在AccessController.doPrivileged()并有一个的的Java牧场常见问题就可以很好的小教程

The basic key is to call AccessController.doPrivileged() and there's a good little tutorial on it at the Java Ranch FAQ.

这篇关于Java小程序的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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