| 1 | /* IdentityScope.java --- IdentityScope Class
|
|---|
| 2 | Copyright (C) 1999 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 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.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 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.
|
|---|
| 20 |
|
|---|
| 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.
|
|---|
| 25 |
|
|---|
| 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. */
|
|---|
| 37 |
|
|---|
| 38 | package java.security;
|
|---|
| 39 | import java.util.Enumeration;
|
|---|
| 40 |
|
|---|
| 41 | /**
|
|---|
| 42 | IdentityScope represents a scope of an identity. IdentityScope
|
|---|
| 43 | is also an Identity and can have a name and scope along with
|
|---|
| 44 | the other qualitites identities posses.
|
|---|
| 45 |
|
|---|
| 46 | An IdentityScope contains other Identity objects. All Identity
|
|---|
| 47 | objects are manipulated in the scope the same way. The scope
|
|---|
| 48 | is suppose to apply different scope to different type of
|
|---|
| 49 | Identities.
|
|---|
| 50 |
|
|---|
| 51 | No identity within the same scope can have the same public key.
|
|---|
| 52 |
|
|---|
| 53 | @since JDK 1.1
|
|---|
| 54 |
|
|---|
| 55 | @deprecated Use java.security.KeyStore, the java.security.cert
|
|---|
| 56 | package, and java.security.Principal.
|
|---|
| 57 |
|
|---|
| 58 | @author Mark Benvenuto
|
|---|
| 59 | */
|
|---|
| 60 | public abstract class IdentityScope extends Identity
|
|---|
| 61 | {
|
|---|
| 62 | private static IdentityScope systemScope = null;
|
|---|
| 63 |
|
|---|
| 64 | /**
|
|---|
| 65 | Creates a new instance of IdentityScope from Serialized Data
|
|---|
| 66 | */
|
|---|
| 67 | protected IdentityScope()
|
|---|
| 68 | {
|
|---|
| 69 | super();
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | /**
|
|---|
| 73 | Creates a new instance of IdentityScope with the specified name
|
|---|
| 74 | and no scope.
|
|---|
| 75 |
|
|---|
| 76 | @param name the name to use
|
|---|
| 77 | */
|
|---|
| 78 | public IdentityScope(String name)
|
|---|
| 79 | {
|
|---|
| 80 | super(name);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | /**
|
|---|
| 84 | Creates a new instance of IdentityScope with the specified name
|
|---|
| 85 | and IdentityScope.
|
|---|
| 86 |
|
|---|
| 87 | @param name the name to use
|
|---|
| 88 | @param scope the scope to use
|
|---|
| 89 |
|
|---|
| 90 | @throws KeyManagementException if the identity scope is already
|
|---|
| 91 | present
|
|---|
| 92 | */
|
|---|
| 93 | public IdentityScope(String name, IdentityScope scope)
|
|---|
| 94 | throws KeyManagementException
|
|---|
| 95 | {
|
|---|
| 96 | super(name, scope);
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | /**
|
|---|
| 100 | Gets the system's Scope.
|
|---|
| 101 | */
|
|---|
| 102 | public static IdentityScope getSystemScope()
|
|---|
| 103 | {
|
|---|
| 104 | if (systemScope == null)
|
|---|
| 105 | {
|
|---|
| 106 | //Load it
|
|---|
| 107 | //systemScope;
|
|---|
| 108 | }
|
|---|
| 109 | return systemScope;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | /**
|
|---|
| 113 | Sets the scope of the system.
|
|---|
| 114 |
|
|---|
| 115 | This class checks the security manager with the call
|
|---|
| 116 | checkSecurityAccess with "setSystemScope".
|
|---|
| 117 |
|
|---|
| 118 | @param scope the new sustem scope
|
|---|
| 119 |
|
|---|
| 120 | @throws SecurityException - if the security manager denies
|
|---|
| 121 | access to "setSystemScope"
|
|---|
| 122 | */
|
|---|
| 123 | protected static void setSystemScope(IdentityScope scope)
|
|---|
| 124 | {
|
|---|
| 125 | SecurityManager sm = System.getSecurityManager();
|
|---|
| 126 | if (sm != null)
|
|---|
| 127 | sm.checkSecurityAccess("setSystemScope");
|
|---|
| 128 |
|
|---|
| 129 | systemScope = scope;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | /**
|
|---|
| 133 | Gets the number of entries within this IdentityScope.
|
|---|
| 134 |
|
|---|
| 135 | @returns the number of entries
|
|---|
| 136 | */
|
|---|
| 137 | public abstract int size();
|
|---|
| 138 |
|
|---|
| 139 | /**
|
|---|
| 140 | Gets the specified Identity within this scope
|
|---|
| 141 | by specified name.
|
|---|
| 142 |
|
|---|
| 143 | @param name name of Identity to get
|
|---|
| 144 |
|
|---|
| 145 | @returns an identity representing the name or null if it
|
|---|
| 146 | cannot be found
|
|---|
| 147 | */
|
|---|
| 148 | public abstract Identity getIdentity(String name);
|
|---|
| 149 |
|
|---|
| 150 | /**
|
|---|
| 151 | Gets the specified Identity within this scope
|
|---|
| 152 | by the specified Principal.
|
|---|
| 153 |
|
|---|
| 154 | @param principal The Principal of the Identity to get
|
|---|
| 155 |
|
|---|
| 156 | @returns an identity representing the principal or null if it
|
|---|
| 157 | cannot be found
|
|---|
| 158 | */
|
|---|
| 159 | public Identity getIdentity(Principal principal)
|
|---|
| 160 | {
|
|---|
| 161 | return getIdentity(principal.getName());
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | /**
|
|---|
| 165 | Gets the specified Identity within this scope
|
|---|
| 166 | by the specified public key.
|
|---|
| 167 |
|
|---|
| 168 | @param key the PublicKey of the Identity to get
|
|---|
| 169 |
|
|---|
| 170 | @returns an identity representing the public key or null if it
|
|---|
| 171 | cannot be found
|
|---|
| 172 | */
|
|---|
| 173 | public abstract Identity getIdentity(PublicKey key);
|
|---|
| 174 |
|
|---|
| 175 | /**
|
|---|
| 176 | Adds an identity to his scope.
|
|---|
| 177 |
|
|---|
| 178 | @param identity the identity to add
|
|---|
| 179 |
|
|---|
| 180 | @throws KeyManagementException if it is an invalid identity,
|
|---|
| 181 | an identity with the same key exists, or another error
|
|---|
| 182 | occurs.
|
|---|
| 183 | */
|
|---|
| 184 | public abstract void addIdentity(Identity identity)
|
|---|
| 185 | throws KeyManagementException;
|
|---|
| 186 |
|
|---|
| 187 | /**
|
|---|
| 188 | Removes an identity to his scope.
|
|---|
| 189 |
|
|---|
| 190 | @param identity the identity to remove
|
|---|
| 191 |
|
|---|
| 192 | @throws KeyManagementException if it is a missing identity,
|
|---|
| 193 | or another error occurs.
|
|---|
| 194 | */
|
|---|
| 195 | public abstract void removeIdentity(Identity identity)
|
|---|
| 196 | throws KeyManagementException;
|
|---|
| 197 |
|
|---|
| 198 | /**
|
|---|
| 199 | Returns an Enumeration of identities.
|
|---|
| 200 |
|
|---|
| 201 | @returns an enumeration of the identities.
|
|---|
| 202 | */
|
|---|
| 203 | public abstract Enumeration identities();
|
|---|
| 204 |
|
|---|
| 205 | /**
|
|---|
| 206 | Returns a string representing this IdentityScope.
|
|---|
| 207 | It includes the name, the scope name, and number of identities.
|
|---|
| 208 |
|
|---|
| 209 | @returns a string representing this IdentityScope.
|
|---|
| 210 | */
|
|---|
| 211 | public String toString()
|
|---|
| 212 | {
|
|---|
| 213 | return (super.getName() + " " + super.getScope().getName()
|
|---|
| 214 | + " " + size());
|
|---|
| 215 | }
|
|---|
| 216 | }
|
|---|