• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

RMI SocketPermission exception from Applet - works from Netbeans

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created an RMI server and an applet that accesses the server.

When I run the applet from Netbeans, everything works great and I get the response back from the server. I have also created a non-applet client and that seems to work as well.
Even though the code was developed using Netbeans, I didn't use any of the GUI tools.

If I run it from my browser (either FireFox or IE), the applet loads, but when I push the button that calls the RMI method I get the following exception:

java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)

I have found lots of topics and tips on this, but can't really seem to get anything to work.

This is the first RMI server / applet combination I have written, so bear with me if it's an obvious problem.

Server Code:







Applet:


HTML


I have verified that the server is running using the netstat command.
I am running Java version 1.6.0_13.
Also, I'm just trying to get this to work, that's why the getLargestPrime method is really rather useless....

Any help on this would be greatly appreciated!
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You got a SocketPermission exception. And what does this tell you? What port are you using on the client and server? These ports should match. 1099 for server then 1099 for client.

Not sure if this may relate to security since applets have their own sandbox restrictions. And RMI security manager may or may not help. Did you use one?

Before you change any code, try it with the appletviewer.
 
Tannis Bo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm thinking SocketPermission exception indicates that the socket the client is attempting to connect to and the socket the server is listening on are different. I started the rmiregistry explicitly like 'start rmiregistry 1099' just to make sure it is using the expected port. After I started the RMI Server, I ran netstat and found this line 'TCP 192.168.0.100:1099 myPC:49695 ESTABLISHED'. The IP address here corresponds to my PCs IP address.

Using the appletviewer, I'm getting the same Exception as I'm getting from the browsers. Here is the Stacktrace:

java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
at java.net.Socket.connect(Socket.java:513)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:180)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at tme4.PrimeGeneratorApplet$PGCalculator.actionPerformed(PrimeGeneratorApplet.java:74)
at java.awt.Button.processActionEvent(Button.java:392)
at java.awt.Button.processEvent(Button.java:360)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Am I correct in my understanding that the RMI Server will use the same port as the RMI Registry?

As far as using a security manager, I didn't have much luck, however it could have been that I didn't fully understand how to use it. Also, I thought that the security manager was for applications and not for applets?

I was just reading some documentation that talked about hosting both the applet, server and html on a webserver. Do I need to be doing this? (Very new to all of this!) I realize if I want the world to see it, it needs to be hosted, but I just need it to work locally.
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you running this on Windows or Unix? On windows if your IP address is say 192.168.0.100 then the server log should say "192.168.0.100:1099" but I it said "127.0.0.1:1099". Only unix can produce 127.0.0.1 without changing the networking hosts file.

Also how are you binding your remote object? I'm not sure if applet binds with RMI different from application or not because your applet code does not have some sort of lookup code for the RMI remote object that applications do.

For your server main method, try adding the createRegistry line and specifying the rmi protocol:
 
Tannis Bo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have made the code changes you suggested and am now getting the following Exception when I attempt to run the client:

tme4.PrimeGenServer PrimeGenServer Port already in use: 1099; nested exception is java.net.BindException: Address is already in use: JVM_Bind

I am assuming I am getting this because the RMI Registry is using port 1099. I checked before I ran the 'start rmiregistry' command and nothing was running on port 1099.

I am running on Windows [Vista 32-bit].

I guess the part of this that perplexes me is what is Netbeans doing that allows the Applet to run from the IDE with no issues?

Unfortunately I have no other option but to run this as an Applet as that is the requirement...
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you need to change the client code


Try that and see it dislike that. You may get another error.
 
Tannis Bo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
I made the change to the Applet code and now I'm getting the same error but it is referencing the 127.0.0.1:1099 IP, even though I hard coded my regular IP in the java.

 
Tannis Bo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So..... I finally got this working with the original code I had.

The problem the entire time was the java.policy file in the jre/lib/security folder. I had done a search for a 'java.policy' file on my PC when I was trying to diagnose the issue, but apparently the default search in Vista doesn't look at non-indexed files, even if you say to look at all files.

I replaced the default with a 'grant all permissions' file and voila everything is working! Now, I just need to figure out how to do this in a more appropriate fashion as I really don't want to be giving all permissions to all java files...

Thanks K. Tsang for all the pointers and assistance - I learned quite a bit during the whole process!



 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice to hear that you got it working. Well you are running applet and applets are bound by that sandbox security issue. I guess you can play around with the policy file and set it to the most secured way (ie allowing least privilege).
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic