I have an application which really should be installed, but does work fine when deployed using JNLP.
我有一个应该安装的应用程序,但在使用JNLP部署时可以正常工作。
However, it would seem that some Java functions such as Runtime.exec
don't work using the default security options.
但是,似乎某些Java函数(如Runtime.exec)无法使用默认安全选项。
I would like to therefore disable UI functionality that relies upon such functions.
因此,我想禁用依赖于此类功能的UI功能。
So my question is, how do I detect at runtime whether certain functions are available or not?
所以我的问题是,如何在运行时检测某些功能是否可用?
The case study, here of course, is Runtime.exec
.
案例研究,当然是Runtime.exec。
3 个解决方案
#1
1
You want to ask to the SecurityManager if you have Exec right with the checkExec method.
如果您使用checkExec方法执行Exec,则需要向SecurityManager询问。
#2
1
I have also found that adding the following to the JNLP file:
我还发现将以下内容添加到JNLP文件中:
<security>
<all-permissions/>
</security>
And signing the JAR file allows the app to run with all the permissions needed for Runtime.exec
.
签署JAR文件允许应用程序以Runtime.exec所需的所有权限运行。
#3
0
For the specific example of Runtime.exec there is a method on the SecurityManager class checkExec(String cmd) that will throw an exception that can be caught to determine if the necessary command can be executed. For more information see the javadoc for Runtime.exec and SecurityManager.checkExec.
对于Runtime.exec的特定示例,SecurityManager类上有一个方法checkExec(String cmd),它将抛出一个异常,可以捕获该异常以确定是否可以执行必要的命令。有关更多信息,请参阅Runtime.exec和SecurityManager.checkExec的javadoc。
The more general case requires creating a Permission object representing the task being checked and running SecurityManager's checkPermission method.
更一般的情况需要创建一个Permission对象,表示正在检查的任务并运行SecurityManager的checkPermission方法。
#1
1
You want to ask to the SecurityManager if you have Exec right with the checkExec method.
如果您使用checkExec方法执行Exec,则需要向SecurityManager询问。
#2
1
I have also found that adding the following to the JNLP file:
我还发现将以下内容添加到JNLP文件中:
<security>
<all-permissions/>
</security>
And signing the JAR file allows the app to run with all the permissions needed for Runtime.exec
.
签署JAR文件允许应用程序以Runtime.exec所需的所有权限运行。
#3
0
For the specific example of Runtime.exec there is a method on the SecurityManager class checkExec(String cmd) that will throw an exception that can be caught to determine if the necessary command can be executed. For more information see the javadoc for Runtime.exec and SecurityManager.checkExec.
对于Runtime.exec的特定示例,SecurityManager类上有一个方法checkExec(String cmd),它将抛出一个异常,可以捕获该异常以确定是否可以执行必要的命令。有关更多信息,请参阅Runtime.exec和SecurityManager.checkExec的javadoc。
The more general case requires creating a Permission object representing the task being checked and running SecurityManager's checkPermission method.
更一般的情况需要创建一个Permission对象,表示正在检查的任务并运行SecurityManager的checkPermission方法。