java.security.AccessControlException:访问被拒绝异常
我正在尝试为 RMI 编写一个简单的程序。但是,我在运行该行时遇到以下异常 Naming.rebind("接口名称",Remoteserverobject);
java.security.AccessControlException: 拒绝访问 (java.net.SocketPermission 127.0.0.1:1099 连接,解析)
我的代码如下:
public static void main(String[] args) throws Exception {
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
}
Remoteserver objremoteserver=new Remoteserver();
objremoteserver.setmsg("Hello! How are you?");
System.out.println(objremoteserver.getmsg());
try
{
Naming.rebind("Remotemethod", objremoteserver);
System.out.println("Server Started");
}
catch(RemoteException re)
{
System.out.println(re.getLocalizedMessage());
}
finally
{
System.out.println("Unknown Exception Occured!!!!");
}
}
如何克服这个问题。提前致谢
I'm trying to do a simple program for RMI. But, I'm getting the following exception while running the line
Naming.rebind("interfacename",Remoteserverobject);
java.security.AccessControlException:
access denied
(java.net.SocketPermission
127.0.0.1:1099 connect,resolve)
My Code is as follows:
public static void main(String[] args) throws Exception {
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
}
Remoteserver objremoteserver=new Remoteserver();
objremoteserver.setmsg("Hello! How are you?");
System.out.println(objremoteserver.getmsg());
try
{
Naming.rebind("Remotemethod", objremoteserver);
System.out.println("Server Started");
}
catch(RemoteException re)
{
System.out.println(re.getLocalizedMessage());
}
finally
{
System.out.println("Unknown Exception Occured!!!!");
}
}
How to overcome this problem. Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要使用安全管理器,除非 (i) 您知道您需要一个安全管理器并且 (ii) 您已经编写了适当的 .policy 文件。如果您认为这两者都适用,请使用 -Djava.security.debug=access,failure 运行您的问题,看看到底出了什么问题。您很可能没有授予自己所需的权限,或者没有正确指定策略文件位置。
Don't use a security manager unless (i) you know you need one and (ii) you have written an appropriate .policy file. If you think both these apply, run your problem with -Djava.security.debug=access,failure to see what is really going wrong. Most likely you haven't granted yourself the required permission or you haven't specified the policy file location correctly.
我想这可行
每个 JRE 都有一个默认的安全管理器,您试图用新的安全管理器覆盖。您没有为这个新的安全管理器指定任何属性。因此会出现错误。解决方案是使用默认管理器,按照这些 说明。
i guess this works
Every JRE has a default security manager, U r trying to override with a new security manager. You dint specify any properties to this new security manager.so the error.The solution is use the default manager are create a completely new security manager following these instructions.
确保您已按照此处的说明设置 RMISecurityManager
Make sure you have setup the RMISecurityManager as explained here