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 / General / May 2006

Tip: Looking for answers? Try searching our database.

access denied (java.lang.RuntimePermission createSecurityManager)

Thread view: 
Shishir - 10 May 2006 15:03 GMT
Hey,
I am a beginner to learning RMI and hence was trying this simple
program.

here is my code with the main class. The error is shown in this class:

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;

@SuppressWarnings("serial")
public class HelloImpl extends UnicastRemoteObject
   implements Hello {

    public HelloImpl() throws RemoteException {
       super();
   }

   public String sayHello() {
       return  "Hello World!";
   }

   public static void main(String args[]) {

       // Create and install a security manager
       if (System.getSecurityManager() == null) {
       System.setSecurityManager(new RMISecurityManager());
       }
       try {
       HelloImpl obj = new HelloImpl();

       // Bind this object instance to the name "HelloServer"
       System.setSecurityManager (new RMISecurityManager() {
           public void checkConnect (String host, int port) {}
           public void checkConnect (String host, int port, Object
context) {}
         });
       Naming.rebind("HelloServer", obj);
       System.out.println("HelloServer bound in registry");
       } catch (Exception e) {
       System.out.println("HelloImpl err: " + e.getMessage());
       e.printStackTrace();
       }
   }
}

This is the error that I get:

java.security.AccessControlException: access denied
(java.lang.RuntimePermission createSecurityManager)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.<init>(Unknown Source)
    at HelloImpl$1.<init>(HelloImpl.java:30)
    at HelloImpl.main(HelloImpl.java:30)
HelloImpl err: access denied (java.lang.RuntimePermission
createSecurityManager)

Any Help on this would be great.

Thanks a lot.
Shishir
Rhino - 10 May 2006 15:42 GMT
> Hey,
> I am a beginner to learning RMI and hence was trying this simple
[quoted text clipped - 57 lines]
>
> Any Help on this would be great.

I'm not very knowledgeable about security but I _think_ this tutorial should
help:
http://java.sun.com/docs/books/tutorial/security1.2/index.html

If it doesn't, you could try comp.lang.java.security although I suspect they
focus on more advanced security issues.

--
Rhino
Thomas Fritsch - 10 May 2006 18:07 GMT
Shishir schrieb:
[...]
>     public static void main(String args[]) {
>
[quoted text clipped - 7 lines]
>        // Bind this object instance to the name "HelloServer"
>        System.setSecurityManager (new RMISecurityManager() {
This is line 30, isn't it?
>            public void checkConnect (String host, int port) {}
>            public void checkConnect (String host, int port, Object
> context) {}
>          });
[...]

> This is the error that I get:
>
[quoted text clipped - 8 lines]
> HelloImpl err: access denied (java.lang.RuntimePermission
> createSecurityManager)

You call System.setSecurityManager(...) two times. The first call gives
no error. The second call throws the exception, from inside the
constructor of SecurityManager. The reason is that the first
SecurityManager instance forbids creating a second SecurityManager instance.
(You might want to look into the API doc
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/SecurityManager.html#SecurityM
anager
()>
or directly into Sun's source of java.lang.SecurityManager now)

One simple solution for your problem is:
omit your first call System.setSecurity(...)

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')



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.