title: AccessController usage
body: <p>I am trying understand the basics of java security and AccessController.doPrivileged() usage
  I started with a sample program</p>
  
  <pre><code>import java.security.AccessController;
  import java.security.PrivilegedAction;
  public class AccessSystemProperty {
     public static void main(String[] args) {
       System.out.println(System.getSecurityManager());
         AccessController.doPrivileged(
          new PrivilegedAction&lt;Boolean&gt;(){
             public Boolean run(){
                 System.out.println(System.getProperty("java.home"));
                 return Boolean.TRUE;
             }
          }
         );
     }
  }
  </code></pre>
  
  <p>if I try to run above code using default security manage I am getting AccessControlException
  My stacktrace is </p>
  
  <pre><code>C:\&gt;java -Djava.security.manager AccessSystemProperty
  java.lang.SecurityManager@923e30
  Exception in thread "main" java.security.AccessControlException: access denied (
  java.util.PropertyPermission java.home read)
          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.checkPropertyAccess(Unknown Source)
          at java.lang.System.getProperty(Unknown Source)
          at AccessSystemProperty$1.run(AccessSystemProperty.java:9)
          at AccessSystemProperty$1.run(AccessSystemProperty.java:8)
          at java.security.AccessController.doPrivileged(Native Method)
          at AccessSystemProperty.main(AccessSystemProperty.java:6)
  </code></pre>
  
  <p>Kindly help me to get a clear picture of</p>
  
  <p>1) When we need to use AccessController.doPrivileged()? (if SecurityManager is present we use AccessController.doPrivileged - why this is failing in above example)</p>
  
  <p>2) What is the real advantage we are getting by using AccessController and PrivilegedAction?</p>
  
  <p>3) Do we need custom policy file for above example to work?</p>
  
  <p>Thanks,</p>
  
  <p>Paul</p>