Search code examples
javarmi

java.security.AccessControlException: access denied Exception


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


Solution

  • 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.