Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top