John,
I think a SecurityManager cannot be removed once its set. Look at this
code:
public class exps
{
public static void main(String[] args)
{
System.setSecurityManager(new SecurityManager());
System.out.println("First SecurityManager set");
System.setSecurityManager(null);
System.out.println("Second SecurityManager set");
System.out.println(System.getProperty("user.name"));
}
}
I ran it and it gave me the following result:
U:\java exps
First SecurityManager set
Exception in thread "main" java.security.AccessControlException:
access denied (
java.lang.RuntimePermission setSecurityManager)
at java.security.AccessControlContext.checkPermission(Unknown
Source)
at java.security.AccessController.checkPermission(Unknown
Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.System.setSecurityManager0(Unknown Source)
at java.lang.System.setSecurityManager(Unknown Source)
at exps.main(exps.java:8)
U:\
I would also recommend you to check the API-Documentation, specially
the classes <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html">System</a>
and <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/SecurityManager.html">Security
Manager</a>
Hope I helped,
R. Hollenstein
Selvamohan Neethiraj - 18 Dec 2004 18:22 GMT
You can set another security manager as long as your current security
manager allows the following two permissions:
java.lang.RuntimePermission createSecurityManager
java.lang.RuntimePermission setSecurityManager
=====================================================================
Try the following code ....
=====================================================================
public class ChangeSecMgr
{
public static void main(String[] args)
{
System.err.println("Current Security Manager: [" +
System.getSecurityManager() + "]") ;
System.setSecurityManager(new RelaxedSecurityManager()) ;
System.err.println("Current Security Manager: [" +
System.getSecurityManager() + "]") ;
System.setSecurityManager(new SecurityManager()) ;
System.err.println("Current Security Manager: [" +
System.getSecurityManager() + "]") ;
}
}
class RelaxedSecurityManager extends SecurityManager
{
public void checkPermission(Permission perm)
{
System.err.println("Permission:[" + perm + "] is ok");
return ;
}
}
=====================================================================
> John,
> I think a SecurityManager cannot be removed once its set. Look at this
[quoted text clipped - 41 lines]
>
> R. Hollenstein