Java.security.AccessControlException: Access Denied Exception

I am trying to make a simple RMI program. But when I execute the line, I get the following exception Naming.rebind ("interface_name", Remoteserverobject);

java.security.AccessControlException: Access denied (java.net.SocketPermission 127.0.0.1:1099 connect, allow)

My code looks like this:

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

+2


a source to share


3 answers


I think it 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!!!!");
        }
    }

      



Each JRE has a default security manager that tries to override the new security manager. You are specifying any properties for this new security administrator. Also, the error. The solution uses a default manager to create a completely new security manager following these instructions.

-1


a source


Do not use Security Manager if (i) you do not know you need one and (ii) you have written the appropriate .policy file. If you think both of these options are applicable then follow your problem with -Djava.security.debug = access, not being able to figure out what is really going wrong. Most likely, you did not grant the required permission or did not provide the correct location for the policy file.



+1


a source


Make sure you have configured RMISecurityManager as described here

0


a source







All Articles