001 /* IdentityScope.java --- IdentityScope Class 002 Copyright (C) 1999, 2003, Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 package java.security; 039 040 import java.util.Enumeration; 041 042 /** 043 * <code>IdentityScope</code> represents a scope of an identity. 044 * <code>IdentityScope</code> is also an {@link Identity} and can have a name 045 * and scope along with the other qualitites identities possess. 046 * 047 * <p>An <code>IdentityScope</code> contains other {@link Identity} objects. 048 * All {@link Identity} objects are manipulated in the scope the same way. The 049 * scope is supposed to apply different scope to different type of 050 * Identities.</p> 051 * 052 * <p>No identity within the same scope can have the same public key.</p> 053 * 054 * @author Mark Benvenuto 055 * @see Identity 056 * @see Signer 057 * @see Principal 058 * @see Key 059 * @deprecated Use java.security.KeyStore, the java.security.cert package, and 060 * java.security.Principal. 061 */ 062 public abstract class IdentityScope extends Identity 063 { 064 private static final long serialVersionUID = -2337346281189773310L; 065 private static IdentityScope systemScope; 066 067 /** Constructor for serialization purposes. */ 068 protected IdentityScope() 069 { 070 super(); 071 } 072 073 /** 074 * Constructs a new instance of <code>IdentityScope</code> with the 075 * specified name and no scope. 076 * 077 * @param name 078 * the name to use. 079 */ 080 public IdentityScope(String name) 081 { 082 super(name); 083 } 084 085 /** 086 * Constructs a new instance of <code>IdentityScope</code> with the 087 * specified name and {@link IdentityScope}. 088 * 089 * @param name 090 * the name to use. 091 * @param scope 092 * the scope to use. 093 * @throws KeyManagementException 094 * if the identity scope is already present. 095 */ 096 public IdentityScope(String name, IdentityScope scope) 097 throws KeyManagementException 098 { 099 super(name, scope); 100 } 101 102 /** 103 * Returns the system's Scope. 104 * 105 * @return the system's Scope. 106 */ 107 public static IdentityScope getSystemScope() 108 { 109 if (systemScope == null) 110 { 111 //Load it 112 //systemScope; 113 } 114 return systemScope; 115 } 116 117 /** 118 * Sets the scope of the system. 119 * 120 * @param scope 121 * the new system scope. 122 * @throws SecurityException 123 * if a {@link SecurityManager} is installed which disallows this 124 * operation. 125 */ 126 protected static void setSystemScope(IdentityScope scope) 127 { 128 SecurityManager sm = System.getSecurityManager(); 129 if (sm != null) 130 sm.checkSecurityAccess("setSystemScope"); 131 132 systemScope = scope; 133 } 134 135 /** 136 * Returns the number of entries within this <code>IdentityScope</code>. 137 * 138 * @return the number of entries within this <code>IdentityScope</code>. 139 */ 140 public abstract int size(); 141 142 /** 143 * Returns the specified {@link Identity}, by name, within this scope. 144 * 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. 149 */ 150 public abstract Identity getIdentity(String name); 151 152 /** 153 * Returns the specified {@link Identity}, by {@link Principal}, within this 154 * scope. 155 * 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. 160 */ 161 public Identity getIdentity(Principal principal) 162 { 163 return getIdentity(principal.getName()); 164 } 165 166 /** 167 * Returns the specified {@link Identity}, by public key, within this scope. 168 * 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. 173 */ 174 public abstract Identity getIdentity(PublicKey key); 175 176 /** 177 * Adds an identity to his scope. 178 * 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. 184 */ 185 public abstract void addIdentity(Identity identity) 186 throws KeyManagementException; 187 188 /** 189 * Removes an identity in this scope. 190 * 191 * @param identity 192 * the {@link Identity} to remove. 193 * @throws KeyManagementException 194 * if it is a missing identity, or if another error occurs. 195 */ 196 public abstract void removeIdentity(Identity identity) 197 throws KeyManagementException; 198 199 /** 200 * Returns an {@link Enumeration} of identities in this scope. 201 * 202 * @return an {@link Enumeration} of the identities in this scope. 203 */ 204 public abstract Enumeration<Identity> identities(); 205 206 /** 207 * Returns a string representing this instance. It includes the name, the 208 * scope name, and number of identities. 209 * 210 * @return a string representation of this instance. 211 */ 212 public String toString() 213 { 214 return (super.getName() + " " + super.getScope().getName() + " " + size()); 215 } 216 }