views:

130

answers:

3

I have an application which really should be installed, but does work fine when deployed using JNLP.

However, it would seem that some Java functions such as Runtime.exec don't work using the default security options.

I would like to therefore disable UI functionality that relies upon such functions. 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.

+1  A: 

You want to ask to the SecurityManager if you have Exec right with the checkExec method.

Damien B
+1  A: 

I have also found that adding the following to the JNLP file:

<security>
    <all-permissions/>
</security>

And signing the JAR file allows the app to run with all the permissions needed for Runtime.exec.

Frank Krueger
A: 

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.

The more general case requires creating a Permission object representing the task being checked and running SecurityManager's checkPermission method.

John Meagher