KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > security > IdentityScope


1 /*
2  * @(#)IdentityScope.java 1.54 04/05/18
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7  
8 package java.security;
9
10 import java.io.Serializable JavaDoc;
11 import java.util.Enumeration JavaDoc;
12 import java.util.Properties JavaDoc;
13
14 /**
15  * <p>This class represents a scope for identities. It is an Identity
16  * itself, and therefore has a name and can have a scope. It can also
17  * optionally have a public key and associated certificates.
18  *
19  * <p>An IdentityScope can contain Identity objects of all kinds, including
20  * Signers. All types of Identity objects can be retrieved, added, and
21  * removed using the same methods. Note that it is possible, and in fact
22  * expected, that different types of identity scopes will
23  * apply different policies for their various operations on the
24  * various types of Identities.
25  *
26  * <p>There is a one-to-one mapping between keys and identities, and
27  * there can only be one copy of one key per scope. For example, suppose
28  * <b>Acme Software, Inc</b> is a software publisher known to a user.
29  * Suppose it is an Identity, that is, it has a public key, and a set of
30  * associated certificates. It is named in the scope using the name
31  * "Acme Software". No other named Identity in the scope has the same
32  * public key. Of course, none has the same name as well.
33  *
34  * @see Identity
35  * @see Signer
36  * @see Principal
37  * @see Key
38  *
39  * @version 1.54 04/05/18
40  * @author Benjamin Renaud
41  *
42  * @deprecated This class is no longer used. Its functionality has been
43  * replaced by <code>java.security.KeyStore</code>, the
44  * <code>java.security.cert</code> package, and
45  * <code>java.security.Principal</code>.
46  */

47 @Deprecated JavaDoc
48 public abstract
49 class IdentityScope extends Identity JavaDoc {
50
51     private static final long serialVersionUID = -2337346281189773310L;
52
53     /* The system's scope */
54     private static IdentityScope JavaDoc scope;
55
56     // initialize the system scope
57
private static void initializeSystemScope() {
58
59     String JavaDoc classname = (String JavaDoc) AccessController.doPrivileged(
60                                new PrivilegedAction JavaDoc() {
61         public Object JavaDoc run() {
62         return Security.getProperty("system.scope");
63         }
64     });
65
66     if (classname == null) {
67         return;
68
69         } else {
70
71         try {
72         Class.forName(classname);
73         } catch (ClassNotFoundException JavaDoc e) {
74         //Security.error("unable to establish a system scope from " +
75
// classname);
76
e.printStackTrace();
77         }
78     }
79     }
80
81     /**
82      * This constructor is used for serialization only and should not
83      * be used by subclasses.
84      */

85     protected IdentityScope() {
86     this("restoring...");
87     }
88
89     /**
90      * Constructs a new identity scope with the specified name.
91      *
92      * @param name the scope name.
93      */

94     public IdentityScope(String JavaDoc name) {
95     super(name);
96     }
97
98     /**
99      * Constructs a new identity scope with the specified name and scope.
100      *
101      * @param name the scope name.
102      * @param scope the scope for the new identity scope.
103      *
104      * @exception KeyManagementException if there is already an identity
105      * with the same name in the scope.
106      */

107     public IdentityScope(String JavaDoc name, IdentityScope JavaDoc scope)
108     throws KeyManagementException JavaDoc {
109     super(name, scope);
110     }
111
112     /**
113      * Returns the system's identity scope.
114      *
115      * @return the system's identity scope.
116      *
117      * @see #setSystemScope
118      */

119     public static IdentityScope JavaDoc getSystemScope() {
120     if (scope == null) {
121         initializeSystemScope();
122     }
123     return scope;
124     }
125
126
127     /**
128      * Sets the system's identity scope.
129      *
130      * <p>First, if there is a security manager, its
131      * <code>checkSecurityAccess</code>
132      * method is called with <code>"setSystemScope"</code>
133      * as its argument to see if it's ok to set the identity scope.
134      *
135      * @param scope the scope to set.
136      *
137      * @exception SecurityException if a security manager exists and its
138      * <code>checkSecurityAccess</code> method doesn't allow
139      * setting the identity scope.
140      *
141      * @see #getSystemScope
142      * @see SecurityManager#checkSecurityAccess
143      */

144     protected static void setSystemScope(IdentityScope JavaDoc scope) {
145     check("setSystemScope");
146     IdentityScope.scope = scope;
147     }
148
149     /**
150      * Returns the number of identities within this identity scope.
151      *
152      * @return the number of identities within this identity scope.
153      */

154     public abstract int size();
155
156     /**
157      * Returns the identity in this scope with the specified name (if any).
158      *
159      * @param name the name of the identity to be retrieved.
160      *
161      * @return the identity named <code>name</code>, or null if there are
162      * no identities named <code>name</code> in this scope.
163      */

164     public abstract Identity JavaDoc getIdentity(String JavaDoc name);
165
166     /**
167      * Retrieves the identity whose name is the same as that of the
168      * specified principal. (Note: Identity implements Principal.)
169      *
170      * @param principal the principal corresponding to the identity
171      * to be retrieved.
172      *
173      * @return the identity whose name is the same as that of the
174      * principal, or null if there are no identities of the same name
175      * in this scope.
176      */

177     public Identity JavaDoc getIdentity(Principal JavaDoc principal) {
178     return getIdentity(principal.getName());
179     }
180
181     /**
182      * Retrieves the identity with the specified public key.
183      *
184      * @param key the public key for the identity to be returned.
185      *
186      * @return the identity with the given key, or null if there are
187      * no identities in this scope with that key.
188      */

189     public abstract Identity JavaDoc getIdentity(PublicKey JavaDoc key);
190
191     /**
192      * Adds an identity to this identity scope.
193      *
194      * @param identity the identity to be added.
195      *
196      * @exception KeyManagementException if the identity is not
197      * valid, a name conflict occurs, another identity has the same
198      * public key as the identity being added, or another exception
199      * occurs. */

200     public abstract void addIdentity(Identity JavaDoc identity)
201     throws KeyManagementException JavaDoc;
202
203     /**
204      * Removes an identity from this identity scope.
205      *
206      * @param identity the identity to be removed.
207      *
208      * @exception KeyManagementException if the identity is missing,
209      * or another exception occurs.
210      */

211     public abstract void removeIdentity(Identity JavaDoc identity)
212     throws KeyManagementException JavaDoc;
213
214     /**
215      * Returns an enumeration of all identities in this identity scope.
216      *
217      * @return an enumeration of all identities in this identity scope.
218      */

219     public abstract Enumeration JavaDoc<Identity JavaDoc> identities();
220
221     /**
222      * Returns a string representation of this identity scope, including
223      * its name, its scope name, and the number of identities in this
224      * identity scope.
225      *
226      * @return a string representation of this identity scope.
227      */

228     public String JavaDoc toString() {
229     return super.toString() + "[" + size() + "]";
230     }
231
232     private static void check(String JavaDoc directive) {
233     SecurityManager JavaDoc security = System.getSecurityManager();
234     if (security != null) {
235         security.checkSecurityAccess(directive);
236     }
237     }
238
239 }
240
Popular Tags