如何授予applet读取系统属性的权限?

时间:2013-09-27 17:35:12

标签: java applet system-properties

我有一个试图阅读http.strictPostRedirect 系统属性的Java小程序。

代码不是我的(它是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")

导致了lot of people grief。显然我不是允许阅读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将没有透明地尝试访问它的代码。

这是一台机器全球设置吗?这是一个域范围的设置吗?它是机器范围的设置吗?这是每用户设置吗?这是一个per-applet设置吗?它是一个每次调用设置吗?它是与 Java运行时引擎的特定版本绑定的设置吗?

tl; dr :如何不崩溃?

读取系统属性

Java确实有list of system properties than at applet cannot read

  • java.class.path
  • java.home
  • user.dir
  • user.home
  • user.name

我的系统属性http.strictPostRedirect不在该列表中。那为什么我不能读它呢?

另见

1 个答案:

答案 0 :(得分:1)

这里的'修复'是对applet进行数字签名,然后在提示时说服用户确认代码。


  

Java确实有一个系统属性列表,而不是applet无法读取的内容:

     
      
  • java.class.path
  •   
  • java.home
  •   
  • user.dir来
  •   
  • 的user.home
  •   
  • user.name
  •   
     

我的系统属性http.strictPostRedirect不在该列表中。那为什么我不能读它呢?

这是沙盒应用的属性“短名单”。无法阅读。还有更多。例如。 user下的任何内容都不允许 1 。只要考虑那些“典型”。

  1. 在沙盒应用中输出7 user properties

  2. Name            Value
    user.country    unknown
    user.dir        unknown
    user.home       unknown
    user.language   unknown
    user.name       unknown
    user.timezone   unknown
    user.variant    unknown
    

      

    显然必须有一个允许我读取系统属性的设置,否则Sun将没有透明地尝试访问它的代码。

    真。请参阅上面的修复程序。


相关问题