简体   繁体   English

运行rmi程序时如何解决java.security.AccessControlException问题?

[英]How do I sort the java.security.AccessControlException issue when running rmi programs?

How do I sort the java.security.AccessControlException problem? 如何对java.security.AccessControlException问题进行排序? When I am running the myRMIServer,I am getting this exception? 运行myRMIServer时,出现此异常吗?

My codes: 我的代码:

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class myRMIServer
{
        public static void main(String[] argv)
                {
                System.setSecurityManager(new RMISecurityManager());
                try
                        {
                        myRMIImpl implementation = new myRMIImpl("myRMIImplInstance");
                        }
                catch (Exception e)
                        {
                        System.out.println("Exception occurred: " + e);
                        }
                }
}

public interface myRMIInterface extends java.rmi.Remote
{
        public java.util.Date getDate() throws java.rmi.RemoteException;
}

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class myRMIImpl extends UnicastRemoteObject implements myRMIInterface
{
        public myRMIImpl(String name) throws RemoteException
                {
                super();
                try
                        {
                        Naming.rebind(name, this);
                        }
                catch(Exception e)
                        {
                        System.out.println("Exception occurred: " + e);
                        }
                }
        public java.util.Date getDate()
                {
                return new java.util.Date();
                }
}

Output 输出量

Exception occurred: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)

How do I solve this problem? 我该如何解决这个问题?

Define a .policy file that grants the required permissions, and name it in a java.security.policy argument. 定义一个授予所需权限的.policy文件,并在java.security.policy参数中命名它。

Or get rid of the security manager. 或摆脱安全经理。 It's only required if you are using the RMI codebase feature. 仅在使用RMI代码库功能时才需要。

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

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