java.security.AccessControlException is thrown in case system SecurityManager is reset when running in module mode

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

java.security.AccessControlException is thrown in case system SecurityManager is reset when running in module mode

Ekaterina Pavlova
Hello,

java.security.AccessControlException is thrown in case system SecurityManager is reset when running
application in module mode. The minimized test case is attached. Is this known issue?
Note, the test works fine in legacy mode but fails in module mode.

thanks,
-katya

===

 > cat Hello.java
package a;

import java.security.*;

public class Hello {
   public static void main(String[] args) {
     System.setSecurityManager(new CustomSecurity());

     System.out.println("Going to call System.exit");
     System.exit(0);
   }
}
class CustomSecurity extends SecurityManager {}


 > cat module-info.java
module hello @ 1.0 {
   requires jdk.base;
   class a.Hello;
}

# run in legacy mode
 > java a.Hello
Going to call System.exit

# run in module mode
 > java -L mlib -m hello
Going to call System.exit
Exception in thread "main" java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0")
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:364)
         at java.security.AccessController.checkPermission(AccessController.java:555)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:550)
         at java.lang.SecurityManager.checkExit(SecurityManager.java:762)
         at java.lang.Runtime.exit(Runtime.java:105)
         at java.lang.System.exit(System.java:962)
         at a.Hello.main(Hello.java:10)
Reply | Threaded
Open this post in threaded view
|

Re: java.security.AccessControlException is thrown in case system SecurityManager is reset when running in module mode

Sean Mullan
On 1/26/12 1:30 PM, Ekaterina Pavlova wrote:
> Hello,
>
> java.security.AccessControlException is thrown in case system SecurityManager is reset when running
> application in module mode. The minimized test case is attached. Is this known issue?
> Note, the test works fine in legacy mode but fails in module mode.

The reason it works in legacy mode is because sun.misc.Launcher.AppClassLoader
overrides getPermissions(CodeSource) and adds the exitVM permission:

        /**
         * allow any classes loaded from classpath to exit the VM.
         */
        protected PermissionCollection getPermissions(CodeSource codesource)
        {
            PermissionCollection perms = super.getPermissions(codesource);
            perms.add(new RuntimePermission("exitVM"));
            return perms;
        }

For jigsaw, we can probably add a similar workaround in
org.openjdk.jigsaw.Launcher or Loader when it is loading a module with an entry
point.

But, one of the things I also want to explore is storing the permissions granted
to a module by the configured policy in the module library when it is installed.
If a module with an entry point is installed (which I guess is the equivalent of
an application?), it could automatically add the RuntimePermission exitVM
permission. Then when the module is loaded, these permissions would be loaded
into the ProtectionDomain associated with that module.

--Sean