Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/java/security/IdentityScope.java
41152 views
1
/*
2
* Copyright (c) 1996, 2019, 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 java.security;
27
28
import java.io.Serializable;
29
import java.util.Enumeration;
30
import java.util.Properties;
31
32
/**
33
* <p>This class represents a scope for identities. It is an Identity
34
* itself, and therefore has a name and can have a scope. It can also
35
* optionally have a public key and associated certificates.
36
*
37
* <p>An IdentityScope can contain Identity objects of all kinds, including
38
* Signers. All types of Identity objects can be retrieved, added, and
39
* removed using the same methods. Note that it is possible, and in fact
40
* expected, that different types of identity scopes will
41
* apply different policies for their various operations on the
42
* various types of Identities.
43
*
44
* <p>There is a one-to-one mapping between keys and identities, and
45
* there can only be one copy of one key per scope. For example, suppose
46
* <b>Acme Software, Inc</b> is a software publisher known to a user.
47
* Suppose it is an Identity, that is, it has a public key, and a set of
48
* associated certificates. It is named in the scope using the name
49
* "Acme Software". No other named Identity in the scope has the same
50
* public key. Of course, none has the same name as well.
51
*
52
* @see Identity
53
* @see Signer
54
* @see Principal
55
* @see Key
56
*
57
* @author Benjamin Renaud
58
* @since 1.1
59
*
60
* @deprecated This class is deprecated and subject to removal in a future
61
* version of Java SE. It has been replaced by
62
* {@code java.security.KeyStore}, the {@code java.security.cert} package,
63
* and {@code java.security.Principal}.
64
*/
65
@Deprecated(since="1.2", forRemoval=true)
66
@SuppressWarnings("removal")
67
public abstract
68
class IdentityScope extends Identity {
69
70
@java.io.Serial
71
private static final long serialVersionUID = -2337346281189773310L;
72
73
/* The system's scope */
74
private static IdentityScope scope;
75
76
// initialize the system scope
77
private static void initializeSystemScope() {
78
79
String classname = AccessController.doPrivileged(
80
new PrivilegedAction<>() {
81
public String run() {
82
return Security.getProperty("system.scope");
83
}
84
});
85
86
if (classname == null) {
87
return;
88
89
} else {
90
91
try {
92
Class.forName(classname);
93
} catch (ClassNotFoundException e) {
94
System.err.println("unable to establish a system scope from " +
95
classname);
96
e.printStackTrace();
97
}
98
}
99
}
100
101
/**
102
* This constructor is used for serialization only and should not
103
* be used by subclasses.
104
*/
105
protected IdentityScope() {
106
this("restoring...");
107
}
108
109
/**
110
* Constructs a new identity scope with the specified name.
111
*
112
* @param name the scope name.
113
*/
114
public IdentityScope(String name) {
115
super(name);
116
}
117
118
/**
119
* Constructs a new identity scope with the specified name and scope.
120
*
121
* @param name the scope name.
122
* @param scope the scope for the new identity scope.
123
*
124
* @throws KeyManagementException if there is already an identity
125
* with the same name in the scope.
126
*/
127
public IdentityScope(String name, IdentityScope scope)
128
throws KeyManagementException {
129
super(name, scope);
130
}
131
132
/**
133
* Returns the system's identity scope.
134
*
135
* @return the system's identity scope, or {@code null} if none has been
136
* set.
137
*
138
* @see #setSystemScope
139
*/
140
public static IdentityScope getSystemScope() {
141
if (scope == null) {
142
initializeSystemScope();
143
}
144
return scope;
145
}
146
147
148
/**
149
* Sets the system's identity scope.
150
*
151
* <p>First, if there is a security manager, its
152
* {@code checkSecurityAccess}
153
* method is called with {@code "setSystemScope"}
154
* as its argument to see if it's ok to set the identity scope.
155
*
156
* @param scope the scope to set.
157
*
158
* @throws SecurityException if a security manager exists and its
159
* {@code checkSecurityAccess} method doesn't allow
160
* setting the identity scope.
161
*
162
* @see #getSystemScope
163
* @see SecurityManager#checkSecurityAccess
164
*/
165
protected static void setSystemScope(IdentityScope scope) {
166
check("setSystemScope");
167
IdentityScope.scope = scope;
168
}
169
170
/**
171
* Returns the number of identities within this identity scope.
172
*
173
* @return the number of identities within this identity scope.
174
*/
175
public abstract int size();
176
177
/**
178
* Returns the identity in this scope with the specified name (if any).
179
*
180
* @param name the name of the identity to be retrieved.
181
*
182
* @return the identity named {@code name}, or null if there are
183
* no identities named {@code name} in this scope.
184
*/
185
public abstract Identity getIdentity(String name);
186
187
/**
188
* Retrieves the identity whose name is the same as that of the
189
* specified principal. (Note: Identity implements Principal.)
190
*
191
* @param principal the principal corresponding to the identity
192
* to be retrieved.
193
*
194
* @return the identity whose name is the same as that of the
195
* principal, or null if there are no identities of the same name
196
* in this scope.
197
*/
198
public Identity getIdentity(Principal principal) {
199
return getIdentity(principal.getName());
200
}
201
202
/**
203
* Retrieves the identity with the specified public key.
204
*
205
* @param key the public key for the identity to be returned.
206
*
207
* @return the identity with the given key, or null if there are
208
* no identities in this scope with that key.
209
*/
210
public abstract Identity getIdentity(PublicKey key);
211
212
/**
213
* Adds an identity to this identity scope.
214
*
215
* @param identity the identity to be added.
216
*
217
* @throws KeyManagementException if the identity is not
218
* valid, a name conflict occurs, another identity has the same
219
* public key as the identity being added, or another exception
220
* occurs. */
221
public abstract void addIdentity(Identity identity)
222
throws KeyManagementException;
223
224
/**
225
* Removes an identity from this identity scope.
226
*
227
* @param identity the identity to be removed.
228
*
229
* @throws KeyManagementException if the identity is missing,
230
* or another exception occurs.
231
*/
232
public abstract void removeIdentity(Identity identity)
233
throws KeyManagementException;
234
235
/**
236
* Returns an enumeration of all identities in this identity scope.
237
*
238
* @return an enumeration of all identities in this identity scope.
239
*/
240
public abstract Enumeration<Identity> identities();
241
242
/**
243
* Returns a string representation of this identity scope, including
244
* its name, its scope name, and the number of identities in this
245
* identity scope.
246
*
247
* @return a string representation of this identity scope.
248
*/
249
public String toString() {
250
return super.toString() + "[" + size() + "]";
251
}
252
253
private static void check(String directive) {
254
SecurityManager security = System.getSecurityManager();
255
if (security != null) {
256
security.checkSecurityAccess(directive);
257
}
258
}
259
260
}
261
262