java.lang.SecurityException: JVM Shared, not allowed to set security manager

UPDATED: 21 December 2013
Java, Applet
I created custom security manager for Applet to get all permission. In below code I'm allowing applet to exit and its not good practice but situation driving me that way for while. I'm also searching for better option. If you guys have solution please comment it.
class customSecurityManager extends SecurityManager{
    SecurityManager original;

    customSecurityManager(SecurityManager original) {
      this.original = original;
    }

    /** Deny permission to exit the VM(uncomment line).*/
    public void checkExit(int status) {
      //throw(new SecurityException("Not allowed"));
    }

    /* Allow this security manager to be replaced,in fact allow pretty much everything. */
    public void checkPermission(Permission perm) {
    }

    public SecurityManager getOriginalSecurityManager() {
       return original;
    }
}
It works pretty well in many systems but one system was throwing an exception as follow...
java.lang.SecurityException: JVM Shared, not allowed to set security manager
 at sun.plugin2.applet.SecurityManagerHelper.checkPermissionHelper(Unknown Source)
 at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
 at java.lang.System.setSecurityManager0(Unknown Source)
 at java.lang.System.setSecurityManager(Unknown Source)
 at SecurityApplet.init(SecurityApplet.java:103)
 at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
 at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
 at j ava.lang.Thread.run(Unknown Source)
After doing lots of search over internet and trying different options finally found solution for applet. Loading applet in separate JVM did the job.
<applet>
...
<param name="separate_jvm" value="true">
...
</applet>

0 comments :