I am trying to prohibit thread creation in an AccessController.doPriviliged() method. The method below creates and runs the thread. I run this with -Djava.security.manager. According to this link, if modifyThreadGroup is not granted, then Thread creation should be disallowed?
http://docs.oracle.com/javase/7/docs/technotes/guides/security/permissions.html
Can anyone enlighten me as to why this is happening and the correct way to disallow Thread creation using AccessController?
// .java.policy in $UserHome:
grant codeBase "file:/C:/-" {
permission java.security.AllPermission;
};
public class ThreadTest {
public void testModifyThreadGroup() {
// grant no permissions
Permissions perms = new Permissions();
ProtectionDomain domain = new ProtectionDomain(
new CodeSource( null, (Certificate[]) null ), perms );
AccessControlContext _accessControlContext = new AccessControlContext(
new ProtectionDomain[] { domain } );
try {
AccessController.doPrivileged(new PrivilegedExceptionAction(){
@Override
public Object run() {
try {
// modifyThreadGroup not granted, so should not be able
// to call Thread constructor???
Thread t = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Thread.run()");
}
});
t.run();
} catch (Exception ex) {
System.out.println("Error running thread: " + ex);
}
return null;
}}, _accessControlContext);
} catch(Exception e) {
System.out.println("Access Error running doPrivileged: " + e);
}
}
}