dcsimg
AccessControlException in RMI
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Unnikrishnan_Nair
Posted On:   Thursday, April 18, 2002 12:34 AM

Hi, I have created a simple RMI program. But when I am trying to run the same I am getting AccessControlException as below Exception in thread "main" java.security.AccessControlException: access denied ( java.net.SocketPermission 127.0.0.1:1099 connect,resolve) I have done the following steps . 1. Created Interface ad compiled. 2. Created Server program implementing this interface and extended UnicastRemoteObject and compiled successfully. 3. Created stub and skeleton using rmic 4. Created Client program in the same directory and compiled. I am including my client program here: import java.rmi.*; import java.net.*; public   More>>

Hi,
I have created a simple RMI program. But when I am trying to run the same I am getting AccessControlException as below

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


I have done the following steps .
1. Created Interface ad compiled.
2. Created Server program implementing this interface and extended UnicastRemoteObject and compiled successfully.
3. Created stub and skeleton using rmic
4. Created Client program in the same directory and compiled.

I am including my client program here:

			
import java.rmi.*;
import java.net.*;

public class RMIClient
{
public static void main(String args[])
throws java.net.UnknownHostException, RemoteException, NotBoundException,
java.net.MalformedURLException
{
if(System.getSecurityManager() == null)
{
System.setSecurityManager(new RMISecurityManager());
}
String url = "rmi://localhost/RMIServer";
System.out.println(url);
RMIInterface rmiInter = (RMIInterface)Naming.lookup(url);
rmiInter.setMessage("New Variable");
System.out.println(rmiInter.getMessage());
}
}
   <<Less

Re: AccessControlException in RMI

Posted By:   Sakibul_Khan  
Posted On:   Tuesday, April 23, 2002 10:38 PM

There is nothing wrong with your program, only that you are not RUNNING

it with the proper option.



You need to add a POLICY file, that specifies the correct Security option

Use the "policytool" that JDK provides to create the policy file OR you

can copy & paste my one. I am giving you the one that I always use:-



------------------------------------------------------------------------------------

grant {

permission java.net.SocketPermission "*:1024-65535", "connect,accept,resolve";

permission java.net.SocketPermission "*:80", "connect";

};

-------------------------------------------------------------------------------------



[N.B. if you get a RUNTIME error stating CANNOT parse policy file,

then it means that you did not write your policy file in the right way.

Hence, I would recomend you to use the "policytool" of JDK, which will

automatically create the policy file in your ROOT directory (for UNIX) OR

the C:Windows dir of Win]. By the way Don't add the dotted lines



Now save the above lines in any file like "myfile.policy", then when you run

your RMI program add the following line in the command line option

that you are currently using:-



-Djava.security.policy=myfile.policy



eg. If previously you were using

java -Djava.rmi.server.codebase=http://www.cs.mcgill.ca/~skhan20/cs/577/ myRMICLIENT 4000



then add the security option & it will become like this:-

java -Djava.rmi.server.codebase=http://www.cs.mcgill.ca/~skhan20/cs/577/ -Djava.security.policy=myfile.policy myRMICLIENT 4000





In my example, 4000 is just a port # that I am mentioning from the command

prompt, you can also hard-code the port # in both of your RMISERVER

& RMICLIENT.

Also, I have always added the policy files in both my

RMIservers & RMIclients. I know it is a MUST for RMIclients, but your program

may still work fine even if you DONT mention the policy file with your server.



If you still have problems, look in to the following file:-

http://www.cs.mcgill.ca/~skhan20/cs/utils_j/RMIsimpleexample.html

the example in here is short, simple & to the point. It tells you STEP by STEP the

procedures of how to install the RMISERVER & then connect a RMICLIENT

to it.
About | Sitemap | Contact