Java RMI - 套接字权限问题
我在尝试将我的 java 程序连接到 2 个不同的套接字时遇到问题。基本上我想初始化我的 RMI 服务器(连接到端口 1099),然后在端口 10002 上初始化 PrologBeans。初始化似乎对两者都工作得很好,但是当我尝试访问 prologBeans 时,我收到以下错误:
Exception in thread "main" java.security.AccessControlException: access denied
(java.net.SocketPermission 127.0.0.1:10002 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
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:519)
at java.net.Socket.connect(Socket.java:475)
at java.net.Socket.<init>(Socket.java:372)
at java.net.Socket.<init>(Socket.java:186)
at se.sics.prologbeans.PrologSession.connectToServer(PrologSession.java:511)
at se.sics.prologbeans.PrologSession.initSend(PrologSession.java:442)
at se.sics.prologbeans.PrologSession.send(PrologSession.java:368)
at se.sics.prologbeans.PrologSession.executeQuery(PrologSession.java:331)
at api.ActionRetriever.logEvent(ActionRetriever.java:68)
at contract.ContractManager.log_event(ContractManager.java:87)
at gui.RMITrial.main(RMITrial.java:39)
我也有一个策略文件(在我的 RMI 代码所在的包中。这是放置策略文件的正确位置还是应该在默认包中?),它设置为:
grant {
permission java.security.AllPermission;};
我想知道是否有人对为什么我收到 SocketPermission 错误?是不是我的权限设置有问题?
任何帮助将不胜感激。
谢谢。
I'm having problems trying to connect my java program to 2 different sockets. Basically I want to initialise my RMI Server (connecting to port 1099) and then also initialise PrologBeans on port 10002. The initialisation seems to work fine for both, but as soon as I try to access the prologBeans I get the following error:
Exception in thread "main" java.security.AccessControlException: access denied
(java.net.SocketPermission 127.0.0.1:10002 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
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:519)
at java.net.Socket.connect(Socket.java:475)
at java.net.Socket.<init>(Socket.java:372)
at java.net.Socket.<init>(Socket.java:186)
at se.sics.prologbeans.PrologSession.connectToServer(PrologSession.java:511)
at se.sics.prologbeans.PrologSession.initSend(PrologSession.java:442)
at se.sics.prologbeans.PrologSession.send(PrologSession.java:368)
at se.sics.prologbeans.PrologSession.executeQuery(PrologSession.java:331)
at api.ActionRetriever.logEvent(ActionRetriever.java:68)
at contract.ContractManager.log_event(ContractManager.java:87)
at gui.RMITrial.main(RMITrial.java:39)
I also have a policy file (in the package where my RMI code is. Is this even the correct place to place the policy file or should it be in the default package?), which is set to:
grant {
permission java.security.AllPermission;};
I was wondering if anyone has any idea on why I'm getting the SocketPermission error? Is my permission settings wrong?
Any help would be much appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要包含 VM 参数 -Djava.security.policy=path/to/policy/file...
然后你的策略文件应该被阅读,一切都会好起来:)
You need to include the VM argument -Djava.security.policy=path/to/policy/file...
and then your policy file should be read and all shall be fine :)