Java RMI Client AccessControlException


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Java RMI Client AccessControlException

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Posts
    2

    Java RMI Client AccessControlException

    Hi I've had some problems trying to get RMI working and was wondering if anyone can help me? I've tried implementing the client/server code two different ways - one way using a Registry object to bind my remote object and one using the Naming.rebind()/Naming.lookup() methods (my current code, which I'll supply in a sec).

    I noticed when I was using the Registry object to bind the DriverObject I was getting errors about stuff not being serializable when trying to run the client. Is it talking about the objects that the DriverObject uses?

    I'm running all of this on a windows machine using the following commands (the code is located in the folder C:\pid):

    set CLASSPATH=
    start rmiregistry

    javac *.java
    rmic -Djava.security.policy=policy.all javapid.DriverObject

    java Server
    java -Djava.security.policy=policy.all -classpath /pid ClientObject

    When running the ClientObject I get the following error:

    exporter: an exception occurred: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkConnect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
    at sun.rmi.server.UnicastRef.newCall(Unknown Source)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Unknown Source)
    at ClientObject.main(ClientObject.java:405)

    I've taken some of the code out of the driver object (the getters/setters are pretty much the same) for this post.

    RemoteEvent.java
    Code:
    package javapid;
     
    import java.rmi.Remote;
    import java.rmi.RemoteException;
     
    public interface RemoteEvent extends Remote
    {
      public double getInput    ()          throws RemoteException;
      public double getOutput   ()          throws RemoteException;
      public double getKp       ()          throws RemoteException;
      public double getKi       ()          throws RemoteException;
      public double getKd       ()          throws RemoteException;
      public double getPlant    ()          throws RemoteException;
      public int    getSgm      ()          throws RemoteException;  
      public double getSgmiv    ()          throws RemoteException;
      public double getSgmav    ()          throws RemoteException;
      public double getSgni     ()          throws RemoteException;
      public void   setKp       (double Kp) throws RemoteException;
      public void   setKi       (double Ki) throws RemoteException;
      public void   setKd       (double Kd) throws RemoteException;
      public void   setPlant    (double g)  throws RemoteException;
      public void   setRate     (double r)  throws RemoteException;
      public void   setSgmiv    (double mi) throws RemoteException;
      public void   setSgmav    (double ma) throws RemoteException;
      public void   setSgni     (double ni) throws RemoteException;
      public void   setSgm      (int md)    throws RemoteException;
      public void   resetSigGen ()          throws RemoteException;
    }
    DriverObject.java
    Code:
    package javapid;
     
    import java.rmi.*;
    import java.rmi.server.*;
    import java.rmi.registry.*;
     
    public class DriverObject extends UnicastRemoteObject implements AsyncEvent, RemoteEvent {
     
      private int externalCount = 0;
      
      private SignalObject SO;
      private SystemObject SY;
      
      private int period = 20;
     
      public DriverObject() throws RemoteException {
        System.out.println("Creating remote control object");
        SO = new SignalObject(0.0,5.0,0.01,100,0,0.0);
        SY = new SystemObject(SO);
        this.Start();
      }  
      
      public DriverObject(SignalObject Sig, SystemObject Sys) throws RemoteException {
        System.out.println("Creating remote control object");
    	  SO = Sig;
        SY = Sys;
        this.Start();
      }
      
      public double getInput() throws RemoteException {
        return SO.getOutput();
      }
          
      public void setKp(double Kp) throws RemoteException {
        SY.setKp(Kp);
      }
     
      public void Start() {
        ClockedEventObject SOT = new ClockedEventObject(period, SO);
        ClockedEventObject SOY = new ClockedEventObject(period, SY);
        ClockedEventObject DOT = new ClockedEventObject(period, this); 
        while(true) {}
      }
      
      public void handleAsyncEvent() {
    // this is used by a clock object I created which is used in the Start() method.
    // it implements the method defined in the AsyncEvent interface.
     
        externalCount++;
      }
     
      public static void main (String args[])
      {
          try
          {
              System.setSecurityManager(new RMISecurityManager());
            
              DriverObject Do = new DriverObject ();
     
              System.out.println ("Created remote object, now advertising it");
     
              //Registry registry = LocateRegistry.getRegistry ("localhost", 1099);
              //registry.rebind ("RemotePID", Do);
              Naming.rebind("RemotePID", Do);
     
              System.out.println ("Advertising completed");
          }
          catch (Exception e)
          {
              System.out.println ("exporter: an exception occurred: "+
                      e.getMessage ());
              e.printStackTrace ();
              System.exit (1);
          }
      }  
      
    }
    ClientObject.java
    Code:
    import javapid.*;
    import java.rmi.*;
    import java.rmi.registry.*;
     
    class ClientObject
    {
      
    //  public void setRst(int i) {
    //    try
    //      {
    //          System.out.println ("Starting client");
    //
    //          Registry registry = LocateRegistry.getRegistry ("localhost", 1099);
    //          Object O          = registry.lookup("RemotePID");
    //          RemoteEvent Rev   = (RemoteEvent) O;
    //
    //          if (i > 0) Rev.resetSigGen();
    //      } catch (Exception e) {
    //          System.out.println ("exporter: an exception occurred: "+
    //                  e.getMessage ());
    //          e.printStackTrace ();
    //          System.exit (1);
    //      }
    //  }
      
      public static void main(String args[]) {
        System.setSecurityManager(new RMISecurityManager());
        
        try {
          System.out.println("Security Manager loaded");
          String url = "//localhost/RemotePID";
          
          RemoteEvent Rev = (RemoteEvent) Naming.lookup(url);
          System.out.println("Got remote object");
          
          System.out.println("Output is:"+ Rev.getOutput());
        } catch (Exception e) {
              System.out.println ("exporter: an exception occurred: "+
                      e.getMessage ());
              e.printStackTrace ();
              System.exit (1);
        }
      }
    }
    Thanks .

  2. #2
    Join Date
    Mar 2006
    Posts
    2
    Ok, fixed the security exception problem . Was just a .java.policy problem - now the problem I'm getting is a "java.rmi.NotBoundException: RemotePID" which I find a bit confusing - the RMIRegistry is definetly running and hasn't crashed plus the server object (DriverObject in my case) is running properly (checking my CPU usage it goes from around about 2-5% to 50% - the program is pretty cpu intensive, so the DriverObject definetly is running).

    My only conclusions I can come up with are either that the DriverObject isn't advertising itself correctly or the ClientObject isn't finding the advertised object for some reason.

    Any ideas people?

    I've also tried the alternate way of advertising and connecting to remote objects:

    DriverObject
    Code:
    Registry registry = LocateRegistry.getRegistry ("localhost", 1099);
    registry.rebind ("RemotePID", new DriverObject ());
    ClientObject
    Code:
    Registry registry = LocateRegistry.getRegistry ("localhost", 1099);
    RemoteEvent Rev   = (RemoteEvent) registry.lookup("RemotePID");
    It's pretty unsecure, but currently my .java.policy file in the root folder of my user profile looks like:
    Code:
    grant {
      permission java.security.AllPermission;
    };

Similar Threads

  1. Replies: 1
    Last Post: 02-20-2001, 01:52 AM
  2. Replies: 0
    Last Post: 12-14-2000, 02:45 PM
  3. Replies: 0
    Last Post: 08-14-2000, 05:37 PM
  4. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM
  5. Java on the client web browser
    By Mark in forum Java
    Replies: 3
    Last Post: 06-03-2000, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center