简体   繁体   English

Java RMI客户端服务器java.security.AccessControlException:访问被拒绝(“ java.util.PropertyPermission”“ java.security.policy”“ write”)

[英]Java RMI Client Server java.security.AccessControlException: access denied (“java.util.PropertyPermission” “java.security.policy” “write”)

I am working on making a simple RMI server in java. 我正在用Java创建一个简单的RMI服务器。 I want to be over a network so i cant use local host for the IP address. 我想通过网络,所以我不能使用本地主机作为IP地址。 I have a lot of code written but I keep getting an error message that reads: 我写了很多代码,但我不断收到一条错误消息,内容为:

  java.security.AccessControlException: access denied("java.util.PropertyPermission" "java.security.policy" "write")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.System.setProperty(Unknown Source)
at test_Client.TestClient.main(TestClient.java:31)

I have done a lot of looking and cant seem to find out what is wrong with my code.my server starts up fine and is running on my assigned ip and port number. 我已经做了很多事情,似乎无法找出我的代码出了什么问题。我的服务器启动正常,并在分配的IP和端口号上运行。 If someone could help me find out why I am getting this error that would be great. 如果有人可以帮助我找出为什么我会收到此错误,那将是很好的。 Thanks. 谢谢。 Here is the sample code for my client 这是我的客户的示例代码

package test_Client;
//this is the client, it has it's own package 

import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;
//import all needed rmi files


import test_Interface.Constant;
import test_Interface.testRMIInterface;
//import my constant file so port number can be found.
//import my test interface from my example interface project, example server testing

public class TestClient {
//start my class


    public static void main(String[] args) throws RemoteException, NotBoundException{
        //throws exceptions so everything is not in try catch blocks...

         if (System.getSecurityManager() == null) {
                System.setSecurityManager(new SecurityManager());
            }



         System.setProperty("java.security.policy", "C:/Users/Robert/workspace/ExampleClient");



         Registry registryClient = LocateRegistry.getRegistry(Constant.SERVER_IP, Constant.PORT_NUM);
        //make my registry client and use port number from constants in example interface
        //get the registry on the servers ip address with the port. 

         testRMIInterface remote =  (testRMIInterface) registryClient.lookup(Constant.RMI_ID);
        //using testInterface interface under my example interface
       //look up the RMI ID and link it to the object created above 




         //this is the one method i have on the server.

         String sendThis = "";
         System.out.println("Please enter a word");
         Scanner keyboard = new Scanner(System.in);
         sendThis = keyboard.next();
         System.out.println(remote.returnTest(sendThis));
        //simple call to the server method returnTest 
        //takes in a string. and returns a different one 
    }
}

You need to set the policy property before installing the SecurityManager. 安装SecurityManager. 之前,您需要设置策略属性SecurityManager.

Otherwise the SecurityManager loads a default policy which doesn't grant you the permission to change the policy. 否则, SecurityManager会加载默认策略,该默认策略不会授予您更改策略的权限。

暂无
暂无

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

相关问题 线程“main”中的异常java.security.AccessControlException:访问被拒绝(java.util.PropertyPermission * read,write) - Exception in thread “main” java.security.AccessControlException: access denied (java.util.PropertyPermission * read,write) java.security.AccessControlException:访问被拒绝(“ java.util.PropertyPermission”“ java.net.useSystemProxies”“写入”) - java.security.AccessControlException: access denied (“java.util.PropertyPermission” “java.net.useSystemProxies” “write”) java.security.AccessControlException:访问被拒绝(“ java.util.PropertyPermission”“ jna.boot.library.path”“ read”) - java.security.AccessControlException: access denied (“java.util.PropertyPermission” “jna.boot.library.path” “read”) rmi java.security.policy访问被拒绝 - rmi java.security.policy access denied Win7 64位jre7和jdk1.7.0_25中的导入按钮错误java.security.accesscontrolexception访问被拒绝(java.util.propertypermission user.dir读取) - Import Button Error java.security.accesscontrolexception access denied (java.util.propertypermission user.dir read) in Win7 64bit jre7 & jdk1.7.0_25 java.security.AccessControlException:Java RMI电话目录中的访问被拒绝 - java.security.AccessControlException: access denied in Java RMI Telephone Directory Java RMI java.security.AccessControlException:访问被拒绝 - Java RMI java.security.AccessControlException: access denied rmi java.security.AccessControlException - rmi java.security.AccessControlException 错误:java.security.AccessControlException:访问被拒绝 - Error: java.security.AccessControlException: Access denied java.security.AccessControlException:访问被拒绝的异常 - java.security.AccessControlException: access denied Exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM