RMI Server拒绝启动:java.security.AccessControlException:拒绝访问(" java.net.SocketPermission"" 127.0.0.1:1099"" connect,resolve")

时间:2015-06-25 11:23:49

标签: java server rmi accesscontrolexception

好的,所以我试着谷歌这个并尝试了一百万种不同的东西,但都没有帮助。

目前,我正在使用以下命令启动我的服务器:

java -Djava.security.policy=rmi_generated.policy -Djava.security.debug=access,failure MainLauncher aiserver.AIServer

MainLauncher基本上只是加载bin /和lib /到类路径+调用aiserver.AIServer.main,不应该真正影响与此相关的任何内容。

这是启动实际服务器的部分:

PolicyFileGenerator.generate();
if (System.getSecurityManager() == null)
        System.setSecurityManager ( new RMISecurityManager() );
try {
    Naming.bind("AIService",server);
} catch (MalformedURLException | RemoteException
        | AlreadyBoundException ex) {
        throw new RuntimeException("failed binding server",ex);
}

这是我得到的例外:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at lib.ClassPathHack.launch(ClassPathHack.java:62)
    at MainLauncher.main(MainLauncher.java:7)
Caused by: java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
    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.<init>(Socket.java:434)
    at java.net.Socket.<init>(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:342)
    at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
    at java.rmi.Naming.bind(Naming.java:128)
    at com.kt.commons.services.RMIServerHelper.register(RMIServerHelper.java:86)
    at aiserver.AIServer.main(AIServer.java:13)

以下是生成的RMI策略文件的当前内容。它将生成为./rmi_generated.policy。

grant codeBase "file:/home/jp/projects/aiservice/bin" {
    permission java.security.AllPermission;
    permission java.net.SocketPermission "localhost:1099", "connect, resolve";
    permission java.net.SocketPermission "127.0.0.1:1099", "connect, resolve";
    permission java.net.SocketPermission "localhost:80", "connect, resolve";

};

当我提供-Djava.security.debug = access,failure flag时,JVM就会呕吐。

jp@jp-ThinkPad-Edge-E530 ~/projects/aiservice $ java -Djava.security.policy=rmi_generated.policy -Djava.security.debug=access,failure MainLauncher aiserver.AIServer
rmi_generated.policy
/home/jp/projects/aiservice
access: access allowed ("java.io.FilePermission" "/home/jp/projects/aiservice/lib/ktcommons.jar" "read")
access: access denied ("java.net.SocketPermission" "jp-ThinkPad-Edge-E530" "resolve")
java.lang.Exception: Stack trace
    at java.lang.Thread.dumpStack(Thread.java:1329)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:447)
    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:1456)
    at java.rmi.registry.LocateRegistry.getRegistry(LocateRegistry.java:158)
    at java.rmi.registry.LocateRegistry.getRegistry(LocateRegistry.java:123)
    at java.rmi.Naming.getRegistry(Naming.java:221)
    at java.rmi.Naming.bind(Naming.java:123)
    at com.kt.commons.services.RMIServerHelper.register(RMIServerHelper.java:86)
    at aiserver.AIServer.main(AIServer.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at lib.ClassPathHack.launch(ClassPathHack.java:62)
    at MainLauncher.main(MainLauncher.java:7)
access: access allowed ("java.security.SecurityPermission" "getPolicy")
access: access allowed ("java.io.FilePermission" "/home/jp/projects/aiservice/lib/ktcommons.jar" "read")
access: domain that failed ProtectionDomain  (file:/home/jp/projects/aiservice/lib/ktcommons.jar <no signer certificates>)
 sun.misc.Launcher$AppClassLoader@73d16e93
 <no principals>
 java.security.Permissions@73035e27 (
 ("java.lang.RuntimePermission" "exitVM")
 ("java.lang.RuntimePermission" "stopThread")
 ("java.net.SocketPermission" "localhost:0" "listen,resolve")
 ("java.io.FilePermission" "/home/jp/projects/aiservice/lib/ktcommons.jar" "read")
 ("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" "/usr/lib/jvm/java-8-oracle/jre/lib/amd64/libnet.so" "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:1329)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:447)
    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.<init>(Socket.java:434)
    at java.net.Socket.<init>(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:342)
    at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
    at java.rmi.Naming.bind(Naming.java:128)
    at com.kt.commons.services.RMIServerHelper.register(RMIServerHelper.java:86)
    at aiserver.AIServer.main(AIServer.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at lib.ClassPathHack.launch(ClassPathHack.java:62)
    at MainLauncher.main(MainLauncher.java:7)
access: access allowed ("java.security.SecurityPermission" "getPolicy")
access: access allowed ("java.io.FilePermission" "/home/jp/projects/aiservice/lib/ktcommons.jar" "read")
access: domain that failed ProtectionDomain  (file:/home/jp/projects/aiservice/lib/ktcommons.jar <no signer certificates>)
 sun.misc.Launcher$AppClassLoader@73d16e93
 <no principals>
 java.security.Permissions@483bf400 (
 ("java.lang.RuntimePermission" "exitVM")
 ("java.lang.RuntimePermission" "stopThread")
 ("java.net.SocketPermission" "localhost:0" "listen,resolve")
 ("java.io.FilePermission" "/home/jp/projects/aiservice/lib/ktcommons.jar" "read")
 ("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")
)


Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at lib.ClassPathHack.launch(ClassPathHack.java:62)
    at MainLauncher.main(MainLauncher.java:7)
Caused by: java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
    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.<init>(Socket.java:434)
    at java.net.Socket.<init>(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:342)
    at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
    at java.rmi.Naming.bind(Naming.java:128)
    at com.kt.commons.services.RMIServerHelper.register(RMIServerHelper.java:86)
    at aiserver.AIServer.main(AIServer.java:13)
    ... 6 more

根据我的googled,可能的原因是JVM找不到我的.policy文件,但是这似乎不是这种情况,因为如果我在策略文件中插入一些语法错误,我会收到不同的错误消息

另一个常见原因似乎是策略文件中的codeBase路径不正确。为了排除这一点,我尝试了以下方法:

  • 的文件:/家庭/ JP /项目/ aiservice /
  • 的文件:/家庭/ JP /项目/ aiservice /
  • 文件:/首页/ JP /项目/ aiservice / *
  • 文件:/首页/ JP /项目/ aiservice /箱
  • 文件:/首页/ JP /项目/ aiservice /斌/
  • 文件:/首页/ JP /项目/ aiservice /斌/ *
  • 的文件:/家庭/ JP /项目/ aiservice / SRC
  • 的文件:/家庭/ JP /项目/ aiservice / SRC /
  • 文件:/首页/ JP /项目/ aiservice / src目录/ *

这些都没有帮助。

是的,我正在运行rmiregistry。

我也试过用sudo做这一切。

FWIW我正在运行的java版本是:

java版&#34; 1.8.0_25&#34; Java(TM)SE运行时环境(版本1.8.0_25-b17) Java HotSpot(TM)64位服务器VM(内置25.25-b02,混合模式)

在Linux Mint 17.1上

1 个答案:

答案 0 :(得分:0)

事实证明,我需要为几个不同的代码库授予权限才能实现这一目的。

授予codeBase“file:/ home / jp / projects / aiservice / bin”{...

授予codeBase“file:/ home / jp / projects / aiservice /”{...

grant codeBase“file:/home/jp/projects/aiservice/lib/ktcommons.jar”{...

它还没有用,但是嘿,至少我现在得到一个不同的例外了!