简体   繁体   English

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

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

I am trying to run a desktop application which is developed in java rmi. 我正在尝试运行一个用java rmi开发的桌面应用程序。 While I am trying to execute this application in eclipse, I am getting following error. 当我试图在eclipse中执行此应用程序时,我收到以下错误。 Please any one help me thanks in advance. 请任何人提前帮助我。

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)

Here is the code. 这是代码。

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. Right click on application in eclipse and click on run configurations. 右键单击eclipse中的应用程序,然后单击运行配置。
  2. Add virtual machine arguments as -Djava.security.policy =java.policy.applet . 将虚拟机参数添加为-Djava.security.policy =java.policy.applet
  3. Create a file, name it as java.policy.applet . 创建一个文件,将其命名为java.policy.applet
  4. Add below lines in that file. 在该文件中添加以下行。

     grant { permission java.security.AllPermission; }; 
  5. Save it and run the application. 保存并运行应用程序。

This will give all security permissions to your Java application. 这将为您的Java应用程序提供所有安全权限。

You have installed a SecurityManager and you haven't given yourself enough permissions in your .policy file to execute your code. 您已经安装了SecurityManager,并且在.policy文件中没有给自己足够的权限来执行您的代码。 The exception tells you what permission is missing, but there are probably more. 该异常会告诉您缺少哪些权限,但可能还有更多权限。 Run your application with -Djava.security.debug=access,failure to see what other security problems there are. 使用-Djava.security.debug = access运行您的应用程序,无法查看其他安全问题。

But the real question here is why the security manager? 但真正的问题是为什么安全经理? You only need it in an RMI server, from the RMI point of view, if you are using the RMI codebase feature. 如果您使用RMI代码库功能,从RMI的角度来看,您只需要在RMI服务器中使用它。 Otherwise you should consider deleting it. 否则你应该考虑删除它。

Also you must store the result of createRegistry somewhere where it won't be garbage-collected, eg in a static variable. 此外,您必须将createRegistry的结果存储在不会被垃圾收集的地方,例如静态变量。 And once you've done that, the getRegistry() call is redundant. 一旦你完成了这个, getRegistry()调用是多余的。

暂无
暂无

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

相关问题 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”) 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”) 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.util.PropertyPermission user.home(拒绝访问) - java.util.PropertyPermission user.home read (Access Denied) java.security.AccessControlException:访问被拒绝的异常 - java.security.AccessControlException: access denied Exception 如何解决 Exception::java.security.AccessControlException: access denied in HttpServlet - How to resolve Exception::java.security.AccessControlException: access denied in HttpServlet JSP-java.security.AccessControlException:拒绝访问 - JSP - java.security.AccessControlException: access denied 错误:java.security.AccessControlException:访问被拒绝 - Error: java.security.AccessControlException: Access denied Java.util.PropertyPermission失败 - Java.util.PropertyPermission Failure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM