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