[英]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.