1

I am trying to run my first Java RMI client-server app with the following command line input.

java -cp eclipse-workspace -Djava.rmi.server.codebase=file:/eclipse-workspace -Djava.rmi.server.hostname=localhost -Djava.security.policy=rmidemo.policy -Djava.security.debug=access ct/ExamEngine

The rmidemo.policy file:

grant codeBase "file:/Users/user/eclipse-workspace/rimdemo/src/ct" {
permission java.security.AllPermission;

};

The stack trace is:

access: access allowed ("java.io.FilePermission" "/Users/user/eclipse-workspace" "read") access: access allowed ("java.security.SecurityPermission" "getProperty.networkaddress.cache.ttl") access: access allowed ("java.util.PropertyPermission" "sun.net.inetaddr.ttl" "read") access: access allowed ("java.security.SecurityPermission" "getProperty.networkaddress.cache.negative.ttl") access: access allowed ("java.util.PropertyPermission" "com.sun.sdp.conf" "read") access: access allowed ("java.lang.RuntimePermission" "loadLibrary.net") access: access allowed ("java.io.FilePermission" "/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libnet.dylib" "read") access: access allowed ("java.lang.RuntimePermission" "modifyThreadGroup") access: access allowed ("java.lang.RuntimePermission" "modifyThreadGroup") access: access allowed ("java.lang.RuntimePermission" "getClassLoader") access: access allowed ("java.lang.RuntimePermission" "modifyThreadGroup") access: access allowed ("java.lang.RuntimePermission" "modifyThread") access: access allowed ("java.lang.RuntimePermission" "setContextClassLoader") access: access allowed ("java.lang.RuntimePermission" "modifyThread") access: access allowed ("java.util.PropertyPermission" "sun.rmi.dgc.logLevel" "read") access: access allowed ("java.util.logging.LoggingPermission" "control") access: access allowed ("java.util.logging.LoggingPermission" "control") access: access allowed ("java.util.PropertyPermission" "java.rmi.dgc.leaseValue" "read") access: access allowed ("java.util.PropertyPermission" "sun.rmi.dgc.checkInterval" "read") access: access allowed ("java.util.logging.LoggingPermission" "control") access: access allowed ("java.util.logging.LoggingPermission" "control") access: access allowed ("java.util.PropertyPermission" "sun.rmi.runtime.schedulerThreads" "read") access: access allowed ("java.lang.RuntimePermission" "sun.rmi.runtime.RuntimeUtil.getInstance") access: access allowed ("java.lang.RuntimePermission" "getProtectionDomain") access: access allowed ("java.util.PropertyPermission" "jdk.internal.lambda.dumpProxyClasses" "read") access: access allowed ("java.lang.reflect.ReflectPermission" "suppressAccessChecks") access: access allowed ("java.util.PropertyPermission" "sun.rmi.transport.dgcFilter" "read") access: access allowed ("java.security.SecurityPermission" "getProperty.sun.rmi.transport.dgcFilter") access: access allowed ("java.lang.RuntimePermission" "setContextClassLoader") access: access allowed ("java.util.PropertyPermission" "java.rmi.server.hostname" "read") access: access allowed ("java.lang.reflect.ReflectPermission" "suppressAccessChecks") access: access allowed ("java.lang.reflect.ReflectPermission" "suppressAccessChecks") access: access allowed ("java.lang.RuntimePermission" "setContextClassLoader") access: access allowed ("java.lang.RuntimePermission" "getClassLoader") access: access allowed ("java.lang.RuntimePermission" "modifyThreadGroup") access: access allowed ("java.lang.RuntimePermission" "modifyThread") access: access allowed ("java.lang.RuntimePermission" "setContextClassLoader") access: access allowed ("java.lang.RuntimePermission" "modifyThread") access: access allowed ("java.lang.RuntimePermission" "modifyThreadGroup") access: access allowed ("java.lang.RuntimePermission" "modifyThreadGroup") access: access allowed ("java.lang.RuntimePermission" "modifyThread") access: access allowed ("java.lang.RuntimePermission" "modifyThread") access: access allowed ("java.lang.RuntimePermission" "modifyThread") access: access allowed ("java.lang.reflect.ReflectPermission" "suppressAccessChecks") access: access allowed ("java.lang.reflect.ReflectPermission" "suppressAccessChecks") access: access allowed ("java.lang.reflect.ReflectPermission" "suppressAccessChecks") access: access allowed ("java.lang.reflect.ReflectPermission" "suppressAccessChecks") access: access denied ("java.net.SocketPermission" "MacBook-Pro.local" "resolve") java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Thread.java:1336) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:462) at java.security.AccessController.checkPermission(AccessController.java:884) at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) at java.lang.SecurityManager.checkConnect(SecurityManager.java:1048) at java.net.InetAddress.getLocalHost(InetAddress.java:1477) at java.rmi.registry.LocateRegistry.getRegistry(LocateRegistry.java:158) at java.rmi.registry.LocateRegistry.getRegistry(LocateRegistry.java:123) at java.rmi.registry.LocateRegistry.getRegistry(LocateRegistry.java:75) at ct.ExamEngine.main(ExamEngine.java:64) access: access allowed ("java.security.SecurityPermission" "getPolicy") access: access allowed ("java.io.FilePermission" "/Users/user/eclipse-workspace" "read") access: domain that failed ProtectionDomain (file:/Users/user/eclipse-workspace/ ) sun.misc.Launcher$AppClassLoader@2a139a55 java.security.Permissions@27bc2616 ( ("java.net.SocketPermission" "localhost:0" "listen,resolve") ("java.io.FilePermission" "/Users/user/eclipse-workspace/-" "read") ("java.lang.RuntimePermission" "exitVM") ("java.lang.RuntimePermission" "stopThread") ("java.util.PropertyPermission" "java.specification.version" "read") ("java.util.PropertyPermission" "java.version" "read") ("java.util.PropertyPermission" "os.arch" "read") ("java.util.PropertyPermission" "java.specification.vendor" "read") ("java.util.PropertyPermission" "java.vm.specification.name" "read") ("java.util.PropertyPermission" "java.vm.vendor" "read") ("java.util.PropertyPermission" "path.separator" "read") ("java.util.PropertyPermission" "os.version" "read") ("java.util.PropertyPermission" "file.separator" "read") ("java.util.PropertyPermission" "line.separator" "read") ("java.util.PropertyPermission" "java.vm.specification.vendor" "read") ("java.util.PropertyPermission" "java.specification.name" "read") ("java.util.PropertyPermission" "java.vendor.url" "read") ("java.util.PropertyPermission" "java.vendor" "read") ("java.util.PropertyPermission" "java.vm.version" "read") ("java.util.PropertyPermission" "java.vm.name" "read") ("java.util.PropertyPermission" "java.vm.specification.version" "read") ("java.util.PropertyPermission" "os.name" "read") ("java.util.PropertyPermission" "java.class.version" "read") )

