Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in thread "main" java.security.AccessControlException: access denied (java.util.PropertyPermission * read,write)

Tags:

java

exception

I am trying to run a desktop application which is developed in java rmi. While I am trying to execute this application in eclipse, I am getting following error. 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();
    }
like image 217
bhuvanpavan Avatar asked Jun 11 '12 10:06

bhuvanpavan


2 Answers

  1. Right click on application in eclipse and click on run configurations.
  2. Add virtual machine arguments as -Djava.security.policy =java.policy.applet.
  3. Create a file, name it as 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.

like image 115
bhuvanpavan Avatar answered Nov 09 '22 12:11

bhuvanpavan


You have installed a SecurityManager and you haven't given yourself enough permissions in your .policy file to execute your code. 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.

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. Otherwise you should consider deleting it.

Also you must store the result of createRegistry somewhere where it won't be garbage-collected, e.g. in a static variable. And once you've done that, the getRegistry() call is redundant.

like image 42
user207421 Avatar answered Nov 09 '22 14:11

user207421