Code Comments
Programming Forum and web based access to our favorite programming groups.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/Syste
m.html">System</a>
and <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/SecurityManag
er.html">SecurityManager</a>
Hope I helped,
R. Hollenstein
Post Follow-up to this messageYou 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 ;
}
}
========================================
=============================
"Robin Hollenstein" <r.hollenstein@csm.edu.mx> wrote in message
news:621b66f7.0412160916.636963b3@posting.google.com...
> 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">Syste
m</a>
> and <a
> href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/SecurityManager.ht
ml">SecurityManager</a>
>
> Hope I helped,
>
> R. Hollenstein
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.