Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SecurityManager and JUnit

577328Oct 20 2010 — edited Oct 20 2010
Hi, I am using an overridden java.lang.SecurityManager with a policy-file containing all required permissions for my program to run. Problems arise when I am trying to run a JUnit3-test. The SecurityManager (basically does logging of violations, otherwise equivalent to the java.lang.SecurityManager) is passed to the VM as a command-line parameter, so is the policy-file.

My SM reports an AccessControlException:

class java.security.AccessControlException - access denied (java.io.FilePermission C:\Programfiler\eclipse\plugins\org.junit_3.8.2.v20090203-1005\junit.jar read)

My policy file:
...
permission java.io.FilePermission "C:\Programfiles\eclipse\plugins\org.junit_3.8.2.v20090203-1005\junit.jar", "read";
...

If I include "permission java.security.AllPermission;", the program executes fine.

I've google for any issues regarding JUnit and SecurityManagers, but found no relevant articles.

Any suggestions would be appreciated.

Regards,

Ronny Mandal

PS! Here is the stack trace of the exception:

java.security.AccessControlException: access denied (java.io.FilePermission C:\Programfiler\eclipse\plugins\org.junit_3.8.2.v20090203-1005\junit.jar read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at no.ronnyma.MySecurityManager.CustomSecurityManager.checkPermission(CustomSecurityManager.java:50)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.exists(Unknown Source)
at sun.misc.FileURLMapper.exists(Unknown Source)
at sun.misc.URLClassPath$JarLoader.getJarFile(Unknown Source)
at sun.misc.URLClassPath$JarLoader.access$600(Unknown Source)
at sun.misc.URLClassPath$JarLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath$JarLoader.ensureOpen(Unknown Source)
at sun.misc.URLClassPath$JarLoader.<init>(Unknown Source)
at sun.misc.URLClassPath$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath.getLoader(Unknown Source)
at sun.misc.URLClassPath.getLoader(Unknown Source)
at sun.misc.URLClassPath.getResource(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)

Edited by: user574325 on Oct 20, 2010 8:13 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 17 2010
Added on Oct 20 2010
1 comment
964 views