[英]How to grant applet permission to read system properties?
我有一个Java小程序正在尝试读取http.strictPostRedirect
系统属性 。
该代码不是我的(它是Java的;因此我无法更改它)。 但是您可以在线找到代码:
HttpURLConnection.java :
if (method.equals("POST") && !Boolean.getBoolean("http.strictPostRedirect") && (stat!=307))
{
/* The HTTP/1.1 spec says that a redirect from a POST
* *should not* be immediately turned into a GET, and
* that some HTTP/1.0 clients incorrectly did this.
* Correct behavior redirects a POST to another POST.
* Unfortunately, since most browsers have this incorrect
* behavior, the web works this way now. Typical usage
* seems to be:
* POST a login code or passwd to a web page.
* after validation, the server redirects to another
* (welcome) page
* The second request is (erroneously) expected to be GET
*
* We will do the incorrect thing (POST-->GET) by default.
* We will provide the capability to do the "right" thing
* (POST-->POST) by a system property, "http.strictPostRedirect=true"
*/
...
}
基本的失败来自于调用:
Boolean.getBoolean("http.strictPostRedirect")
这引起了很多人的悲伤 。 显然,我不允许阅读http.strictPostRedirect
系统属性。 尝试读取它会引发AccessControlException :
java.security.AccessControlException: access denied (java.util.PropertyPermission http.strictPostRedirect read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at java.lang.Boolean.getBoolean(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect(Unknown Source)
因此,如果我没有权限读取 系统属性的权限:
如何获得对系统属性的读取权限?
显然,必须有一个设置可以授予我读取系统属性的权限,否则Sun不会拥有透明地尝试访问它的代码。
它是世界范围内的机器吗? 它是域范围的设置吗? 它是机器范围的设置吗? 是每个用户的设置吗? 是每个小程序的设置吗? 它是按调用设置的吗? 它是与特定版本的Java Runtime Engine绑定的设置吗?
tl; dr :如何使不崩溃?
Java确实有一个系统属性列表,比applet无法读取 :
java.class.path
java.home
user.dir
user.home
user.name
我的系统属性 http.strictPostRedirect
不在该列表中。 那我为什么看不懂呢?
这里的“解决方案”是对小程序进行数字签名,然后在出现提示时说服用户确定代码。
Java确实有一个系统属性列表,比applet无法读取:
- java.class.path
- java.home
- user.dir来
- 的user.home
- 用户名
我的系统属性http.strictPostRedirect不在该列表中。 那我为什么看不懂呢?
这是沙盒应用程序的属性的“简短列表”。 无法阅读。 还有很多。 EG禁止user
1 。 只考虑那些是“典型的”。
user
属性的输出。 Name Value
user.country unknown
user.dir unknown
user.home unknown
user.language unknown
user.name unknown
user.timezone unknown
user.variant unknown
显然,必须有一个设置可以授予我读取系统属性的权限,否则Sun不会拥有透明地尝试访问它的代码。
真正。 请参阅上面的修复程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.