[英]Java RMI java.security.AccessControlException: access denied
I'm writing a client-server program with Java RMI and I'm getting an error: 我正在使用Java RMI编写客户端服务器程序,但出现错误:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve") java.security.AccessControlException:访问被拒绝(“ java.net.SocketPermission”“ 127.0.0.1:1099”“ connect,resolve”)
My code looks like this: 我的代码如下所示:
package xxx;
import java.rmi.Naming;
import java.rmi.RemoteException;
public class Server extends Engine implements RemoteInterface {
public Server() {
super();
if(System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
Naming.rebind("Test", this);
System.out.println("Bound in registry!");
} catch(Exception ex) {
System.out.println(ex);
}
}
@Override
public void test() throws RemoteException {
System.out.println("test() invoked");
}
}
What's wrong? 怎么了?
I had forgot to add the registry and to implement Serializable. 我忘了添加注册表并实现Serializable。 Problem solved. 问题解决了。 I also removed the SecurityManager. 我还删除了SecurityManager。
You have installed a SecurityManager but you haven't granted yourself enough permissions to execute this code. 您已经安装了SecurityManager,但尚未授予自己足够的权限来执行此代码。
Why do you think you need a SecurityManager at all? 为什么您认为根本需要SecurityManager? Unless you are planning to run uploaded code I would just get rid of it 除非您打算运行上传的代码,否则我将摆脱它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.