This discussion is archived
10 Replies Latest reply: Jun 26, 2011 5:41 PM by EJP RSS

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

800408 Newbie
Currently Being Moderated
Hi all,
i got the above message even i declare a :
server.policy file that look like:

grant {
// Allow everything for now
permission java.security.AllPermission;
};

and also i ad to eclipse in VM arguments the following line:
-Djava.security.policy=server.policy -Djava.rmi.server.codebase=compute.jar
is any one can help??

Thanks
  • 1. Re: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    gimbal2 Guru
    Currently Being Moderated
    so your problem may just be in the computer, like a software firewall that is blocking you.
  • 2. Re: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    EJP Guru
    Currently Being Moderated
    No. This is a Java security sandbox problem. Any time you get "access denied" with a named permission, you are runing under the control of a SecurityManager and you need to grant yourself that permission. In this case, java.net.SocketPermission 127.0.0.1:1099 connect,resolve.
  • 3. Re: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    gimbal2 Guru
    Currently Being Moderated
    EJP wrote:
    No. This is a Java security sandbox problem. Any time you get "access denied" with a named permission, you are runing under the control of a SecurityManager and you need to grant yourself that permission. In this case, java.net.SocketPermission 127.0.0.1:1099 connect,resolve.
    commits the lesson to memory

    Note to self: don't make assumptions without a Google search.
  • 4. Re: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    800408 Newbie
    Currently Being Moderated
    Thanks for your answers but the problem was simpler :
    i have to make ;
    "start rmiregistry" on windows.
    but than i got a nother problem and it is:
    "Error unmarshaling return; nested exception is: ...."

    is any one has any idea???

    Thanks
  • 5. Re: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    gimbal2 Guru
    Currently Being Moderated
    well before anyone can have any idea, you would be advised to post the entire error message.
  • 6. Re: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    EJP Guru
    Currently Being Moderated
    The problem wasn't simpler. Running the Registry doesn't solve permission problems. You had to solve that problem and then solve the registry problem. Two problems so far. There are probably more in store: RMI isn't simple.
  • 7. Re: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    800408 Newbie
    Currently Being Moderated
    Hi all,
    i was serch on the web and i try a bit diffrent approach for the same code:

    so instead :

    if (System.getSecurityManager() == null) {
    System.setSecurityManager(new SecurityManager());
    }

    and than : "start registry"

    i change it to:

    LocateRegistry.createRegistry(1099);
    without : 'start registry"

    and it works fine.

    what can the problem with start registry that i missing???

    Thanks
  • 8. Re: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    EJP Guru
    Currently Being Moderated
    What problem? You've posted half of the top line of an exception, where's the rest of it? The part with the information?
  • 9. Re: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    800408 Newbie
    Currently Being Moderated
    let me summerize all the info:

    this is the partial code i run:
    public static void main(String[] args) throws RemoteException {
    if (System.getSecurityManager() == null) {
    System.setSecurityManager(new SecurityManager());
    }
    //this is working     LocateRegistry.createRegistry(1099);

    try {
    String name = "Compute";
    Compute engine = new ComputeEngine();
    Compute stub =
    (Compute) UnicastRemoteObject.exportObject(engine, 0);
    Registry registry = LocateRegistry.getRegistry();
    registry.rebind(name, stub);
    System.out.println("ComputeEngine bound");
    } catch (Exception e) {
    System.err.println("ComputeEngine exception:");
    e.printStackTrace();
    }



    the first run i made with the:
    1- start registry
    2- the jvm arguments: -Djava.security.policy=server.policy -Djava.rmi.server.codebase=ComputeEngine
    3- server.policy file looks:
    grant {
    // Allow everything for now
    permission java.security.AllPermission;
    };

    when i run this i got the following exception:
    ComputeEngine exception:
    java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
         java.net.MalformedURLException: no protocol: ComputeEngine
         at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:227)
         at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
         at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
         at ComputeEngine.main(ComputeEngine.java:63)
    Caused by: java.net.MalformedURLException: no protocol: ComputeEngine
         at java.net.URL.<init>(URL.java:567)
         at java.net.URL.<init>(URL.java:464)
         at java.net.URL.<init>(URL.java:413)
         at sun.rmi.server.LoaderHandler.pathToURLs(LoaderHandler.java:751)
         at sun.rmi.server.LoaderHandler.getDefaultCodebaseURLs(LoaderHandler.java:120)
         at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:149)
         at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
         at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
         at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
         at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)
         at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
         at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:225)
         ... 3 more

    in my second run i use almost the same code except* i remark the if statemnt for the getSecurityManager and add "LocateRegistry.createRegistry(1099)" :
    public static void main(String[] args) throws RemoteException {
    /* if (System.getSecurityManager() == null) {
    System.setSecurityManager(new SecurityManager());
    }
    */
         LocateRegistry.createRegistry(1099);

    try {
    String name = "Compute";
    Compute engine = new ComputeEngine();
    Compute stub =
    (Compute) UnicastRemoteObject.exportObject(engine, 0);
    Registry registry = LocateRegistry.getRegistry();
    registry.rebind(name, stub);
    System.out.println("ComputeEngine bound");
    } catch (Exception e) {
    System.err.println("ComputeEngine exception:");
    e.printStackTrace();
    }

    1- i was turn off the start registry
    2- i was not send any parameters to the jvm.

    and it works fine (no any exception and the server wait for client to connect).

    my feeling is that i missing some Security point at the first run.

    is it more clear now???

    Thanks

    by the way :
    when this forum was belong to sun i was able to add some code with special character and not as a text.
    is this option still exist???
  • 10. Re: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    EJP Guru
    Currently Being Moderated
    java.rmi.server.codebase specifies a URL, not a classname. Check the documentation.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points