rmi java.security.policy访问被拒绝 [英] rmi java.security.policy access denied

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

问题描述

我是Java中RMI的新手,我想使用RMI创建客户端服务器应用程序,

I am new to RMI topic in java and i wana to create client server applicaiton using RMI,

我遵循了在此链接中找到的本教程:使用Eclipse的RMI教程

i followed this tutorial found in this link : RMI Tutorial using eclipse

但是我正在使用 netbeans ,这是服务器代码:

but i am using netbeans ,and here is server code:

import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.*;   

public class AdditionServer {
       public static void main (String[] argv) {
           try {
               if (System.getSecurityManager() == null)
                            {
                                System.setSecurityManager(new SecurityManager());
                            }   
                           String policy="file:/home/user/NetBeansProjects/RMIServerSide/security.policy";

                           System.setProperty("java.security.policy",policy);

               Addition Hello = new Addition();

                                    System.out.println("test\n");
                            Registry reg=LocateRegistry.createRegistry(1099);

               reg.rebind("rmi://localhost/ABC", Hello);

               System.out.println("Addition Server is ready.");
               }catch (Exception e) {
                   System.out.println("Addition Server failed: " + e);
                }
           }
}

,这里是security.policy:

and here security.policy :

grant codeBase "/home/user/NetBeansProjects/RMIServerSide/build/classes/" {
    permission java.security.AllPermission;
};

然后我运行rmiregistry&在终端. 然后我运行服务器,这里的输出是什么:

then i run the rmiregistry & in the terminal. then i run the server and here what is the output exactly :

Addition Server failed: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "java.security.policy" "write")

有没有我想念的东西,例如用于vm的配置或??? .....

Is there something i miss it, like a config for vm or something ???.....

推荐答案

我遇到了同样的问题.我已按照以下步骤对其进行了修复:

I had the same problem. I have fixed it following these steps:

  1. 我已经创建了一个策略文件,我将其命名为security.policy

具有以下内容

grant {
    // Allow everything for now
    permission java.security.AllPermission;
};

2-在将远程对象绑定到rmiregistry之前,添加以下代码行.

2- Add the following line of code just before binding the remote object to the rmiregistry.

System.setProperty("java.security.policy","file:./security.policy");

这篇关于rmi java.security.policy访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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