Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

access denied (java.lang.RuntimePermission createSecurityManager)

249 views
Skip to first unread message

Shishir

unread,
May 10, 2006, 10:03:07 AM5/10/06
to
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

unread,
May 10, 2006, 10:42:31 AM5/10/06
to

"Shishir" <shish...@gmail.com> wrote in message
news:1147269787....@g10g2000cwb.googlegroups.com...

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

unread,
May 10, 2006, 1:07:22 PM5/10/06
to
Shishir schrieb:
[...]

> 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() {
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:
>
> 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)
>
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#SecurityManager()>
or directly into Sun's source of java.lang.SecurityManager now)

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

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

0 new messages