简体   繁体   English

Java RMI-访问另一台计算机上的RMI注册表对象-AccessControlException?

[英]Java RMI - Accessing RMI Registry Objects on a Different Machine - AccessControlException?

I'm attempting to get a client on one machine to talk to a server on another machine through Java RMI. 我正在尝试使一台计算机上的客户端通过Java RMI与另一台计算机上的服务器通信。 I deploy the server at host IP X on port Y. I then attempt to get the client to lookup the remote object on the server and I get the following exception: 我将服务器部署在端口Y上的主机IP X上。然后,我尝试让客户端在服务器上查找远程对象,但出现以下异常:

Exception in thread "main" java.security.AccessControlException: access denied (java.net.SocketPermission <IP address>:<port> connect,resolve)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
    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:524)
    at java.net.Socket.connect(Socket.java:478)
    at java.net.Socket.<init>(Socket.java:375)
    at java.net.Socket.<init>(Socket.java:189)
    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 nursestation.NurseStation.subscribeToPatients(NurseStation.java:65)
    at nursestation.NurseStation.<init>(NurseStation.java:42)
    at nursestation.perf.SimplePerfTest.main(SimplePerfTest.java:28)

Note that both the client and server are running with a policy file allowing all permissions. 请注意,客户端和服务器都使用允许所有权限的策略文件运行。 The RMI registry is running on the server as well. RMI注册表也在服务器上运行。 Any ideas as to why I'm getting this exception? 关于我为什么要得到这个例外的任何想法? What can I do to allow the client to talk to a server running on a different server? 我该怎么做才能使客户端与在其他服务器上运行的服务器通信?

Update: 更新:

Policy file 政策文件

grant {
  permission java.security.AllPermission;
};

Client Startup - Using RMI plugin for Eclipse 客户端启动-将RMI插件用于Eclipse

  1. Start the RMI registry 启动RMI注册表
  2. Executed "java BedsideMonitorMain patient1 vital1 vital2" with the specified policy file for java.security.policy shown above and java.rmi.server.codebase pointing to my project workspace code 使用上面显示的java.security.policy的指定策略文件和指向我的项目工作区代码的java.rmi.server.codebase执行“ java BedsideMonitorMain Patient1 vital1 vital2”
  3. The patient1 object is binded to the RMI registry Patient1对象绑定到RMI注册表

Server Startup 服务器启动

  1. Executed "java NurseStationMain patient1" with the specified policy file for java.security.policy shown above and java.rmi.server.codebase pointing to my project workspace code 使用上面显示的java.security.policy的指定策略文件和指向我的项目工作区代码的java.rmi.server.codebase执行“ java NurseStationMain Patient1”

So I figured out the underlying problem. 所以我找出了潜在的问题。 Apparently both machines had a different license key for the Eclipse RMI plugin, which did not allow both machines to communicate with each other. 显然,两台机器的Eclipse RMI插件具有不同的许可证密钥,该许可证密钥不允许两台机器相互通信。 When I made the license key on both machines identical, then I was able to get the client and server to communicate with each other. 当我使两台机器上的许可证密钥相同时,便能够使客户端和服务器相互通信。 For my purpose, this is sufficient, as I'm not using this system in a production environment (it's for a class project). 就我的目的而言,这已经足够了,因为我没有在生产环境中使用该系统(它是用于班级项目的)。 I am curious though what the "best" solution would be to this problem. 我很好奇这个问题的“最佳”解决方案是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM