RMI连接被拒绝 [英] RMI connection refused

查看:409
本文介绍了RMI连接被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图获得rmi连接。我遇到了很多安全问题,但一直无法找到解决这一问题的方法。我执行我的jar文件:

I am trying to get a rmi connection going. I have ran into many security issues but have been unable to find a way past all this. I execute my jar file with:

java -Djava.security.policy=java.security.AllPermission -jar "myjarfile"

我用来创建它的代码是:

The code I have been using to create this is:

public class server
{
    public static void main(String args[])throws Exception
    {
    if (System.getSecurityManager() == null)
        System.setSecurityManager ( new RMISecurityManager() {
        public void checkConnect (String host, int port) {}
        public void checkConnect (String host, int port, Object context) {}
        });

    try
    {
        sampleserverimpl server = new sampleserverimpl();
        System.out.println("SERVER IS WAITING");
        LocateRegistry.createRegistry(2020);

        //Runtime.getRuntime().exec("rmiregistry 2020");
        Naming.rebind("//localhost:2020/SERVER", server);

    }
    catch(Exception e)
    {
        System.out.println(e);
    }
}
};

我收到的错误跟踪是:

Exception in thread "RMI TCP Connection(idle)" java.security.AccessControlExcept
ion: access denied (java.net.SocketPermission 127.0.0.1:31199 accept,resolve)jav
a.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:

    java.io.EOFException

我尝试过不同的解决这个问题的方法,有人能在这里看到问题吗?

I have tried different ways to get around this, can anyone see the issue here?

谢谢

推荐答案

-Djava.security.policy 接受指向策略文件的URL,该策略文件又包含权限。所以你应该: -Djava.security.policy = / some / path / my.policy 作为JVM参数,其中 my.policy 文件包含:

-Djava.security.policy accepts a URL which points to a policy file which in turn contains the permissions. So you should have: -Djava.security.policy=/some/path/my.policy as the JVM argument where the my.policy file contains:

grant {
  permission java.security.AllPermission;
};

此外,为了避免代码中存在NULL检查并手动创建 SecurityManager ,您可以通过传递JVM开关请求为您的应用程序自动安装SecurityManager: -Djava.security.manager

Also, in order to avoid the NULL check present in your code and the manual creation of a SecurityManager, you can request a SecurityManager be automatically installed for your application by passing the JVM switch: -Djava.security.manager.

您的最终JVM调用应如下所示:

Your final JVM invocation should look like:

java -Djava.security.manager -Djava.security.policy=/some/path/my.policy

这篇关于RMI连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