This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access Control Exception

 
Laxmi Bhavisetti
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Running RMI sample program
It's like running any other program using the java cmd.

Sample ->
 
Laxmi Bhavisetti
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic