2
|
1 |
/*
|
|
2 |
* Copyright 1996-2006 Sun Microsystems, Inc. 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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any 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 |
*
|
|
59 |
* @deprecated This class is no longer used. Its functionality has been
|
|
60 |
* replaced by <code>java.security.KeyStore</code>, the
|
|
61 |
* <code>java.security.cert</code> package, and
|
|
62 |
* <code>java.security.Principal</code>.
|
|
63 |
*/
|
|
64 |
@Deprecated
|
|
65 |
public abstract
|
|
66 |
class IdentityScope extends Identity {
|
|
67 |
|
|
68 |
private static final long serialVersionUID = -2337346281189773310L;
|
|
69 |
|
|
70 |
/* The system's scope */
|
|
71 |
private static IdentityScope scope;
|
|
72 |
|
|
73 |
// initialize the system scope
|
|
74 |
private static void initializeSystemScope() {
|
|
75 |
|
|
76 |
String classname = AccessController.doPrivileged(
|
|
77 |
new PrivilegedAction<String>() {
|
|
78 |
public String run() {
|
|
79 |
return Security.getProperty("system.scope");
|
|
80 |
}
|
|
81 |
});
|
|
82 |
|
|
83 |
if (classname == null) {
|
|
84 |
return;
|
|
85 |
|
|
86 |
} else {
|
|
87 |
|
|
88 |
try {
|
|
89 |
Class.forName(classname);
|
|
90 |
} catch (ClassNotFoundException e) {
|
|
91 |
//Security.error("unable to establish a system scope from " +
|
|
92 |
// classname);
|
|
93 |
e.printStackTrace();
|
|
94 |
}
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
/**
|
|
99 |
* This constructor is used for serialization only and should not
|
|
100 |
* be used by subclasses.
|
|
101 |
*/
|
|
102 |
protected IdentityScope() {
|
|
103 |
this("restoring...");
|
|
104 |
}
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Constructs a new identity scope with the specified name.
|
|
108 |
*
|
|
109 |
* @param name the scope name.
|
|
110 |
*/
|
|
111 |
public IdentityScope(String name) {
|
|
112 |
super(name);
|
|
113 |
}
|
|
114 |
|
|
115 |
/**
|
|
116 |
* Constructs a new identity scope with the specified name and scope.
|
|
117 |
*
|
|
118 |
* @param name the scope name.
|
|
119 |
* @param scope the scope for the new identity scope.
|
|
120 |
*
|
|
121 |
* @exception KeyManagementException if there is already an identity
|
|
122 |
* with the same name in the scope.
|
|
123 |
*/
|
|
124 |
public IdentityScope(String name, IdentityScope scope)
|
|
125 |
throws KeyManagementException {
|
|
126 |
super(name, scope);
|
|
127 |
}
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Returns the system's identity scope.
|
|
131 |
*
|
|
132 |
* @return the system's identity scope.
|
|
133 |
*
|
|
134 |
* @see #setSystemScope
|
|
135 |
*/
|
|
136 |
public static IdentityScope getSystemScope() {
|
|
137 |
if (scope == null) {
|
|
138 |
initializeSystemScope();
|
|
139 |
}
|
|
140 |
return scope;
|
|
141 |
}
|
|
142 |
|
|
143 |
|
|
144 |
/**
|
|
145 |
* Sets the system's identity scope.
|
|
146 |
*
|
|
147 |
* <p>First, if there is a security manager, its
|
|
148 |
* <code>checkSecurityAccess</code>
|
|
149 |
* method is called with <code>"setSystemScope"</code>
|
|
150 |
* as its argument to see if it's ok to set the identity scope.
|
|
151 |
*
|
|
152 |
* @param scope the scope to set.
|
|
153 |
*
|
|
154 |
* @exception SecurityException if a security manager exists and its
|
|
155 |
* <code>checkSecurityAccess</code> method doesn't allow
|
|
156 |
* setting the identity scope.
|
|
157 |
*
|
|
158 |
* @see #getSystemScope
|
|
159 |
* @see SecurityManager#checkSecurityAccess
|
|
160 |
*/
|
|
161 |
protected static void setSystemScope(IdentityScope scope) {
|
|
162 |
check("setSystemScope");
|
|
163 |
IdentityScope.scope = scope;
|
|
164 |
}
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Returns the number of identities within this identity scope.
|
|
168 |
*
|
|
169 |
* @return the number of identities within this identity scope.
|
|
170 |
*/
|
|
171 |
public abstract int size();
|
|
172 |
|
|
173 |
/**
|
|
174 |
* Returns the identity in this scope with the specified name (if any).
|
|
175 |
*
|
|
176 |
* @param name the name of the identity to be retrieved.
|
|
177 |
*
|
|
178 |
* @return the identity named <code>name</code>, or null if there are
|
|
179 |
* no identities named <code>name</code> in this scope.
|
|
180 |
*/
|
|
181 |
public abstract Identity getIdentity(String name);
|
|
182 |
|
|
183 |
/**
|
|
184 |
* Retrieves the identity whose name is the same as that of the
|
|
185 |
* specified principal. (Note: Identity implements Principal.)
|
|
186 |
*
|
|
187 |
* @param principal the principal corresponding to the identity
|
|
188 |
* to be retrieved.
|
|
189 |
*
|
|
190 |
* @return the identity whose name is the same as that of the
|
|
191 |
* principal, or null if there are no identities of the same name
|
|
192 |
* in this scope.
|
|
193 |
*/
|
|
194 |
public Identity getIdentity(Principal principal) {
|
|
195 |
return getIdentity(principal.getName());
|
|
196 |
}
|
|
197 |
|
|
198 |
/**
|
|
199 |
* Retrieves the identity with the specified public key.
|
|
200 |
*
|
|
201 |
* @param key the public key for the identity to be returned.
|
|
202 |
*
|
|
203 |
* @return the identity with the given key, or null if there are
|
|
204 |
* no identities in this scope with that key.
|
|
205 |
*/
|
|
206 |
public abstract Identity getIdentity(PublicKey key);
|
|
207 |
|
|
208 |
/**
|
|
209 |
* Adds an identity to this identity scope.
|
|
210 |
*
|
|
211 |
* @param identity the identity to be added.
|
|
212 |
*
|
|
213 |
* @exception KeyManagementException if the identity is not
|
|
214 |
* valid, a name conflict occurs, another identity has the same
|
|
215 |
* public key as the identity being added, or another exception
|
|
216 |
* occurs. */
|
|
217 |
public abstract void addIdentity(Identity identity)
|
|
218 |
throws KeyManagementException;
|
|
219 |
|
|
220 |
/**
|
|
221 |
* Removes an identity from this identity scope.
|
|
222 |
*
|
|
223 |
* @param identity the identity to be removed.
|
|
224 |
*
|
|
225 |
* @exception KeyManagementException if the identity is missing,
|
|
226 |
* or another exception occurs.
|
|
227 |
*/
|
|
228 |
public abstract void removeIdentity(Identity identity)
|
|
229 |
throws KeyManagementException;
|
|
230 |
|
|
231 |
/**
|
|
232 |
* Returns an enumeration of all identities in this identity scope.
|
|
233 |
*
|
|
234 |
* @return an enumeration of all identities in this identity scope.
|
|
235 |
*/
|
|
236 |
public abstract Enumeration<Identity> identities();
|
|
237 |
|
|
238 |
/**
|
|
239 |
* Returns a string representation of this identity scope, including
|
|
240 |
* its name, its scope name, and the number of identities in this
|
|
241 |
* identity scope.
|
|
242 |
*
|
|
243 |
* @return a string representation of this identity scope.
|
|
244 |
*/
|
|
245 |
public String toString() {
|
|
246 |
return super.toString() + "[" + size() + "]";
|
|
247 |
}
|
|
248 |
|
|
249 |
private static void check(String directive) {
|
|
250 |
SecurityManager security = System.getSecurityManager();
|
|
251 |
if (security != null) {
|
|
252 |
security.checkSecurityAccess(directive);
|
|
253 |
}
|
|
254 |
}
|
|
255 |
|
|
256 |
}
|