jdk/src/jdk.security.auth/share/classes/com/sun/security/auth/PolicyFile.java
changeset 30044 bab15bbe2ca3
parent 25859 3317bb8137f4
child 34894 3248b89d1921
equal deleted inserted replaced
30043:b0dd05ec3db1 30044:bab15bbe2ca3
    29 import java.security.PermissionCollection;
    29 import java.security.PermissionCollection;
    30 import javax.security.auth.Subject;
    30 import javax.security.auth.Subject;
    31 
    31 
    32 /**
    32 /**
    33  * This class represents a default implementation for
    33  * This class represents a default implementation for
    34  * <code>javax.security.auth.Policy</code>.
    34  * {@code javax.security.auth.Policy}.
    35  *
    35  *
    36  * <p> This object stores the policy for entire Java runtime,
    36  * <p> This object stores the policy for entire Java runtime,
    37  * and is the amalgamation of multiple static policy
    37  * and is the amalgamation of multiple static policy
    38  * configurations that resides in files.
    38  * configurations that resides in files.
    39  * The algorithm for locating the policy file(s) and reading their
    39  * The algorithm for locating the policy file(s) and reading their
    40  * information into this <code>Policy</code> object is:
    40  * information into this {@code Policy} object is:
    41  *
    41  *
    42  * <ol>
    42  * <ol>
    43  * <li>
    43  * <li>
    44  *   Loop through the security properties,
    44  *   Loop through the security properties,
    45  *   <i>auth.policy.url.1</i>, <i>auth.policy.url.2</i>, ...,
    45  *   <i>auth.policy.url.1</i>, <i>auth.policy.url.2</i>, ...,
    46  *   <i>auth.policy.url.X</i>".
    46  *   <i>auth.policy.url.X</i>".
    47  *   Each property value specifies a <code>URL</code> pointing to a
    47  *   Each property value specifies a {@code URL} pointing to a
    48  *   policy file to be loaded.  Read in and load each policy.
    48  *   policy file to be loaded.  Read in and load each policy.
    49  *
    49  *
    50  * <li>
    50  * <li>
    51  *   The <code>java.lang.System</code> property <i>java.security.auth.policy</i>
    51  *   The {@code java.lang.System} property <i>java.security.auth.policy</i>
    52  *   may also be set to a <code>URL</code> pointing to another policy file
    52  *   may also be set to a {@code URL} pointing to another policy file
    53  *   (which is the case when a user uses the -D switch at runtime).
    53  *   (which is the case when a user uses the -D switch at runtime).
    54  *   If this property is defined, and its use is allowed by the
    54  *   If this property is defined, and its use is allowed by the
    55  *   security property file (the Security property,
    55  *   security property file (the Security property,
    56  *   <i>policy.allowSystemProperty</i> is set to <i>true</i>),
    56  *   <i>policy.allowSystemProperty</i> is set to <i>true</i>),
    57  *   also load that policy.
    57  *   also load that policy.
    81  *
    81  *
    82  * All non-bold items above must appear as is (although case
    82  * All non-bold items above must appear as is (although case
    83  * doesn't matter and some are optional, as noted below).
    83  * doesn't matter and some are optional, as noted below).
    84  * Italicized items represent variable values.
    84  * Italicized items represent variable values.
    85  *
    85  *
    86  * <p> A grant entry must begin with the word <code>grant</code>.
    86  * <p> A grant entry must begin with the word {@code grant}.
    87  * The <code>signedBy</code> and <code>codeBase</code>
    87  * The {@code signedBy} and {@code codeBase}
    88  * name/value pairs are optional.
    88  * name/value pairs are optional.
    89  * If they are not present, then any signer (including unsigned code)
    89  * If they are not present, then any signer (including unsigned code)
    90  * will match, and any codeBase will match.  Note that the
    90  * will match, and any codeBase will match.  Note that the
    91  * <code>principal</code> name/value pair is not optional.
    91  * {@code principal} name/value pair is not optional.
    92  * This <code>Policy</code> implementation only permits
    92  * This {@code Policy} implementation only permits
    93  * Principal-based grant entries.  Note that the <i>principalClass</i>
    93  * Principal-based grant entries.  Note that the <i>principalClass</i>
    94  * may be set to the wildcard value, *, which allows it to match
    94  * may be set to the wildcard value, *, which allows it to match
    95  * any <code>Principal</code> class.  In addition, the <i>principalName</i>
    95  * any {@code Principal} class.  In addition, the <i>principalName</i>
    96  * may also be set to the wildcard value, *, allowing it to match
    96  * may also be set to the wildcard value, *, allowing it to match
    97  * any <code>Principal</code> name.  When setting the <i>principalName</i>
    97  * any {@code Principal} name.  When setting the <i>principalName</i>
    98  * to the *, do not surround the * with quotes.
    98  * to the *, do not surround the * with quotes.
    99  *
    99  *
   100  * <p> A permission entry must begin with the word <code>permission</code>.
   100  * <p> A permission entry must begin with the word {@code permission}.
   101  * The word <code><i>Type</i></code> in the template above is
   101  * The word <i>{@code Type}</i> in the template above is
   102  * a specific permission type, such as <code>java.io.FilePermission</code>
   102  * a specific permission type, such as {@code java.io.FilePermission}
   103  * or <code>java.lang.RuntimePermission</code>.
   103  * or {@code java.lang.RuntimePermission}.
   104  *
   104  *
   105  * <p> The "<i>action</i>" is required for
   105  * <p> The "<i>action</i>" is required for
   106  * many permission types, such as <code>java.io.FilePermission</code>
   106  * many permission types, such as {@code java.io.FilePermission}
   107  * (where it specifies what type of file access that is permitted).
   107  * (where it specifies what type of file access that is permitted).
   108  * It is not required for categories such as
   108  * It is not required for categories such as
   109  * <code>java.lang.RuntimePermission</code>
   109  * {@code java.lang.RuntimePermission}
   110  * where it is not necessary - you either have the
   110  * where it is not necessary - you either have the
   111  * permission specified by the <code>"<i>name</i>"</code>
   111  * permission specified by the "<i>{@code name}</i>"
   112  * value following the type name or you don't.
   112  * value following the type name or you don't.
   113  *
   113  *
   114  * <p> The <code>signedBy</code> name/value pair for a permission entry
   114  * <p> The {@code signedBy} name/value pair for a permission entry
   115  * is optional. If present, it indicates a signed permission. That is,
   115  * is optional. If present, it indicates a signed permission. That is,
   116  * the permission class itself must be signed by the given alias in
   116  * the permission class itself must be signed by the given alias in
   117  * order for it to be granted. For example,
   117  * order for it to be granted. For example,
   118  * suppose you have the following grant entry:
   118  * suppose you have the following grant entry:
   119  *
   119  *
   122  *     permission Foo "foobar", signedBy "FooSoft";
   122  *     permission Foo "foobar", signedBy "FooSoft";
   123  *   }
   123  *   }
   124  * </pre>
   124  * </pre>
   125  *
   125  *
   126  * <p> Then this permission of type <i>Foo</i> is granted if the
   126  * <p> Then this permission of type <i>Foo</i> is granted if the
   127  * <code>Foo.class</code> permission has been signed by the
   127  * {@code Foo.class} permission has been signed by the
   128  * "FooSoft" alias, or if <code>Foo.class</code> is a
   128  * "FooSoft" alias, or if {@code Foo.class} is a
   129  * system class (i.e., is found on the CLASSPATH).
   129  * system class (i.e., is found on the CLASSPATH).
   130  *
   130  *
   131  * <p> Items that appear in an entry must appear in the specified order
   131  * <p> Items that appear in an entry must appear in the specified order
   132  * (<code>permission</code>, <i>Type</i>, "<i>name</i>", and
   132  * ({@code permission}, <i>Type</i>, "<i>name</i>", and
   133  * "<i>action</i>"). An entry is terminated with a semicolon.
   133  * "<i>action</i>"). An entry is terminated with a semicolon.
   134  *
   134  *
   135  * <p> Case is unimportant for the identifiers (<code>permission</code>,
   135  * <p> Case is unimportant for the identifiers ({@code permission},
   136  * <code>signedBy</code>, <code>codeBase</code>, etc.) but is
   136  * {@code signedBy}, {@code codeBase}, etc.) but is
   137  * significant for the <i>Type</i>
   137  * significant for the <i>Type</i>
   138  * or for any string that is passed in as a value. <p>
   138  * or for any string that is passed in as a value.
   139  *
   139  *
   140  * <p> An example of two entries in a policy configuration file is
   140  * <p> An example of two entries in a policy configuration file is
   141  * <pre>
   141  * <pre>
   142  *   // if the code is comes from "foo.com" and is running as "Duke",
   142  *   // if the code is comes from "foo.com" and is running as "Duke",
   143  *   // grant it read/write to all files in /tmp.
   143  *   // grant it read/write to all files in /tmp.
   151  *
   151  *
   152  *   grant principal foo.com.Principal "Duke" {
   152  *   grant principal foo.com.Principal "Duke" {
   153  *         permission java.util.PropertyPermission "java.vendor";
   153  *         permission java.util.PropertyPermission "java.vendor";
   154  * </pre>
   154  * </pre>
   155  *
   155  *
   156  * <p> This <code>Policy</code> implementation supports
   156  * <p> This {@code Policy} implementation supports
   157  * special handling for PrivateCredentialPermissions.
   157  * special handling for PrivateCredentialPermissions.
   158  * If a grant entry is configured with a
   158  * If a grant entry is configured with a
   159  * <code>PrivateCredentialPermission</code>,
   159  * {@code PrivateCredentialPermission},
   160  * and the "Principal Class/Principal Name" for that
   160  * and the "Principal Class/Principal Name" for that
   161  * <code>PrivateCredentialPermission</code> is "self",
   161  * {@code PrivateCredentialPermission} is "self",
   162  * then the entry grants the specified <code>Subject</code> permission to
   162  * then the entry grants the specified {@code Subject} permission to
   163  * access its own private Credential.  For example,
   163  * access its own private Credential.  For example,
   164  * the following grants the <code>Subject</code> "Duke"
   164  * the following grants the {@code Subject} "Duke"
   165  * access to its own a.b.Credential.
   165  * access to its own a.b.Credential.
   166  *
   166  *
   167  * <pre>
   167  * <pre>
   168  *   grant principal foo.com.Principal "Duke" {
   168  *   grant principal foo.com.Principal "Duke" {
   169  *      permission javax.security.auth.PrivateCredentialPermission
   169  *      permission javax.security.auth.PrivateCredentialPermission
   170  *              "a.b.Credential self",
   170  *              "a.b.Credential self",
   171  *              "read";
   171  *              "read";
   172  *    };
   172  *    };
   173  * </pre>
   173  * </pre>
   174  *
   174  *
   175  * The following grants the <code>Subject</code> "Duke"
   175  * The following grants the {@code Subject} "Duke"
   176  * access to all of its own private Credentials:
   176  * access to all of its own private Credentials:
   177  *
   177  *
   178  * <pre>
   178  * <pre>
   179  *   grant principal foo.com.Principal "Duke" {
   179  *   grant principal foo.com.Principal "Duke" {
   180  *      permission javax.security.auth.PrivateCredentialPermission
   180  *      permission javax.security.auth.PrivateCredentialPermission
   182  *              "read";
   182  *              "read";
   183  *    };
   183  *    };
   184  * </pre>
   184  * </pre>
   185  *
   185  *
   186  * The following grants all Subjects authenticated as a
   186  * The following grants all Subjects authenticated as a
   187  * <code>SolarisPrincipal</code> (regardless of their respective names)
   187  * {@code SolarisPrincipal} (regardless of their respective names)
   188  * permission to access their own private Credentials:
   188  * permission to access their own private Credentials:
   189  *
   189  *
   190  * <pre>
   190  * <pre>
   191  *   grant principal com.sun.security.auth.SolarisPrincipal * {
   191  *   grant principal com.sun.security.auth.SolarisPrincipal * {
   192  *      permission javax.security.auth.PrivateCredentialPermission
   192  *      permission javax.security.auth.PrivateCredentialPermission
   205  *              "read";
   205  *              "read";
   206  *    };
   206  *    };
   207  * </pre>
   207  * </pre>
   208 
   208 
   209  * @deprecated As of JDK&nbsp;1.4, replaced by
   209  * @deprecated As of JDK&nbsp;1.4, replaced by
   210  *             <code>sun.security.provider.PolicyFile</code>.
   210  *             {@code sun.security.provider.PolicyFile}.
   211  *             This class is entirely deprecated.
   211  *             This class is entirely deprecated.
   212  *
   212  *
   213  * @see java.security.CodeSource
   213  * @see java.security.CodeSource
   214  * @see java.security.Permissions
   214  * @see java.security.Permissions
   215  * @see java.security.ProtectionDomain
   215  * @see java.security.ProtectionDomain
   230     }
   230     }
   231 
   231 
   232     /**
   232     /**
   233      * Refreshes the policy object by re-reading all the policy files.
   233      * Refreshes the policy object by re-reading all the policy files.
   234      *
   234      *
   235      * <p>
       
   236      *
       
   237      * @exception SecurityException if the caller doesn't have permission
   235      * @exception SecurityException if the caller doesn't have permission
   238      *          to refresh the <code>Policy</code>.
   236      *          to refresh the {@code Policy}.
   239      */
   237      */
   240     @Override
   238     @Override
   241     public void refresh() {
   239     public void refresh() {
   242         apf.refresh();
   240         apf.refresh();
   243     }
   241     }
   244 
   242 
   245     /**
   243     /**
   246      * Examines this <code>Policy</code> and returns the Permissions granted
   244      * Examines this {@code Policy} and returns the Permissions granted
   247      * to the specified <code>Subject</code> and <code>CodeSource</code>.
   245      * to the specified {@code Subject} and {@code CodeSource}.
   248      *
   246      *
   249      * <p> Permissions for a particular <i>grant</i> entry are returned
   247      * <p> Permissions for a particular <i>grant</i> entry are returned
   250      * if the <code>CodeSource</code> constructed using the codebase and
   248      * if the {@code CodeSource} constructed using the codebase and
   251      * signedby values specified in the entry <code>implies</code>
   249      * signedby values specified in the entry {@code implies}
   252      * the <code>CodeSource</code> provided to this method, and if the
   250      * the {@code CodeSource} provided to this method, and if the
   253      * <code>Subject</code> provided to this method contains all of the
   251      * {@code Subject} provided to this method contains all of the
   254      * Principals specified in the entry.
   252      * Principals specified in the entry.
   255      *
   253      *
   256      * <p> The <code>Subject</code> provided to this method contains all
   254      * <p> The {@code Subject} provided to this method contains all
   257      * of the Principals specified in the entry if, for each
   255      * of the Principals specified in the entry if, for each
   258      * <code>Principal</code>, "P1", specified in the <i>grant</i> entry
   256      * {@code Principal}, "P1", specified in the <i>grant</i> entry
   259      * one of the following two conditions is met:
   257      * one of the following two conditions is met:
   260      *
   258      *
   261      * <p>
       
   262      * <ol>
   259      * <ol>
   263      * <li> the <code>Subject</code> has a
   260      * <li> the {@code Subject} has a
   264      *      <code>Principal</code>, "P2", where
   261      *      {@code Principal}, "P2", where
   265      *      <code>P2.getClass().getName()</code> equals the
   262      *      {@code P2.getClass().getName()} equals the
   266      *      P1's class name, and where
   263      *      P1's class name, and where
   267      *      <code>P2.getName()</code> equals the P1's name.
   264      *      {@code P2.getName()} equals the P1's name.
   268      *
   265      *
   269      * <li> P1 implements
   266      * <li> P1 implements
   270      *      <code>com.sun.security.auth.PrincipalComparator</code>,
   267      *      {@code com.sun.security.auth.PrincipalComparator},
   271      *      and <code>P1.implies</code> the provided <code>Subject</code>.
   268      *      and {@code P1.implies} the provided {@code Subject}.
   272      * </ol>
   269      * </ol>
   273      *
   270      *
   274      * <p> Note that this <code>Policy</code> implementation has
   271      * <p> Note that this {@code Policy} implementation has
   275      * special handling for PrivateCredentialPermissions.
   272      * special handling for PrivateCredentialPermissions.
   276      * When this method encounters a <code>PrivateCredentialPermission</code>
   273      * When this method encounters a {@code PrivateCredentialPermission}
   277      * which specifies "self" as the <code>Principal</code> class and name,
   274      * which specifies "self" as the {@code Principal} class and name,
   278      * it does not add that <code>Permission</code> to the returned
   275      * it does not add that {@code Permission} to the returned
   279      * <code>PermissionCollection</code>.  Instead, it builds
   276      * {@code PermissionCollection}.  Instead, it builds
   280      * a new <code>PrivateCredentialPermission</code>
   277      * a new {@code PrivateCredentialPermission}
   281      * for each <code>Principal</code> associated with the provided
   278      * for each {@code Principal} associated with the provided
   282      * <code>Subject</code>.  Each new <code>PrivateCredentialPermission</code>
   279      * {@code Subject}.  Each new {@code PrivateCredentialPermission}
   283      * contains the same Credential class as specified in the
   280      * contains the same Credential class as specified in the
   284      * originally granted permission, as well as the Class and name
   281      * originally granted permission, as well as the Class and name
   285      * for the respective <code>Principal</code>.
   282      * for the respective {@code Principal}.
   286      *
   283      *
   287      * <p>
   284      * @param subject the Permissions granted to this {@code Subject}
   288      *
   285      *          and the additionally provided {@code CodeSource}
   289      * @param subject the Permissions granted to this <code>Subject</code>
       
   290      *          and the additionally provided <code>CodeSource</code>
       
   291      *          are returned. <p>
       
   292      *
       
   293      * @param codesource the Permissions granted to this <code>CodeSource</code>
       
   294      *          and the additionally provided <code>Subject</code>
       
   295      *          are returned.
   286      *          are returned.
   296      *
   287      *
   297      * @return the Permissions granted to the provided <code>Subject</code>
   288      * @param codesource the Permissions granted to this {@code CodeSource}
   298      *          <code>CodeSource</code>.
   289      *          and the additionally provided {@code Subject}
       
   290      *          are returned.
       
   291      *
       
   292      * @return the Permissions granted to the provided {@code Subject}
       
   293      *          {@code CodeSource}.
   299      */
   294      */
   300     @Override
   295     @Override
   301     public PermissionCollection getPermissions(final Subject subject,
   296     public PermissionCollection getPermissions(final Subject subject,
   302                                                final CodeSource codesource) {
   297                                                final CodeSource codesource) {
   303         return apf.getPermissions(subject, codesource);
   298         return apf.getPermissions(subject, codesource);