access: access allowed ("java.util.PropertyPermission" "java.rmi.server.hostname" "read") access: access allowed ("java.util.PropertyPermission" "sun.rmi.transport.connectionTimeout" "read") access: access allowed ("java.util.PropertyPermission" "sun.rmi.transport.tcp.handshakeTimeout" "read") access: access allowed ("java.util.PropertyPermission" "sun.rmi.transport.tcp.responseTimeout" "read") access: access allowed ("java.lang.RuntimePermission" "sun.rmi.runtime.RuntimeUtil.getInstance") access: access allowed ("java.util.PropertyPermission" "jdk.net.ephemeralPortRange.low" "read") access: access allowed ("java.lang.RuntimePermission" "loadLibrary.net") access: access allowed ("java.io.FilePermission" "/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libnet.dylib" "read") access: access allowed ("java.util.PropertyPermission" "os.name" "read") access: access allowed ("java.util.PropertyPermission" "jdk.net.ephemeralPortRange.high" "read") access: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve") java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Thread.java:1336) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:462) at java.security.AccessController.checkPermission(AccessController.java:884) at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051) at java.net.Socket.connect(Socket.java:584) at java.net.Socket.connect(Socket.java:538) at java.net.Socket.(Socket.java:434) at java.net.Socket.(Socket.java:211) at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40) at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148) at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613) at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216) at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202) at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:338) at sun.rmi.registry.RegistryImpl_Stub.rebind(RegistryImpl_Stub.java:147) at ct.ExamEngine.main(ExamEngine.java:65) access: access allowed ("java.security.SecurityPermission" "getPolicy") access: access allowed ("java.io.FilePermission" "/Users/user/eclipse-workspace" "read") access: domain that failed ProtectionDomain (file:/Users/user/eclipse-workspace/ ) sun.misc.Launcher$AppClassLoader@2a139a55 java.security.Permissions@4fca772d ( ("java.net.SocketPermission" "localhost:0" "listen,resolve") ("java.io.FilePermission" "/Users/user/eclipse-workspace/-" "read") ("java.lang.RuntimePermission" "exitVM") ("java.lang.RuntimePermission" "stopThread") ("java.util.PropertyPermission" "java.specification.version" "read") ("java.util.PropertyPermission" "java.version" "read") ("java.util.PropertyPermission" "os.arch" "read") ("java.util.PropertyPermission" "java.specification.vendor" "read") ("java.util.PropertyPermission" "java.vm.specification.name" "read") ("java.util.PropertyPermission" "java.vm.vendor" "read") ("java.util.PropertyPermission" "path.separator" "read") ("java.util.PropertyPermission" "os.version" "read") ("java.util.PropertyPermission" "file.separator" "read") ("java.util.PropertyPermission" "line.separator" "read") ("java.util.PropertyPermission" "java.vm.specification.vendor" "read") ("java.util.PropertyPermission" "java.specification.name" "read") ("java.util.PropertyPermission" "java.vendor.url" "read") ("java.util.PropertyPermission" "java.vendor" "read") ("java.util.PropertyPermission" "java.vm.version" "read") ("java.util.PropertyPermission" "java.vm.name" "read") ("java.util.PropertyPermission" "java.vm.specification.version" "read") ("java.util.PropertyPermission" "os.name" "read") ("java.util.PropertyPermission" "java.class.version" "read") )

