Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

SecurityManager Question
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

Report this thread to moderator Post Follow-up to this message
Old Post
Robin Hollenstein
12-16-04 09:09 PM


Re: SecurityManager Question
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 ;
}
}
 ========================================
=============================


"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



Report this thread to moderator Post Follow-up to this message
Old Post
Selvamohan Neethiraj
12-18-04 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Security archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:47 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.