2003-10-28 David S. Miller <davem@redhat.com>
[official-gcc.git] / libjava / java / security / IdentityScope.java
blob88e00fc81c027b84a5c3e8e5bab0273105782fe7
1 /* IdentityScope.java --- IdentityScope Class
2 Copyright (C) 1999, 2003, Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.security;
40 import java.util.Enumeration;
42 /**
43 * <p>This class represents a scope for identities. It is an Identity itself,
44 * and therefore has a name and can have a scope. It can also optionally have a
45 * public key and associated certificates.</p>
47 * <p>An <code>IdentityScope</code> can contain {@link Identity} objects of all
48 * kinds, including {@link Signer}s. All types of <code>Identity</code> objects
49 * can be retrieved, added, and removed using the same methods. Note that it is
50 * possible, and in fact expected, that different types of identity scopes will
51 * apply different policies for their various operations on the various types of
52 * Identities.</p>
54 * <p>There is a one-to-one mapping between keys and identities, and there can
55 * only be one copy of one key per scope. For example, suppose Acme Software,
56 * Inc is a software publisher known to a user. Suppose it is an <i>Identity</i>,
57 * that is, it has a public key, and a set of associated certificates. It is
58 * named in the scope using the name "Acme Software". No other named <i>Identity
59 * </i> in the scope has the same public key. Of course, none has the same name
60 * as well.</p>
62 * @author Mark Benvenuto
63 * @see Identity
64 * @see Signer
65 * @see Principal
66 * @see Key
67 * @deprecated This class is no longer used. Its functionality has been replaced
68 * by <code>java.security.KeyStore</code>, the <code>java.security.cert</code>
69 * package, and <code>java.security.Principal</code>.
71 public abstract class IdentityScope extends Identity
73 private static final long serialVersionUID = -2337346281189773310L;
74 private static IdentityScope systemScope = null;
76 /**
77 * This constructor is used for serialization only and should not be used by
78 * subclasses.
80 protected IdentityScope()
82 super();
85 /**
86 * Constructs a new identity scope with the specified name.
88 * @param name the scope name.
90 public IdentityScope(String name)
92 super(name);
95 /**
96 * Constructs a new identity scope with the specified name and scope.
98 * @param name the scope name.
99 * @param scope the scope for the new identity scope.
100 * @throws KeyManagementException if there is already an identity with the
101 * same name in the scope.
103 public IdentityScope(String name, IdentityScope scope)
104 throws KeyManagementException
106 super(name, scope);
110 * Returns the system's identity scope.
112 * @return the system's identity scope.
113 * @see #setSystemScope(IdentityScope)
115 public static IdentityScope getSystemScope()
117 if (systemScope == null)
119 //Load it
120 //systemScope;
122 return systemScope;
126 * <p>Sets the system's identity scope.</p>
128 * <p>First, if there is a security manager, its <code>checkSecurityAccess()
129 * </code> method is called with <code>"setSystemScope"</code> as its argument
130 * to see if it's ok to set the identity scope.</p>
132 * @param scope the scope to set.
133 * @throws SecurityException if a security manager exists and its
134 * <code>checkSecurityAccess()<code> method doesn't allow setting the
135 * identity scope.
136 * @see #getSystemScope()
137 * @see SecurityManager#checkSecurityAccess(String)
139 protected static void setSystemScope(IdentityScope scope)
141 SecurityManager sm = System.getSecurityManager();
142 if (sm != null)
143 sm.checkSecurityAccess("setSystemScope");
145 systemScope = scope;
149 * Returns the number of identities within this identity scope.
151 * @return the number of identities within this identity scope.
153 public abstract int size();
156 * Returns the identity in this scope with the specified name (if any).
158 * @param name the name of the identity to be retrieved.
159 * @return the identity named name, or <code>null</code> if there are no
160 * identities named name in this scope.
162 public abstract Identity getIdentity(String name);
165 * Retrieves the identity whose name is the same as that of the specified
166 * principal. (Note: <code>Identity</code> implements <code>Principal</code>.)
168 * @param principal the principal corresponding to the identity to be
169 * retrieved.
170 * @return the identity whose name is the same as that of the principal, or
171 * <code>null</code> if there are no identities of the same name in this scope.
173 public Identity getIdentity(Principal principal)
175 return getIdentity(principal.getName());
179 * Retrieves the identity with the specified public key.
181 * @param key the public key for the identity to be returned.
182 * @return the identity with the given key, or <code>null</code> if there are
183 * no identities in this scope with that key.
185 public abstract Identity getIdentity(PublicKey key);
188 * Adds an identity to this identity scope.
190 * @param identity the identity to be added.
191 * @throws KeyManagementException if the identity is not valid, a name
192 * conflict occurs, another identity has the same public key as the identity
193 * being added, or another exception occurs.
195 public abstract void addIdentity(Identity identity)
196 throws KeyManagementException;
199 * Removes an identity from this identity scope.
201 * @param identity the identity to be removed.
202 * @throws KeyManagementException if the identity is missing, or another
203 * exception occurs.
205 public abstract void removeIdentity(Identity identity)
206 throws KeyManagementException;
209 * Returns an enumeration of all identities in this identity scope.
211 * @return an enumeration of all identities in this identity scope.
213 public abstract Enumeration identities();
216 * Returns a string representation of this identity scope, including its name,
217 * its scope name, and the number of identities in this identity scope.
219 * @return a string representation of this identity scope.
220 * @see SecurityManager#checkSecurityAccess(String)
222 public String toString()
224 return (super.getName() + " " + super.getScope().getName() + " " + size());