Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Setting RMI security policy.

Owen_Jun 28 2009 — edited Jul 2 2009
Hello people.

It appears that I am having problems configuring a security policy for a NetBeans Java client project. I'm not sure whether my problem is with the client or server or both.

Previously, I created a program that functioned as an agent, and, because each running instance of this agent used the same code base, no instance required that it get the code of an object from any other. However, I am now putting together client program to connect to one of these agents, and it appears that the client program needs the code of an object residing on the server. This is especially true when a client request throws an exception on the server.

All programs use localhost as they all run on my laptop.

On the client, I have created a policy file called client.policy in accordance with that given by [the Java RMI tutorial|http://java.sun.com/docs/books/tutorial/rmi/running.html]. It contains the following:
grant codeBase "file:./myproject/" {
    permission java.security.AllPermission;
};
This file resides in a directory called artefacts - accessible directly from when one opens the jar. From the NetBeans run panel of the project properties dialogue box, I have entered "-Djava.security.policy=./artefacts/client.policy" in the VM Options text.

I have done something similar, in accordance with the Java RMI tutorial on the server. When I build the server, I notice that no jar file has been created, but maybe that's a side point for now...

When I run the programs, I receive the following exception on the client:
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:12000 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 myproject.core.administrationclient.bootstrap.Loader.sendMessage(Loader.java:78)
        at myproject.core.administrationclient.bootstrap.Loader.executeClientCommand(Loader.java:67)
        at myproject.core.administrationclient.bootstrap.CommandWindow.commandActionPerformed(CommandWindow.java:70)
        at myproject.core.administrationclient.bootstrap.CommandWindow.access$000(CommandWindow.java:13)
        at myproject.core.administrationclient.bootstrap.CommandWindow$1.actionPerformed(CommandWindow.java:38)
        at javax.swing.JTextField.fireActionPerformed(JTextField.java:492)
        at javax.swing.JTextField.postActionEvent(JTextField.java:705)
        at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:820)
        at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1636)
        at javax.swing.JComponent.processKeyBinding(JComponent.java:2849)
        at javax.swing.JComponent.processKeyBindings(JComponent.java:2884)
        at javax.swing.JComponent.processKeyEvent(JComponent.java:2812)
        at java.awt.Component.processEvent(Component.java:5818)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4413)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
        at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:697)
        at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:962)
        at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:834)
        at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:661)
        at java.awt.Component.dispatchEventImpl(Component.java:4285)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Window.dispatchEventImpl(Window.java:2440)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Please give me some pointers as to what I'm going wrong. It would be much appreciated.

Thanks,

Owen.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 30 2009
Added on Jun 28 2009
34 comments
2,475 views