Java RMI - Socket Permission issues

北城余情 提交于 2019-12-24 05:38:26

问题


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.


回答1:


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 :)



来源:https://stackoverflow.com/questions/2329052/java-rmi-socket-permission-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!