简体   繁体   English

如何解决java.security.AccessControlException

[英]how resolve java.security.AccessControlException

I'm trying to create an rmi application : the client transfer file to the serve. 我正在尝试创建一个rmi应用程序:客户端将文件传输到服务器。 But , when running the code i get security manager exception. 但是,运行代码时,我得到了安全管理器异常。 Here is the client side : 这是客户端:

  import java.rmi.Naming;
  import java.rmi.RMISecurityManager;
  import java.util.Scanner;
  public class StartFileClient {
  public static void main(String[] args) {
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());
    try{
        FileClient c=new FileClient("imed");            
        FileServerInt server=(FileServerInt)Naming.lookup("rmi://localhost/abc");
        server.login(c);
        System.out.println("Listening.....");           
        Scanner s=new Scanner(System.in);           
        while(true){
            String line=s.nextLine();
        }
    }catch(Exception e){
        e.printStackTrace();
    }
}   

} }

Here is the server side : 这是服务器端:

 import java.rmi.Naming;
public class StartFileServer {
public static void main(String[] args) {
    // TODO Auto-generated method stub
    try{

        java.rmi.registry.LocateRegistry.createRegistry(1099);

        FileServer fs=new FileServer();
        fs.setFile("itcrowd.avi");          
        Naming.rebind("rmi://localhost/abc", fs);
        System.out.println("File Server is Ready");

    }catch(Exception e){
        e.printStackTrace();
    }
}   

} }

Also, i create a file security.policy 另外,我创建一个文件security.policy

  grant {
        permission java.security.AllPermission;

}; };

Thanks for helping. 感谢您的帮助。

Clearly your policy file isn't being found. 显然,找不到您的策略文件。 You need to specify its location via the java.security.policy system property. 您需要通过java.security.policy系统属性指定其位置。

BUT Unless you're using the codebase feature, remove the security manager. 但是,除非您使用代码库功能,否则请删除安全管理器。

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

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