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('$','@')