如何传递通过JNLP任意系统属性,其值可能会更改为一个签名的Java的RIA(小程序,在webstart)? [英] How can I pass arbitrary system properties whose values may change to a signed Java RIA (applet, webstart) via JNLP?

查看:435
本文介绍了如何传递通过JNLP任意系统属性,其值可能会更改为一个签名的Java的RIA(小程序,在webstart)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于严格的安全限制在 7u51 ,由于在一月份,我想我签字JNLP文件。

Due to tighter security restrictions in 7u51, due in January, I'm trying to sign my JNLP file.

我们的应用程序需要设置一定的自定义系统属性,和这些属性的值取决于小程序被部署在不同的。我想,以避免重新签署包含每个部署的JNLP模板JAR。

Our application requires certain custom system properties to be set, and the values of some of those properties are different depending on where the applet is being deployed. I would like to avoid having to re-sign the JAR containing the JNLP template for each deployment.

推杆的幼稚的做法<属性名=我的螺旋桨VALUE =*/> 的JNLP模板不起作用。

The naive approach of putting <property name="my-prop" value="*"/> in the JNLP template does not work.

即使&LT;属性名=我的螺旋桨VALUE =固定值/&GT; 在模板中,我有时会收到一个对话框说这应用程序将执行不安全的操作是否要继续:?

Even with <property name="my-prop" value="fixed-value"/> in the template, I sometimes get a dialog saying "This application is going to perform an insecure operation. Do you want to continue?":

什么是在传递系统属性一个签名的Java的RIA?

What's the right way to pass system properties in to a signed Java RIA?

推荐答案

在这两方面,您的应用程序将需要添加一些琐碎code在启动时被执行,以解决这两个问题。

On both counts, your application will need to add some trivial code to be executed at start-up, in order to work around these two issues.

借助 JNLP规范说:

据预计,一个JNLP客户端将黑名单(或限制)某些JNLP元素和参数值,如Java的虚拟机ARGS或名称属性和价值,以维护安全。确切名单是由个人JNLP客户端实现。

It is expected that a JNLP Client will blacklist (or restrict) certain jnlp elements and argument values such as "java-vm-args" or property "name" and "value" to maintain security. The exact list is up to the individual JNLP Client implementations.

事实上,Oracle实施(至少在7u45)不黑名单&LT的属性,属性/&GT; 元素 - 它不能使用通配符。我一直无法找到这个决定背后的推理,但它就在那里。

In fact, the Oracle implementation (at least in 7u45) does blacklist the value attribute of the <property/> element -- it cannot be wildcarded. I've been unable to locate any reasoning behind this decision, but there it is.

该Webstart的解决方法允许任意属性的名称,以及价值;该applet变通要求属性的名称为code-签约时间才能知道。

The webstart work-around allows arbitrary property names as well as values; the applet work-around requires that the names of the properties be known at code-signing time.

在您的JNLP文件,包括一些通配符参数:

In your JNLP file, include a number of wildcard arguments:

<application-desc main-class="com.example.YourMainClass">
  <argument>*</argument>
  <argument>*</argument>
</application-desc>

在您的应用程序的方法,解析这些参数,并使用它们复制到系统属性<一个href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#setProperty%28java.lang.String,%20java.lang.String%29\"相对=nofollow> System.setProperty() ,跳过仍然有文字值参数*。我建议简单地分割每个参数的中第一次出现=。 (如果你的应用程序已经接受常规参数,以及,你就必须获得更多的创造性一点。)

In your application's main method, parse these arguments and copy them in to system properties using System.setProperty(), skipping over arguments that still have the literal value "*". I recommend simply splitting each argument on the first occurrence of "=". (If your application already takes regular arguments as well, you'll have to get a bit more creative.)

在您的JNLP文件,包括定义需要被设置系统属性参数:

In your JNLP file, include parameters defining the system properties that need to be set:

<applet-desc main-class="com.example.YourMainClassApplet">
  <param name="SYS_PROPERTY_PARAMETERS" value="prop1,prop2"/>
  <param name="prop1" value="*"/>
  <param name="prop2" value="*"/>
</applet-desc>

在您 Applet.init() 方法,获得 SYS_PROPERTY_PARAMETERS 参数的值,并遍历它来获得每个参数的值。如果不是字面*,将其复制到系统属性使用 System.setProperty()

In your Applet.init() method, get the value of the SYS_PROPERTY_PARAMETERS parameter, and iterate over it to get the value of each parameter. If it is not the literal "*", copy it to a system property using System.setProperty().

这是在Oracle插件一个错误由使用触发LiveConnect的的(Java的&LT; - > JavaScript的交互)。

This is a bug in the Oracle plugin that is triggered by the use of LiveConnect (Java <-> JavaScript interaction).

preFIX所有系统属性通过&LT设置;物业/&gt;中。JNLP的JNLP元素与

Prefix all system properties set via <property/> elements in the JNLP with "jnlp.":

<property name="jnlp.my-prop" value="fixed-value"/>

然后在你的应用程序的的main() Applet.init()方法,遍历的 <副本code> System.getProperties() ,如果​​属性名称与JNLP。,复制的价值所在与扒掉了preFIX相同名称的属性。 (迭代副本是必要的,以避免 ConcurrentModificationException的

Then in your application's main() or Applet.init() method, iterate over a copy of System.getProperties() and, if the property name starts with "jnlp.", copy its value into a property of the same name with that prefix stripped off. (Iterating over the copy is necessary to avoid a ConcurrentModificationException.)

最后,如果在用于属性值填充可能会导致将JNLP文档中的其它元素的属性的过程中被重新排序,这可能会导致将JNLP模板验证失败。 (解析与DOM解析器的JNLP,在通配符灌装,流回来了使用 StreamResult 这是可能发生的一种方法。)例如,我有这两个多-attribute元素,以及元素的顺序必须匹配

Finally, if your process of filling in the values for the properties could cause attributes of other elements in the JNLP document to be reordered, this may cause the JNLP template validation to fail. (Parsing the JNLP with a DOM parser, filling in the wildcards, and streaming it back out using StreamResult is one way this could happen.) For example, I had these two multi-attribute elements, and the order of the elements had to match:

<jnlp codebase="*" spec="1.0+">
<j2se java-vm-args="-Xms256M -Xmx512M -XX:MaxPermSize=256m" version="1.6+"/>

这篇关于如何传递通过JNLP任意系统属性,其值可能会更改为一个签名的Java的RIA(小程序,在webstart)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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