RMI connection refused
Asked Answered
D

2

3

I am trying to get a rmi connection going. I have ran into many security issues but have been unable to find a way past all this. I execute my jar file with:

java -Djava.security.policy=java.security.AllPermission -jar "myjarfile"

The code I have been using to create this is:

public class server
{
    public static void main(String args[])throws Exception
    {
    if (System.getSecurityManager() == null)
        System.setSecurityManager ( new RMISecurityManager() {
        public void checkConnect (String host, int port) {}
        public void checkConnect (String host, int port, Object context) {}
        });

    try
    {
        sampleserverimpl server = new sampleserverimpl();
        System.out.println("SERVER IS WAITING");
        LocateRegistry.createRegistry(2020);

        //Runtime.getRuntime().exec("rmiregistry 2020");
        Naming.rebind("//localhost:2020/SERVER", server);

    }
    catch(Exception e)
    {
        System.out.println(e);
    }
}
};

The error trace I am receiving is:

Exception in thread "RMI TCP Connection(idle)" java.security.AccessControlExcept
ion: access denied (java.net.SocketPermission 127.0.0.1:31199 accept,resolve)jav
a.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:

    java.io.EOFException

I have tried different ways to get around this, can anyone see the issue here?

Thanks

Demonism answered 18/11, 2010 at 11:28 Comment(0)
W
7

-Djava.security.policy accepts a URL which points to a policy file which in turn contains the permissions. So you should have: -Djava.security.policy=/some/path/my.policy as the JVM argument where the my.policy file contains:

grant {
  permission java.security.AllPermission;
};

Also, in order to avoid the NULL check present in your code and the manual creation of a SecurityManager, you can request a SecurityManager be automatically installed for your application by passing the JVM switch: -Djava.security.manager.

Your final JVM invocation should look like:

java -Djava.security.manager -Djava.security.policy=/some/path/my.policy
Winder answered 18/11, 2010 at 11:46 Comment(1)
Got the it running now, thanks. Tried the file earlier but didn't add in the security manager. +1Demonism
H
0

This is two separate exceptions. The first is a permission problem. The second one, the EOFException, could have any of a number of causes. I would need to see java -version and the complete stack trace to assist further.

Hazeghi answered 18/11, 2010 at 11:45 Comment(1)
I have somewhat the same Problem, my Application which uses RMI runs into an EOFException, and Crashes, but if i set the Permissions to AllPermissions all runs fine. Any Idea which permission can cause this?Papp

© 2022 - 2024 — McMap. All rights reserved.