jdk/src/jdk.security.auth/share/classes/com/sun/security/auth/PolicyFile.java
author weijun
Fri, 17 Jun 2016 09:46:34 +0800
changeset 39047 cf08ea56b4de
parent 34894 3248b89d1921
permissions -rw-r--r--
8146619: Re-examine supportness of public classes in com.sun.security.auth.** Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19212
80526b520497 8022410: Fix Javac Warnings in com.sun.security.auth Package
dxu
parents: 14775
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4350
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4350
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4350
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4350
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4350
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.security.auth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.CodeSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.PermissionCollection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.security.auth.Subject;
19212
80526b520497 8022410: Fix Javac Warnings in com.sun.security.auth Package
dxu
parents: 14775
diff changeset
    31
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This class represents a default implementation for
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    34
 * {@code javax.security.auth.Policy}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p> This object stores the policy for entire Java runtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * and is the amalgamation of multiple static policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * configurations that resides in files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The algorithm for locating the policy file(s) and reading their
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    40
 * information into this {@code Policy} object is:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <li>
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 10336
diff changeset
    44
 *   Loop through the security properties,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   <i>auth.policy.url.1</i>, <i>auth.policy.url.2</i>, ...,
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 10336
diff changeset
    46
 *   <i>auth.policy.url.X</i>".
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    47
 *   Each property value specifies a {@code URL} pointing to a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *   policy file to be loaded.  Read in and load each policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <li>
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    51
 *   The {@code java.lang.System} property <i>java.security.auth.policy</i>
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    52
 *   may also be set to a {@code URL} pointing to another policy file
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   (which is the case when a user uses the -D switch at runtime).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   If this property is defined, and its use is allowed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   security property file (the Security property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *   <i>policy.allowSystemProperty</i> is set to <i>true</i>),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *   also load that policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *   If the <i>java.security.auth.policy</i> property is defined using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *   "==" (rather than "="), then ignore all other specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *   policies and only load this policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Each policy file consists of one or more grant entries, each of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * which consists of a number of permission entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *   grant signedBy "<b>alias</b>", codeBase "<b>URL</b>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *         principal <b>principalClass</b> "<b>principalName</b>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *         principal <b>principalClass</b> "<b>principalName</b>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *         ... {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *     permission <b>Type</b> "<b>name</b> "<b>action</b>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *         signedBy "<b>alias</b>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *     permission <b>Type</b> "<b>name</b> "<b>action</b>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *         signedBy "<b>alias</b>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *     ....
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *   };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * All non-bold items above must appear as is (although case
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * doesn't matter and some are optional, as noted below).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * Italicized items represent variable values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    86
 * <p> A grant entry must begin with the word {@code grant}.
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    87
 * The {@code signedBy} and {@code codeBase}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * name/value pairs are optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * If they are not present, then any signer (including unsigned code)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * will match, and any codeBase will match.  Note that the
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    91
 * {@code principal} name/value pair is not optional.
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    92
 * This {@code Policy} implementation only permits
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * Principal-based grant entries.  Note that the <i>principalClass</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * may be set to the wildcard value, *, which allows it to match
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    95
 * any {@code Principal} class.  In addition, the <i>principalName</i>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * may also be set to the wildcard value, *, allowing it to match
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    97
 * any {@code Principal} name.  When setting the <i>principalName</i>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * to the *, do not surround the * with quotes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   100
 * <p> A permission entry must begin with the word {@code permission}.
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   101
 * The word <i>{@code Type}</i> in the template above is
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   102
 * a specific permission type, such as {@code java.io.FilePermission}
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   103
 * or {@code java.lang.RuntimePermission}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * <p> The "<i>action</i>" is required for
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   106
 * many permission types, such as {@code java.io.FilePermission}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * (where it specifies what type of file access that is permitted).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * It is not required for categories such as
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   109
 * {@code java.lang.RuntimePermission}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * where it is not necessary - you either have the
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   111
 * permission specified by the "<i>{@code name}</i>"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * value following the type name or you don't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   114
 * <p> The {@code signedBy} name/value pair for a permission entry
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * is optional. If present, it indicates a signed permission. That is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * the permission class itself must be signed by the given alias in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * order for it to be granted. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * suppose you have the following grant entry:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *   grant principal foo.com.Principal "Duke" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *     permission Foo "foobar", signedBy "FooSoft";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * <p> Then this permission of type <i>Foo</i> is granted if the
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   127
 * {@code Foo.class} permission has been signed by the
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   128
 * "FooSoft" alias, or if {@code Foo.class} is a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * system class (i.e., is found on the CLASSPATH).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * <p> Items that appear in an entry must appear in the specified order
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   132
 * ({@code permission}, <i>Type</i>, "<i>name</i>", and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * "<i>action</i>"). An entry is terminated with a semicolon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   135
 * <p> Case is unimportant for the identifiers ({@code permission},
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   136
 * {@code signedBy}, {@code codeBase}, etc.) but is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * significant for the <i>Type</i>
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   138
 * or for any string that is passed in as a value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <p> An example of two entries in a policy configuration file is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 *   // if the code is comes from "foo.com" and is running as "Duke",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 *   // grant it read/write to all files in /tmp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *   grant codeBase "foo.com", principal foo.com.Principal "Duke" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 *              permission java.io.FilePermission "/tmp/*", "read,write";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *   };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *   // grant any code running as "Duke" permission to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *   // the "java.vendor" Property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *   grant principal foo.com.Principal "Duke" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *         permission java.util.PropertyPermission "java.vendor";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   156
 * <p> This {@code Policy} implementation supports
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * special handling for PrivateCredentialPermissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * If a grant entry is configured with a
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   159
 * {@code PrivateCredentialPermission},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * and the "Principal Class/Principal Name" for that
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   161
 * {@code PrivateCredentialPermission} is "self",
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   162
 * then the entry grants the specified {@code Subject} permission to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * access its own private Credential.  For example,
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   164
 * the following grants the {@code Subject} "Duke"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * access to its own a.b.Credential.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *   grant principal foo.com.Principal "Duke" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *      permission javax.security.auth.PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *              "a.b.Credential self",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 *              "read";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 *    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   175
 * The following grants the {@code Subject} "Duke"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * access to all of its own private Credentials:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *   grant principal foo.com.Principal "Duke" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 *      permission javax.security.auth.PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 *              "* self",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 *              "read";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 *    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * The following grants all Subjects authenticated as a
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   187
 * {@code SolarisPrincipal} (regardless of their respective names)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * permission to access their own private Credentials:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 *   grant principal com.sun.security.auth.SolarisPrincipal * {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 *      permission javax.security.auth.PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 *              "* self",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 *              "read";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * The following grants all Subjects permission to access their own
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * private Credentials:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 *   grant principal * * {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 *      permission javax.security.auth.PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 *              "* self",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 *              "read";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 *    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * @deprecated As of JDK&nbsp;1.4, replaced by
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   210
 *             {@code sun.security.provider.PolicyFile}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 *             This class is entirely deprecated.
39047
cf08ea56b4de 8146619: Re-examine supportness of public classes in com.sun.security.auth.**
weijun
parents: 34894
diff changeset
   212
 * This class is subject to removal in a future version of Java SE.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * @see java.security.CodeSource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * @see java.security.Permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * @see java.security.ProtectionDomain
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 10336
diff changeset
   217
 * @see java.security.Security security properties
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 */
39047
cf08ea56b4de 8146619: Re-examine supportness of public classes in com.sun.security.auth.**
weijun
parents: 34894
diff changeset
   219
@Deprecated(since="1.4", forRemoval=true)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
public class PolicyFile extends javax.security.auth.Policy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
19439
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents: 19212
diff changeset
   222
    private final sun.security.provider.AuthPolicyFile apf;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Initializes the Policy object and reads the default policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * configuration file(s) into the Policy object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public PolicyFile() {
19439
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents: 19212
diff changeset
   229
        apf = new sun.security.provider.AuthPolicyFile();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Refreshes the policy object by re-reading all the policy files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @exception SecurityException if the caller doesn't have permission
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   236
     *          to refresh the {@code Policy}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
19439
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents: 19212
diff changeset
   238
    @Override
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents: 19212
diff changeset
   239
    public void refresh() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents: 19212
diff changeset
   240
        apf.refresh();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   244
     * Examines this {@code Policy} and returns the Permissions granted
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   245
     * to the specified {@code Subject} and {@code CodeSource}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * <p> Permissions for a particular <i>grant</i> entry are returned
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   248
     * if the {@code CodeSource} constructed using the codebase and
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   249
     * signedby values specified in the entry {@code implies}
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   250
     * the {@code CodeSource} provided to this method, and if the
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   251
     * {@code Subject} provided to this method contains all of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Principals specified in the entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   254
     * <p> The {@code Subject} provided to this method contains all
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * of the Principals specified in the entry if, for each
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   256
     * {@code Principal}, "P1", specified in the <i>grant</i> entry
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * one of the following two conditions is met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * <ol>
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   260
     * <li> the {@code Subject} has a
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   261
     *      {@code Principal}, "P2", where
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   262
     *      {@code P2.getClass().getName()} equals the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *      P1's class name, and where
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   264
     *      {@code P2.getName()} equals the P1's name.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * <li> P1 implements
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   267
     *      {@code com.sun.security.auth.PrincipalComparator},
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   268
     *      and {@code P1.implies} the provided {@code Subject}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   271
     * <p> Note that this {@code Policy} implementation has
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * special handling for PrivateCredentialPermissions.
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   273
     * When this method encounters a {@code PrivateCredentialPermission}
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   274
     * which specifies "self" as the {@code Principal} class and name,
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   275
     * it does not add that {@code Permission} to the returned
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   276
     * {@code PermissionCollection}.  Instead, it builds
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   277
     * a new {@code PrivateCredentialPermission}
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   278
     * for each {@code Principal} associated with the provided
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   279
     * {@code Subject}.  Each new {@code PrivateCredentialPermission}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * contains the same Credential class as specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * originally granted permission, as well as the Class and name
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   282
     * for the respective {@code Principal}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   284
     * @param subject the Permissions granted to this {@code Subject}
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   285
     *          and the additionally provided {@code CodeSource}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *          are returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   288
     * @param codesource the Permissions granted to this {@code CodeSource}
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   289
     *          and the additionally provided {@code Subject}
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   290
     *          are returned.
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   291
     *
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   292
     * @return the Permissions granted to the provided {@code Subject}
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   293
     *          {@code CodeSource}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
19439
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents: 19212
diff changeset
   295
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public PermissionCollection getPermissions(final Subject subject,
19439
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents: 19212
diff changeset
   297
                                               final CodeSource codesource) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents: 19212
diff changeset
   298
        return apf.getPermissions(subject, codesource);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
}