繁体   English   中英

线程“main”中的异常java.security.AccessControlException:访问被拒绝(java.util.PropertyPermission * read,write)

[英]Exception in thread “main” java.security.AccessControlException: access denied (java.util.PropertyPermission * read,write)

我正在尝试运行一个用java rmi开发的桌面应用程序。 当我试图在eclipse中执行此应用程序时,我收到以下错误。 请任何人提前帮助我。

Exception in thread "main" java.security.AccessControlException: access denied (java.util.PropertyPermission * read,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.SecurityManager.checkPropertiesAccess(Unknown Source)
    at java.lang.System.getProperties(Unknown Source)
    at .HeadOfficeManager.Manager.main(Manager.java:103)

这是代码。

public static void main(String args[])
{
    Manager frame = new Manager();
    frame.setVisible(true);
    // frame.show(); old 1.4

    // Create and install a security manager
    if (System.getSecurityManager()== null)
    {
        System.setSecurityManager(new RMISecurityManager());
    }
    try
    {
        Properties prop = System.getProperties();
        String httpPath = prop.getProperty("HTTPPath");
        new ClassFileServer(80, httpPath);
    }
    catch (IOException e)
    {}

    try
    {
        java.rmi.registry.LocateRegistry.createRegistry(1099);
        System.out.println("RMI registry ready.");
    }
    catch (Exception e)
    {
        System.out.println("Exception starting RMI registry:");
        e.printStackTrace();
    }
    try
    {
        RMIHandler = new ManagerRMIHandler();

        // Bind the remote object's stub in the registry
        Registry registry = LocateRegistry.getRegistry();
        registry.rebind("HeadOfficeManager", RMIHandler);

        System.err.println("Server ready");
    }
    catch (Exception e)
    {
        System.err.println("Server exception: " + e.toString());
        e.printStackTrace();
    }
  1. 右键单击eclipse中的应用程序,然后单击运行配置。
  2. 将虚拟机参数添加为-Djava.security.policy =java.policy.applet
  3. 创建一个文件,将其命名为java.policy.applet
  4. 在该文件中添加以下行。

     grant { permission java.security.AllPermission; }; 
  5. 保存并运行应用程序。

这将为您的Java应用程序提供所有安全权限。

您已经安装了SecurityManager,并且在.policy文件中没有给自己足够的权限来执行您的代码。 该异常会告诉您缺少哪些权限,但可能还有更多权限。 使用-Djava.security.debug = access运行您的应用程序,无法查看其他安全问题。

但真正的问题是为什么安全经理? 如果您使用RMI代码库功能,从RMI的角度来看,您只需要在RMI服务器中使用它。 否则你应该考虑删除它。

此外,您必须将createRegistry的结果存储在不会被垃圾收集的地方,例如静态变量。 一旦你完成了这个, getRegistry()调用是多余的。

暂无
暂无

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

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