Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Security / December 2004

Tip: Looking for answers? Try searching our database.

SecurityManager Question

Thread view: 
Robin Hollenstein - 16 Dec 2004 17:16 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.