Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Java.security.AccessControlException: access denied (https://www.askmehelpdesk.com/showthread.php?t=683849)

  • Jul 17, 2012, 10:34 AM
    javalola
    Java.security.AccessControlException: access denied
    Hi, I am a beginner in java. I am trying to create a rmi client- database server application in java, but I am struggling. The client and the database server are to work well even if placed in different computers, that is in separate packages.
    My server seems to be working fine, but when I run my client I keep on getting the error: java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve").

    I read on security policies recently and I don't really know how to work with it in netbeans. I read that I am to create a security policy file and place it in the server package and client package too. I did so, I created a txt file with my policy and placed a copy of it in my netbeans projects, inside the server and client src file and in the package respectively. My policy looks as follows:
    Code:

    grant {
      permission java.security.AllPermission;
    };


    My server looks as follows:
    Code:

    package wildanimalsserver;
    import java.rmi.RMISecurityManager;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    /**
     *
     * @author CTI
     */
    public class WildAnimalsServer {
     
        public WildAnimalsServer() {
        }
        public static void main(String [] args) {
            try {
                RMISecurityManager security = new RMISecurityManager();
                System.setSecurityManager(new RMISecurityManager());
                //Creating and getting the reference to the RMI registry
                Registry registry = LocateRegistry.createRegistry(1099);
               
                //Instantiating the object
                AnimalObject ao = new AnimalObject();
                //Registering the object
                registry.rebind("Animal", ao);
                System.out.println("Server ready...");
            } catch (Exception e) {
                System.out.println(e);
            }
        }
       
    }


    .. and my client:
    Code:

    package wildanimalsclient;
    import java.rmi.RMISecurityManager;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    /**
     *
     * @author CTI
     */
    public class WildAnimalsClient {
     
        /**
        * @param args the command line arguments
        */
        public static void main(String[] args) {
        try {
                RMISecurityManager security = new RMISecurityManager();
                System.setSecurityManager(new RMISecurityManager());
                // Get reference to rmi registry server
                Registry registry = LocateRegistry.getRegistry(1099);
                // Looking up for the server object
                IRemoteAnimal ra = (IRemoteAnimal)registry.lookup("Animal");
                System.out.println("Client ready and responding...");
     
            } catch (Exception e) {
                System.out.println(e);
            }     
        }
    }


    My Server consists of:
    Animal.java(entity class mapping to database)
    IRemoteanimal.java(RMI application interface)
    AnimalObject.java(Animal object to be distributed)
    WildAnimalsServer.java(server application)
    WildAnimalsDBmanager.java(manage connection to database)
    AnimalRepository.java(provides crud operations)

    And my client:
    Animal.java(same as server)
    IRemoteanimal.java(same as server)
    WildAnimalsClient.java(client application calling RMI server)
  • Aug 27, 2012, 03:42 PM
    Marconian
    Could you find the answer to your problem? I'm beginning to work with RMI and I'm facing the same problem: java.net.SocketPermission

    Let me know if you find any solution.

    Thanks,

    Marcos Alves
    [email protected]

  • All times are GMT -7. The time now is 12:07 AM.