I met this issue and tried for long time, still couldn't solve it. All the solutions in similar topics in stackoverfflow have been tried but not useful for me. Any help would be really appreciate!!
Errors:
Set initial logic: Analyzer_ADD
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException:AnalyzerLogicAdd (no security manager: RMI class loader disabled)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy0.loadLogicFromRepository(Unknown Source)
at exampleSAS.logicRepository.LocalLogicRepository.loadLogicFromRepository(LocalLogicRepository.java:61)
at exampleSAS.adaptationLogic.AdaptationLogicService.implementLogic(AdaptationLogicService.java:50)
at exampleSAS.MainStarter.main(MainStarter.java:18)
Caused by: java.lang.ClassNotFoundException: AnalyzerLogicAdd (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at sun.rmi.server.UnicastRef.unmarshalValue(Unknown Source)
... 7 more
I have both server.policy file in RMI server project, and client.policy in RMI client project:
grant {
permission java.security.AllPermission ;
};
and I specified VM arguments for server project:
-Djava.rmi.server.codebase=file:C:\workspace\Repository\ -Djava.security.policy=C:\workspace\Repository\server.policy
for client project:
-Djava.rmi.server.codebase=file:C:\workspace\Repository\ -Djava.security.policy=C:\workspace\SAS\client.policy
And the starter code for server:
public static void main(String[] args) {
try {
LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
System.setProperty("java.security.policy", "AllPermission.policy");
//create a local instance of the object and export the service
LogicRepository rep = LogicRepository.getInstance();
ILogicRepository stub = (ILogicRepository)UnicastRemoteObject.exportObject(rep, 0);
Registry registry = LocateRegistry.getRegistry();
registry.rebind(SasConstants.LOGIC_REPOSITORY, stub);
System.out.println("Logic Repository has been started");
} catch (RemoteException e) {
e.printStackTrace();
}
}
I know here are duplicated policy setting with VM arguments, but even I delete this it still doesn't work.
Somehow I think the security manager is not working, could anyone please help here?
The server could launch normally, and client could also call simple method like helloWorld in server, but when I tried to return an object, the errors come out.
Many thanks! Regards,Tony
After adding setSecurityManager, I got error "access denied". The code and error are following:
public static void main(String[] args) {
try {
LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
System.setProperty("java.security.policy", "AllPermission.policy");
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
......
Error stack:
access: access allowed ("java.io.FilePermission" "C:\workspace\Repository\bin" "read")
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" "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 denied ("java.net.SocketPermission" "TONYYANG70FC" "resolve")
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Unknown Source)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.InetAddress.getLocalHost(Unknown Source)
at java.rmi.registry.LocateRegistry.getRegistry(Unknown Source)
at java.rmi.registry.LocateRegistry.getRegistry(Unknown Source)
at java.rmi.registry.LocateRegistry.getRegistry(Unknown Source)
at LogicRepositoryStarter.main(LogicRepositoryStarter.java:37)
access: access allowed ("java.security.SecurityPermission" "getPolicy")
access: access allowed ("java.io.FilePermission" "C:\workspace\Repository\bin" "read")
access: domain that failed ProtectionDomain (file:/C:/workspace/Repository/bin/ <no signer certificates>)
sun.misc.Launcher$AppClassLoader@387f44
<no principals>
java.security.Permissions@17c264 (
("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")
("java.io.FilePermission" "\C:\workspace\Repository\bin\-" "read")
("java.lang.RuntimePermission" "exitVM")
("java.lang.RuntimePermission" "stopThread")
("java.net.SocketPermission" "localhost:0" "listen,resolve")
)
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" "C:\Program Files\Java\jre1.8.0_40\bin\net.dll" "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(Unknown Source)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at LogicRepositoryStarter.main(LogicRepositoryStarter.java:38)
access: access allowed ("java.security.SecurityPermission" "getPolicy")
access: access allowed ("java.io.FilePermission" "C:\workspace\Repository\bin" "read")
access: domain that failed ProtectionDomain (file:/C:/workspace/Repository/bin/ <no signer certificates>)
sun.misc.Launcher$AppClassLoader@387f44
<no principals>
java.security.Permissions@81197d (
("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")
("java.io.FilePermission" "\C:\workspace\Repository\bin\-" "read")
("java.lang.RuntimePermission" "exitVM")
("java.lang.RuntimePermission" "stopThread")
("java.net.SocketPermission" "localhost:0" "listen,resolve")
)
Exception in thread "main" java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at LogicRepositoryStarter.main(LogicRepositoryStarter.java:38)
With more information which better expose this issue:
In the client, I successfully called the methods of the server class:
print() which just says hello world
loadLogicFromRepository(type, logicID)
Client code:
protected ILogicRepository server;
private void initializeRMI() {
Registry registry;
try {
registry = LocateRegistry.getRegistry();
server = (ILogicRepository) registry.lookup(FesasConstants.LOGIC_REPOSITORY);
} catch (RemoteException | NotBoundException e) {
e.printStackTrace();
}
try {
//TODO: check, that the correct meta data is used (string with the ID at the beginning)
server.print();
return server.loadLogicFromRepository(type, logicID);
} catch (RemoteException | LogicNotFoundException e) {
e.printStackTrace();
}
}
code for server.loadLogicFromRepository :
public ILogic loadLogicFromRepository(LogicType type, String logicID) throws RemoteException, LogicNotFoundException {
AnalyzerLogicAdd logic =new AnalyzerLogicAdd();
return logic;
}
It does nothing but just return an object of another server class AnalyzerLogicAdd, which implements serialisable interface
And this object is very important for me to get from server.
Just defining a security policy doesn't install a security manager. You have to do that explicitly, and afterwards.