Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / java / security / IdentityScope.java
blobd1ea1f29500ad2933fdb470a3ad9aa74dc245b1c
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 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 * <code>IdentityScope</code> represents a scope of an identity.
44 * <code>IdentityScope</code> is also an {@link Identity} and can have a name
45 * and scope along with the other qualitites identities possess.
47 * <p>An <code>IdentityScope</code> contains other {@link Identity} objects.
48 * All {@link Identity} objects are manipulated in the scope the same way. The
49 * scope is supposed to apply different scope to different type of
50 * Identities.</p>
52 * <p>No identity within the same scope can have the same public key.</p>
54 * @author Mark Benvenuto
55 * @see Identity
56 * @see Signer
57 * @see Principal
58 * @see Key
59 * @deprecated Use java.security.KeyStore, the java.security.cert package, and
60 * java.security.Principal.
62 public abstract class IdentityScope extends Identity
64 private static final long serialVersionUID = -2337346281189773310L;
65 private static IdentityScope systemScope;
67 /** Constructor for serialization purposes. */
68 protected IdentityScope()
70 super();
73 /**
74 * Constructs a new instance of <code>IdentityScope</code> with the
75 * specified name and no scope.
77 * @param name
78 * the name to use.
80 public IdentityScope(String name)
82 super(name);
85 /**
86 * Constructs a new instance of <code>IdentityScope</code> with the
87 * specified name and {@link IdentityScope}.
89 * @param name
90 * the name to use.
91 * @param scope
92 * the scope to use.
93 * @throws KeyManagementException
94 * if the identity scope is already present.
96 public IdentityScope(String name, IdentityScope scope)
97 throws KeyManagementException
99 super(name, scope);
103 * Returns the system's Scope.
105 * @return the system's Scope.
107 public static IdentityScope getSystemScope()
109 if (systemScope == null)
111 //Load it
112 //systemScope;
114 return systemScope;
118 * Sets the scope of the system.
120 * @param scope
121 * the new system scope.
122 * @throws SecurityException
123 * if a {@link SecurityManager} is installed which disallows this
124 * operation.
126 protected static void setSystemScope(IdentityScope scope)
128 SecurityManager sm = System.getSecurityManager();
129 if (sm != null)
130 sm.checkSecurityAccess("setSystemScope");
132 systemScope = scope;
136 * Returns the number of entries within this <code>IdentityScope</code>.
138 * @return the number of entries within this <code>IdentityScope</code>.
140 public abstract int size();
143 * Returns the specified {@link Identity}, by name, within this scope.
145 * @param name
146 * name of {@link Identity} to get.
147 * @return an {@link Identity} representing the name or <code>null</code> if
148 * it cannot be found.
150 public abstract Identity getIdentity(String name);
153 * Returns the specified {@link Identity}, by {@link Principal}, within this
154 * scope.
156 * @param principal
157 * the {@link Principal} to use.
158 * @return an identity representing the {@link Principal} or <code>null</code>
159 * if it cannot be found.
161 public Identity getIdentity(Principal principal)
163 return getIdentity(principal.getName());
167 * Returns the specified {@link Identity}, by public key, within this scope.
169 * @param key
170 * the {@link PublicKey} to use.
171 * @return an identity representing the public key or <code>null</code> if
172 * it cannot be found.
174 public abstract Identity getIdentity(PublicKey key);
177 * Adds an identity to his scope.
179 * @param identity
180 * the {@link Identity} to add.
181 * @throws KeyManagementException
182 * if it is an invalid identity, an identity with the same key
183 * exists, or if another error occurs.
185 public abstract void addIdentity(Identity identity)
186 throws KeyManagementException;
189 * Removes an identity in this scope.
191 * @param identity
192 * the {@link Identity} to remove.
193 * @throws KeyManagementException
194 * if it is a missing identity, or if another error occurs.
196 public abstract void removeIdentity(Identity identity)
197 throws KeyManagementException;
200 * Returns an {@link Enumeration} of identities in this scope.
202 * @return an {@link Enumeration} of the identities in this scope.
204 public abstract Enumeration identities();
207 * Returns a string representing this instance. It includes the name, the
208 * scope name, and number of identities.
210 * @return a string representation of this instance.
212 public String toString()
214 return (super.getName() + " " + super.getScope().getName() + " " + size());