Question

I have a strange error :

my Code :

System.setProperty("java.security.policy", "client.policy");
System.setProperty("java.rmi.server.codebase", Servicecodebase);
System.setSecurityManager(new RMISecurityManager()); 

    Class<?> InterfaceMath =  RMIClassLoader.loadClass("http://127.0.0.1/dis/service.jar", "Service.InterfaceMath");



    Remote service = null;                  
     service  = Naming.lookup("rmi://127.0.0.1:1099/ok"); //  Error Message here
    Method getInformation = service.getClass().getDeclaredMethod("test", String.class);
    String res = (String) getInformation.invoke(service);
     System.out.println(" res : "+res);

My file client.policy :

grant {
    permission java.security.AllPermission;
    permission java.net.SocketPermission "localhost:1099", "connect, resolve";
    permission java.net.SocketPermission "127.0.0.1:1099", "connect, resolve";
    permission java.net.SocketPermission "localhost:80", "connect, resolve";
};

my error :

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

I take on Eclipse in Run Configuration - VM Arguments -Djava.security.policy==client.policy And I lanch --- Start rmiregistry on the console.

It's strange because I have configure my File, I load my Interface but i can't communicate with my RMI. Server I don't know why I have this problem.

update : my project ClientRMI :

  1. src
  2. (Default package)
  3. consumerTest.java
  4. client.policy
Was it helpful?

Solution

Obviously the file isn't being found. As you've only specified it as "client.policy", it needs to be in the current working directory when the program is launched.

If you run it with

-Djava.security.debug=access,failure

you will get a very complete trace of security manager failures, including the security domain in effect at the time and the .policy file it was configured from.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top