ExamEngine exception: java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve") at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) at java.security.AccessController.checkPermission(AccessController.java:884) at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051) at java.net.Socket.connect(Socket.java:584) at java.net.Socket.connect(Socket.java:538) at java.net.Socket.(Socket.java:434) at java.net.Socket.(Socket.java:211) at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40) at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148) at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613) at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216) at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202) at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:338) at sun.rmi.registry.RegistryImpl_Stub.rebind(RegistryImpl_Stub.java:147) at ct.ExamEngine.main(ExamEngine.java:65)

[EDIT] If it wasn't already clear the issue lies with the security manager, when I removed it, it worked, but it is necessary for this app, so I need to figure out a way around this.

1 Answer 1

0

Try this...

Start the RMI Registry
rmiregistry &

To Start the server (don't forget the "&" at end so it runs in background)
Note: When the codebase property value is set to the URL of a directory, the value must be terminated by a "/".
-Djava.security.policy=/Users/user/eclipse-workspace/rimdemo/src/ct/rmidemo.policy -Djava.rmi.server.codebase=file:/Users/user/eclipse-workspace/rimdemo/src/ct/

To start a client
-Djava.security.policy=/Users/user/eclipse-workspace/rimdemo/src/ct/rmidemo.policy

Your server policy should be:

grant {

permission java.security.AllPermission;

};

Your client policy should be:

grant {

permission java.security.AllPermission;

};

Note: you can likely just use the same policy file for both client and server. Also note, your classpath needs to be the root directory of your class file tree

Sign up to request clarification or add additional context in comments.

6 Comments

Sorry my command line caused that for some reason. I used the same parms as you mentioned above but it causes that error.
I'm headed home back can try and research a little more tomorrow! Let me know if you get it working, I do recall someone else being fixed by making sure they were running the code within same folder as the class files.
I was able to get it running by removing the security manager but unfortunately it is necessary for this project.
@ConorNaylor, thanks for marking it as correct - I take it it worked?
I just got it working today, after some more grievance. Your answer is correct, but I still managed to make a mess of it. Thanks
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.