Results 1 to 4 of 4
  1. #1
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default See the Policy File Effects (Applications)

    I'm having trouble with approach 1 in See the Policy File Effects (The Java™ Tutorials > Security Features in Java SE > Quick Tour of Controlling Applications)

    My policy file contains the following:
    Java Code:
    /* AUTOMATICALLY GENERATED ON Sat Jun 05 14:40:34 CDT 2010*/
    /* DO NOT EDIT */
    
    grant codeBase "http://java.sun.com/docs/books/tutorial/security/tour1/examples/" {
      permission java.io.FilePermission "writetest", "write";
    };
    
    grant codeBase "file:/C:/Test/" {
      permission java.util.PropertyPermission "user.home", "read";
      permission java.util.PropertyPermission "java.home", "read";
    };
    I did use the policytool to create my policy file. Here is what my policy file looks in policytool:


    When I type (while the cmd's current directory is C:\Test):
    Java Code:
    java -Djava.security.manager -Djava.security.policy=mypolicy GetProps
    I get this:


    GetProps is in C:\Test:


    This is GetProps.java:
    Java Code:
    class GetProps {
    
        public static void main(String[] args) {
    
            /* Test reading properties w & w/out security manager */
            
            String s;
    
            try {
    
                System.out.println("About to get os.name property value");
    
                s = System.getProperty("os.name", "not specified");
                System.out.println("  The name of your operating system is: " + s);
    
                System.out.println("About to get java.version property value");
    
                s = System.getProperty("java.version", "not specified");
                System.out.println("  The version of the JVM you are running is: " + s);
    
                System.out.println("About to get user.home property value");
    
                s = System.getProperty("user.home", "not specified");
                System.out.println("  Your user home directory is: " + s);
    
                System.out.println("About to get java.home property value");
    
                s = System.getProperty("java.home", "not specified");
                System.out.println("  Your JRE installation directory is: " + s);
    
    
            } catch (Exception e) {
                System.err.println("Caught exception " + e.toString());
            }
    
        }
    
    }
    As you can see, I'm still getting the exception when I shouldn't be. What's wrong? Thanks in advance.

    Best Regards,

    Aziz
    Last edited by Lil_Aziz1; 06-06-2010 at 12:33 AM.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    To see if you can grant permissions with your policy file, remove the codebase for the second entry. That check if the JVM was using your policy file. Then its a question of finding the correct format for the codebase. Another test is to add a - or a * after the last / in the codebase.

    I just ran the same tests a last week.

    @REM with manager but without .policy to allow
    java -Djava.security.manager GetProps
    MORE
    @REM with manager but with .policy to allow
    java -Djava.security.manager -Djava.security.policy=mypolicy1.policy GetProps
    MORE
    mypolicy1.policy:
    /* AUTOMATICALLY GENERATED ON Mon May 17 14:11:12 CDT 2010*/
    /* DO NOT EDIT */

    grant codeBase "File:/E:/Testing/Security/" {
    permission java.util.PropertyPermission "user.home", "read";
    permission java.util.PropertyPermission "java.home", "read";
    };
    Last edited by Norm; 06-06-2010 at 03:27 AM. Reason: Show code used

  3. #3
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    So I should remove
    Java Code:
    grant codeBase "file:/C:/Test/" {
      permission java.util.PropertyPermission "user.home", "read";
      permission java.util.PropertyPermission "java.home", "read";
    };
    from the policy file? If so, I did and I still get the same error.

    Or do you want me to remove
    Java Code:
      permission java.util.PropertyPermission "java.home", "read";
    If so, I did this also and I am still getting the same error. :(
    Last edited by Lil_Aziz1; 06-06-2010 at 05:13 AM.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  4. #4
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Uninstalled the JDK and then reinstalled it and it worked! :) Baller
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

Similar Threads

  1. Java RMI .policy file
    By krati in forum Networking
    Replies: 9
    Last Post: 04-24-2014, 05:04 PM
  2. Replies: 3
    Last Post: 01-29-2010, 06:53 AM
  3. Replies: 1
    Last Post: 10-16-2008, 09:56 PM
  4. Djava.security.policy=applet.policy
    By willemjav in forum Java Applets
    Replies: 1
    Last Post: 03-09-2008, 01:57 AM
  5. Djava.security.policy=applet.policy
    By willemjav in forum NetBeans
    Replies: 0
    Last Post: 03-09-2008, 01:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •