我遇到了这个问题并且尝试了很长时间,仍然无法解决它。 stackoverfflow中类似主题的所有解决方案都已尝试过但对我没用。任何帮助都会非常感激!!
错误:
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
我在RMI服务器项目中有server.policy文件,在RMI客户端项目中有client.policy:
grant {
permission java.security.AllPermission ;
};
我为服务器项目指定了VM参数:
-Djava.rmi.server.codebase=file:C:\workspace\Repository\ -Djava.security.policy=C:\workspace\Repository\server.policy
用于客户项目:
-Djava.rmi.server.codebase=file:C:\workspace\Repository\ -Djava.security.policy=C:\workspace\SAS\client.policy
服务器的入门代码:
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();
}
}
我知道这里有使用VM参数的重复策略设置,但即使我删除它仍然无效。
不知怎的,我认为安全经理没有工作,有人可以帮忙吗?
服务器可以正常启动,客户端也可以在服务器中调用helloWorld这样的简单方法,但是当我尝试返回一个对象时,错误就会出现。
非常感谢! 的问候,贝
添加setSecurityManager后,我收到错误“访问被拒绝”。代码和错误如下:
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());
}
......
错误堆栈:
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)
有更多信息可以更好地揭露这个问题:
在客户端,我成功调用了服务器类的方法:
print(),它只是说你好世界
loadLogicFromRepository(type,logicID)
客户代码:
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();
}
}
server.loadLogicFromRepository的代码:
public ILogic loadLogicFromRepository(LogicType type, String logicID) throws RemoteException, LogicNotFoundException {
AnalyzerLogicAdd logic =new AnalyzerLogicAdd();
return logic;
}
它只会返回另一个服务器类AnalyzerLogicAdd的对象,它实现了可序列化的接口
这个对象对我来说非常重要。
答案 0 :(得分:1)
仅定义安全策略不会安装安全管理器。你必须明确地做,然后再做。