• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099

 
jay Singh Rana
Greenhorn
Posts: 11
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , I am trying to establish a RMI connection on my local computer. I have created a Server class and generated Skeletons for that through rmic . The jdk version i am using is jdk1.4. When i run the Server class it successfully binds with the default port and localhost. But when i run the client class i get this error message.- java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 .
Please note that i also thought that it could be a certificate issue and hence i copied Server and Client class in the same directory and tried, but still received the same error.
The exception is raise while executing the following line in client.java
registry.lookup(name);
I will appreciate if anyone can help. I am attaching my Server and Client class.





 
Simon Roberts
Author
Ranch Hand
Posts: 175
8
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably installed a SecurityManager (that's "normal" and often flat out necessary in RMI). If you did so, then it looks like you failed to grant your code the necessary permissions.

It's helpful, when learning this stuff, to create a security configuration that grants "AllPermission" to all code. That way, when you're learning the mechanics of the system, stuff works. Then, when it's working, you can / should reduce the permission set to the minimum actually required to work succesfully.
 
jay Singh Rana
Greenhorn
Posts: 11
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Simon for your feedback. I have verified that my Server is publishing my interface on the network. I verified it through netstat.

TCP jay-pc:1099 jay-pc.resource.labour.net:0 LISTENING
I have added full path for java.policy like:


and now when i test to see if anything i find anything in registry before lookup i get no value. I am testing it by doing this:

This shows that something is prohibiting my client to get the registry. It could be policy or anything else. I need your help in understanding what else i can try.

Thanks a mil
Jay
 
jay Singh Rana
Greenhorn
Posts: 11
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I managed to connect and get response from the Server when i kept the Server class and Client class in the same directory. I just checked through netstat that port 1099 was occupied by another process so i
changed the port to 3333 and i could get the response from server by calling my Client.
Now i am testing by keeping my Client and Server in two different projects. But i am getting the below error.



my question is do we have to copy the skelton classes which are generated by rmic to the Client directory?

 
Simon Roberts
Author
Ranch Hand
Posts: 175
8
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears you're using the default security configuration. That one prohibits almost everything. You need to create a more flexible policy file and use that instead.
 
jay Singh Rana
Greenhorn
Posts: 11
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Simon, I have been able to get connection. I just changed the java.policy file and granted access to all and it worked.
Now i am facing issues while transferring object over the network. I always get null value from the object at client side. The values are set on the server but when it reaches client it becomes null. Though if i set a string i can easily get that on the client side.
Here are my server and client classes.


This is the Client Class



Citizen Class

 
Simon Roberts
Author
Ranch Hand
Posts: 175
8
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects in RMI can be passed by value, or by reference. Your code looks like you're trying to have the server modify the object created by the client. For that, you need the client object to be passed by reference. That only happens if you export it as an RMI remote object. If you do that, it doesn't need to be Serializable. Serializable is use to pass by value, and since you never add the citizen to the array list in the server, then no copy of the modified object will ever get back to the client.

I suggest that pass by value is probably the more robust semantic, since passing references around, while very powerful, does mean you must address any potential concurrency issues.
 
jay Singh Rana
Greenhorn
Posts: 11
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Simon
Thanks for highlighting that i missed to add the citizen object to the list. I made that mistake while pasting the code into the code section. But actually i am adding citizen object in SaySomething() method.
I just want to achieve a scenario where i pass an object to the server(say in this case citizen ), and the server return that object with Values which can be used on the Client side.
In my example i am passing an empty citizen object to the Server and setting name and surname values to the object and returning it back to the client.
I strongly believe i am making mistake in implementing serialization, the reason being i can receive primitive values like Strings values from server but fail to receive object values.
I want your feedback if i am doing the below things correct:
1. I copied the generated Skelton server classes into my Client directory.
2. I have MyInterface interface on both client side and server side which extends Remote
3. I have Citizen class which implements Serializable,Remote
4. I have the citizen class on both Server and Client side.

Please guide me correcting anything thats not fine here.

regards
Jay
 
Simon Roberts
Author
Ranch Hand
Posts: 175
8
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're passing objects by value (copying the values and creating a new object on the receiving side) which I believe you are, then the objects in question should not be remote, and should not be exported. They should be Serializable, and nothing else.

If you make something into an exported Remote object, then the stub to it is passed around, and you're modifying the "server side" (i.e. original) object, not creating a new one and passing it around.
 
jay Singh Rana
Greenhorn
Posts: 11
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RESOLVED

I managed to resolve the issue where i was not able to receive values from my object which was set on the Server side. My object value always used to be null on the Client side.
I was only making one mistake of declaring the variables as static. I removed the static keyword and can pass the objects between Client and Server.
Rest of the things remains as its declared in my previous post.

Regards
Jay
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!