aspose file tools*
The moose likes Java in General and the fly likes Access Control Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Access Control Exception" Watch "Access Control Exception" New topic
Author

Access Control Exception

Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
Hi, im facing the following error, with the code below. java.security.AccessControlException: access denied (java.net.SocketPermission Rohit-PC Resolve )

I even tried to implement grant permission method with following code.

grant {
permission java.net.SocketPermission
"Rohit-PC", "connect,resolve";


But im still facing errors. If you have any solution can you please resolve it.

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
It would be helpful if you have posted the remote interface and the impl class.

Anyhow I have written custom classes. The issue seems to be in setting policy.

My policy.txt file contents -



My VM arguments (I ran using Eclipse)



I am giving the classes with which I tried. I took the liberty to remove some lines of code.

RMIServer


Remote Interface



Implementation class


John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Two other issues i noted -

1. You have used the same port to create registry and register the service
2. URL you used was malformed. I have preceded it with rmi.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
I even tried to implement grant permission method with following code.

grant {
permission java.net.SocketPermission
"Rohit-PC", "connect,resolve";

Reiterating - This should be saved in a file and given as VM argument. Should not be implemented in code. Please read Running RMI
Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
Hi,
As part of creating policy files, im not running RMIregistry. Here im working with Remote object parameters. In which a client obtain a remote reference, it can be returned to the client for a method call.

Im Attaching all the code files i have now.

For Hello.java

And here i need a MessageObject, so the program for MessageObject.java is



PRogram for RMIServer.java


Here the program for RMIClient.java

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Was the error resolved after giving the policy file as a VM argument? Your previous post did not mention what you tried and the errors you still receive.
Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
Hi john when im trying to run the policy file as VM argument in command prompt. The file is not recognized as batch file. Sorry for posting late reply was out of internet.
Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
I created policy file as you said, below is the policy file

grant codeBase "file:/C:/Users/Rohit/Desktop/mywork/RMI/RMIParameters" {
permission java.security.AllPermission;
};


Now, how do i run it as virtual machine. Because i have 2 RMIserver and RMIClient. Do i need to create policy files for both. But both files are in same folder. So, 1 policy file is ok.
And im running the RMIParameters,i dont need to run registry file to execute.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hope you gave below VM parameters while running. I am not understanding on what registry file you are trying to execute.


If your goal is to create a simple RMI i think you can forbid using RMISecurityManager.... ah well good luck
Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
Im unable to pass VM parameters. Because im executing the files in command prompt. When i try to execute -Djava:"file:/C:/Users/Rohit/Desktop/mywork/RMI/RMIParameters". The erros says its not recognized as batch file.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Running RMI sample program
It's like running any other program using the java cmd.

Sample ->
Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
Yeah i tried the same, but im still facing the error. Batch file not found

IVe tried java -cp C:/Users/Rohit/Desktop/mywork/RMI/RMIParameters
-Djava.rmi.server.codebase=file:/ C:/Users/Rohit/Desktop/mywork/RMI/RMIParameters

Error -Djava.rmi.server.codebase is not recognized as internal or external command
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access Control Exception