tags:

views:

156

answers:

3

Hi!

I'm trying to do a simple program for RMI. But, I'm getting the following exception while running the line Naming.rebind("interfacename",Remoteserverobject);

java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)

My Code is as follows:

public static void main(String[] args) throws Exception {

        if(System.getSecurityManager()==null)
        {
            System.setSecurityManager(new RMISecurityManager());
        }
        Remoteserver objremoteserver=new Remoteserver();
        objremoteserver.setmsg("Hello! How are you?");
        System.out.println(objremoteserver.getmsg());
        try
        {
        Naming.rebind("Remotemethod", objremoteserver);
        System.out.println("Server Started");
        }
        catch(RemoteException re)
        {
            System.out.println(re.getLocalizedMessage());
        }
        finally
        {
            System.out.println("Unknown Exception Occured!!!!");
        }
    }

How to overcome this problem. Thanks in advance

A: 

Make sure you have setup the RMISecurityManager as explained here

objects
S. I included that line. It is creating new rmisecurity manager. But, no use.
Nila
can you post your code
objects
S.. I posted. Can u check that?
Nila
A: 

Don't use a security manager unless (i) you know you need one and (ii) you have written an appropriate .policy file. If you think both these apply, run your problem with -Djava.security.debug=access,failure to see what is really going wrong. Most likely you haven't granted yourself the required permission or you haven't specified the policy file location correctly.

EJP
@Downvoter: what is your problem with this answer?
EJP
A: 

Hi nila, i guess this works

public static void main(String[] args) throws Exception {

        Remoteserver objremoteserver=new Remoteserver();
        objremoteserver.setmsg("Hello! How are you?");
        System.out.println(objremoteserver.getmsg());
        try
        {
        Naming.rebind("Remotemethod", objremoteserver);
        System.out.println("Server Started");
        }
        catch(RemoteException re)
        {
            System.out.println(re.getLocalizedMessage());
        }
        finally
        {
            System.out.println("Unknown Exception Occured!!!!");
        }
    }

Every JRE has a default security manager, U r trying to override with a new security manager. You dint specify any properties to this new security manager.so the error.The solution is use the default manager are create a completely new security manager following these instructions.

rgksugan