Source for java.security.IdentityScope

   1: /* IdentityScope.java --- IdentityScope Class
   2:    Copyright (C) 1999, 2003, 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., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 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: 
  40: import java.util.Enumeration;
  41: 
  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.
  46:  * 
  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>
  51:  * 
  52:  * <p>No identity within the same scope can have the same public key.</p>
  53:  * 
  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.
  61:  */
  62: public abstract class IdentityScope extends Identity
  63: {
  64:   private static final long serialVersionUID = -2337346281189773310L;
  65:   private static IdentityScope systemScope;
  66: 
  67:   /** Constructor for serialization purposes. */
  68:   protected IdentityScope()
  69:   {
  70:     super();
  71:   }
  72: 
  73:   /**
  74:    * Constructs a new instance of <code>IdentityScope</code> with the
  75:    * specified name and no scope.
  76:    * 
  77:    * @param name
  78:    *          the name to use.
  79:    */
  80:   public IdentityScope(String name)
  81:   {
  82:     super(name);
  83:   }
  84: 
  85:   /**
  86:    * Constructs a new instance of <code>IdentityScope</code> with the
  87:    * specified name and {@link IdentityScope}.
  88:    * 
  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.
  95:    */
  96:   public IdentityScope(String name, IdentityScope scope)
  97:     throws KeyManagementException
  98:   {
  99:     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: }