001 /*
002 * Copyright 1996-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.security;
027
028 import java.io.Serializable;
029 import java.util.Enumeration;
030 import java.util.Properties;
031
032 /**
033 * <p>This class represents a scope for identities. It is an Identity
034 * itself, and therefore has a name and can have a scope. It can also
035 * optionally have a public key and associated certificates.
036 *
037 * <p>An IdentityScope can contain Identity objects of all kinds, including
038 * Signers. All types of Identity objects can be retrieved, added, and
039 * removed using the same methods. Note that it is possible, and in fact
040 * expected, that different types of identity scopes will
041 * apply different policies for their various operations on the
042 * various types of Identities.
043 *
044 * <p>There is a one-to-one mapping between keys and identities, and
045 * there can only be one copy of one key per scope. For example, suppose
046 * <b>Acme Software, Inc</b> is a software publisher known to a user.
047 * Suppose it is an Identity, that is, it has a public key, and a set of
048 * associated certificates. It is named in the scope using the name
049 * "Acme Software". No other named Identity in the scope has the same
050 * public key. Of course, none has the same name as well.
051 *
052 * @see Identity
053 * @see Signer
054 * @see Principal
055 * @see Key
056 *
057 * @version 1.62 07/05/05
058 * @author Benjamin Renaud
059 *
060 * @deprecated This class is no longer used. Its functionality has been
061 * replaced by <code>java.security.KeyStore</code>, the
062 * <code>java.security.cert</code> package, and
063 * <code>java.security.Principal</code>.
064 */
065 @Deprecated
066 public abstract class IdentityScope extends Identity {
067
068 private static final long serialVersionUID = -2337346281189773310L;
069
070 /* The system's scope */
071 private static IdentityScope scope;
072
073 // initialize the system scope
074 private static void initializeSystemScope() {
075
076 String classname = AccessController
077 .doPrivileged(new PrivilegedAction<String>() {
078 public String run() {
079 return Security.getProperty("system.scope");
080 }
081 });
082
083 if (classname == null) {
084 return;
085
086 } else {
087
088 try {
089 Class.forName(classname);
090 } catch (ClassNotFoundException e) {
091 //Security.error("unable to establish a system scope from " +
092 // classname);
093 e.printStackTrace();
094 }
095 }
096 }
097
098 /**
099 * 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 * Sets the system's identity scope.
145 *
146 * <p>First, if there is a security manager, its
147 * <code>checkSecurityAccess</code>
148 * method is called with <code>"setSystemScope"</code>
149 * as its argument to see if it's ok to set the identity scope.
150 *
151 * @param scope the scope to set.
152 *
153 * @exception SecurityException if a security manager exists and its
154 * <code>checkSecurityAccess</code> method doesn't allow
155 * setting the identity scope.
156 *
157 * @see #getSystemScope
158 * @see SecurityManager#checkSecurityAccess
159 */
160 protected static void setSystemScope(IdentityScope scope) {
161 check("setSystemScope");
162 IdentityScope.scope = scope;
163 }
164
165 /**
166 * Returns the number of identities within this identity scope.
167 *
168 * @return the number of identities within this identity scope.
169 */
170 public abstract int size();
171
172 /**
173 * Returns the identity in this scope with the specified name (if any).
174 *
175 * @param name the name of the identity to be retrieved.
176 *
177 * @return the identity named <code>name</code>, or null if there are
178 * no identities named <code>name</code> in this scope.
179 */
180 public abstract Identity getIdentity(String name);
181
182 /**
183 * Retrieves the identity whose name is the same as that of the
184 * specified principal. (Note: Identity implements Principal.)
185 *
186 * @param principal the principal corresponding to the identity
187 * to be retrieved.
188 *
189 * @return the identity whose name is the same as that of the
190 * principal, or null if there are no identities of the same name
191 * in this scope.
192 */
193 public Identity getIdentity(Principal principal) {
194 return getIdentity(principal.getName());
195 }
196
197 /**
198 * Retrieves the identity with the specified public key.
199 *
200 * @param key the public key for the identity to be returned.
201 *
202 * @return the identity with the given key, or null if there are
203 * no identities in this scope with that key.
204 */
205 public abstract Identity getIdentity(PublicKey key);
206
207 /**
208 * Adds an identity to this identity scope.
209 *
210 * @param identity the identity to be added.
211 *
212 * @exception KeyManagementException if the identity is not
213 * valid, a name conflict occurs, another identity has the same
214 * public key as the identity being added, or another exception
215 * occurs. */
216 public abstract void addIdentity(Identity identity)
217 throws KeyManagementException;
218
219 /**
220 * Removes an identity from this identity scope.
221 *
222 * @param identity the identity to be removed.
223 *
224 * @exception KeyManagementException if the identity is missing,
225 * or another exception occurs.
226 */
227 public abstract void removeIdentity(Identity identity)
228 throws KeyManagementException;
229
230 /**
231 * Returns an enumeration of all identities in this identity scope.
232 *
233 * @return an enumeration of all identities in this identity scope.
234 */
235 public abstract Enumeration<Identity> identities();
236
237 /**
238 * Returns a string representation of this identity scope, including
239 * its name, its scope name, and the number of identities in this
240 * identity scope.
241 *
242 * @return a string representation of this identity scope.
243 */
244 public String toString() {
245 return super .toString() + "[" + size() + "]";
246 }
247
248 private static void check(String directive) {
249 SecurityManager security = System.getSecurityManager();
250 if (security != null) {
251 security.checkSecurityAccess(directive);
252 }
253 }
254
255 }
|