Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Exception occured: java.security.AccessControlException: access denied.....

843793Aug 4 2008 — edited Aug 5 2008
Ive been trying this example for the last 9 days and found a lot of ideas and help inline but ive finally decided to ask for help. Ive tried almost everything so if anyone can help me, Id really appreciate it. Im only trying to use this on one pc at the moment.

I run and compile as follows from a batch file:
cd RMIProject/src
javac *.java
rmic imcImpl
start rmiregistry 1099
start java -Djava.security.policy=policy imcServer 127.0.0.1:1099
java -Djava.security.policy="C:/rmiproject/src/policy.policy" imcClient 127.0.0.1:1099

And get the following error:

C:\RMIProject\src>start java -Djava.security.policy=policy imcServer 127.0.0.1:1099

C:\RMIProject\src>java -Djava.security.policy="C:/rmiproject/src/policy.policy" imcClient 127.0.0.1:1099
starting client
middle client
INSIDE CLIENT 1 127.0.0.1:1099
Client Exception occured: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)

C:\RMIProject\src>

My CLASSPATH IS C:\Sun\SDK\jdk\bin;.;C:\RMIProject\src\
My Path IS C:\Sun\SDK\jdk\bin;.;C:\RMIProject\src\


My

What do I need to do? Im about to do crazy from it! Please and thank you.



Server-
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class imcServer
{
	public static void main(String[] argv)
    	{
		System.out.println("Inside Server");
		System.setProperty("java.security.policy", "C:/RMIProject/src/policy.policy/");
		System.setSecurityManager(new RMISecurityManager());
            try
 	      {
      		System.out.println("Server-is-done ");
			imcImpl implementation = new imcImpl("imcImplInstance");
	      }
		catch (Exception e)
        	{
        		System.out.println("Server-Exception occurred: " + e);
       
		System.out.println("leaving server");
	}
}
Client -
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.util.Date;

public class imcClient
{
	public static void main(String[] argv)
      {
		System.out.println("starting client");
		System.setProperty("java.security.policy", "C:/RMIProject/src/policyc.policy/");

            System.setSecurityManager(new RMISecurityManager());
            if (argv.length != 1)
            {
       		System.out.println("usage: java imcClient <IP Address of host running RMI server>");
                  System.exit(0);
            }            
		System.out.println("middle client");
            String serverName = argv[0];
		System.out.println("INSIDE CLIENT 1 "+ serverName);
            try
            {
          		//bind server object to object in client
            	imcInterface myServerObject = (imcInterface) 
                Naming.lookup	("rmi://localhost/imcImplInstance");
                  //invoke method on server object
                  Date d = myServerObject.getDate();
                  System.out.println("Date on server is " + d);
            }
            catch(Exception e)
            {
             	System.out.println("Client Exception occured: " + e);
                	System.exit(0);
            }
            System.out.println("RMI connection successful");
	}
}
Interface -
public interface imcInterface extends java.rmi.Remote //must have extension

{
	public java.util.Date getDate() throws java.rmi.RemoteException; //must have extension

}
Implementation -
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class imcImpl extends UnicastRemoteObject implements imcInterface
{
  	public imcImpl(String name) throws RemoteException
	{
  		super();
        try
        {
        	Naming.rebind(name, this);
        }
               
		catch(Exception e)
		{
        System.out.println("Exception occurred: " + e);
		}    
	}
        
	public java.util.Date getDate()
	{
		return new java.util.Date();       
	}
}
Policy
grant {
	// Allow everything for now
	permission java.security.AllPermission;
};
Edited by: beermat10 on Aug 4, 2008 6:20 PM

Edited by: beermat10 on Aug 4, 2008 6:21 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 2 2008
Added on Aug 4 2008
2 comments
166 views