/[classpath]/classpath/java/security/Identity.java
ViewVC logotype

Diff of /classpath/java/security/Identity.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by mkoch, Wed Oct 2 12:58:40 2002 UTC revision 1.6 by raif, Sat Mar 8 14:10:12 2003 UTC
# Line 1  Line 1 
1  /* Identity.java --- Identity Class  /* Identity.java --- Identity Class
2     Copyright (C) 1999 Free Software Foundation, Inc.     Copyright (C) 1999, 2003, Free Software Foundation, Inc.
3    
4     This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
6  GNU Classpath is free software; you can redistribute it and/or modify  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  it under the terms of the GNU General Public License as published by
# Line 36  obligated to do so.  If you do not wish Line 36  obligated to do so.  If you do not wish
36  exception statement from your version. */  exception statement from your version. */
37    
38  package java.security;  package java.security;
39    
40  import java.io.Serializable;  import java.io.Serializable;
41  import java.util.Vector;  import java.util.Vector;
42    
43  /**  /**
44     The Identity class is used to repsent people and companies that   * <p>This class represents identities: real-world objects such as people,
45     can be authenticated using public key encryption. The identities   * companies or organizations whose identities can be authenticated using their
46     can also be abstract objects such as smart cards.   * public keys. Identities may also be more abstract (or concrete) constructs,
47     * such as daemon threads or smart cards.</p>
48     Identity object store a name and public key for each identity.   *
49     The names cannot be changed and the identities can be scoped.   * <p>All Identity objects have a <i>name</i> and a <i>public key</i>. Names
50     Each identity (name and public key) within a scope is unique   * are immutable. <i>Identities</i> may also be <b>scoped</b>. That is, if an
51     to that scope.   * <i>Identity</i> is specified to have a particular <i>scope</i>, then the
52     * <i>name</i> and <i>public key</i> of the <i>Identity</i> are unique within
53     Each identity has a set of ceritificates which all specify the   * that <i>scope</i>.</p>
54     same public key but not necessarily the same name.   *
55     * <p>An <i>Identity</i> also has a <i>set of certificates</i> (all certifying
56     The Identity class can be subclassed to allow additional   * its own <i>public key</i>). The <i>Principal</i> names specified in these
57     information to be attached to it.   * certificates need not be the same, only the key.</p>
58     *
59     @since JDK 1.1   * <p>An <i>Identity</i> can be subclassed, to include postal and email
60     * addresses, telephone numbers, images of faces and logos, and so on.</p>
61     @deprecated Use java.security.KeyStore, the java.security.cert   *
62     package, and java.security.Principal.   * @author Mark Benvenuto
63     * @see IdentityScope
64     @author Mark Benvenuto         * @see Signer
65     * @see Principal
66     * @deprecated This class is no longer used. Its functionality has been replaced
67     * by <code>java.security.KeyStore</code>, the <code>java.security.cert</code>
68     * package, and <code>java.security.Principal</code>.
69   */   */
70  public abstract class Identity implements Principal, Serializable  public abstract class Identity implements Principal, Serializable
71  {  {
# Line 72  public abstract class Identity implement Line 77  public abstract class Identity implement
77    private String info;    private String info;
78    private Vector certificates;    private Vector certificates;
79    
80    /**    /** Constructor for serialization only. */
      Creates a new instance of Identity from Serialized Data  
    */  
81    protected Identity()    protected Identity()
82    {    {
83    }    }
84    
85    /**    /**
86       Creates a new instance of Identity with the specified name     * Constructs an identity with the specified name and scope.
87       and IdentityScope.     *
88       * @param name the identity name.
89       @param name the name to use     * @param scope the scope of the identity.
90       @param scope the scope to use     * @throws KeyManagementException if there is already an identity with the
91       * same name in the scope.
      @throws KeyManagementException if the identity is already  
      present  
92     */     */
93    public Identity(String name, IdentityScope scope)    public Identity(String name, IdentityScope scope)
94      throws KeyManagementException      throws KeyManagementException
# Line 97  public abstract class Identity implement Line 98  public abstract class Identity implement
98    }    }
99    
100    /**    /**
101       Creates a new instance of Identity with the specified name     * Constructs an identity with the specified name and no scope.
102       and no scope.     *
103       * @param name the identity name.
      @param name the name to use  
104     */     */
105    public Identity(String name)    public Identity(String name)
106    {    {
# Line 109  public abstract class Identity implement Line 109  public abstract class Identity implement
109    }    }
110    
111    /**    /**
112       Gets the name for this Identity.     * Returns this identity's name.
113       *
114       @return the name     * @return the name of this identity.
115     */     */
116    public final String getName()    public final String getName()
117    {    {
# Line 119  public abstract class Identity implement Line 119  public abstract class Identity implement
119    }    }
120    
121    /**    /**
122       Gets the scope for this Identity.     * Returns this identity's scope.
123       *
124       @return the scope     * @return the scope of this identity.
125     */     */
126    public final IdentityScope getScope()    public final IdentityScope getScope()
127    {    {
# Line 129  public abstract class Identity implement Line 129  public abstract class Identity implement
129    }    }
130    
131    /**    /**
132       Gets the public key for this identity.     * Returns this identity's public key.
133       *
134       @return the public key     * @return the public key for this identity.
135       * @see #setPublicKey(java.security.PublicKey)
136     */     */
137    public PublicKey getPublicKey()    public PublicKey getPublicKey()
138    {    {
# Line 139  public abstract class Identity implement Line 140  public abstract class Identity implement
140    }    }
141    
142    /**    /**
143       Sets the public key for this identity.     * <p>Sets this identity's public key. The old key and all of this identity's
144       The old key and all certificates are removed.     * certificates are removed by this operation.</p>
145       *
146       This class checks the security manager with the call     * <p>First, if there is a security manager, its <code>checkSecurityAccess()
147       checkSecurityAccess with "setIdentityPublicKey".     * </code> method is called with <code>"setIdentityPublicKey"</code> as its
148       * argument to see if it's ok to set the public key.</p>
149       @param key the public key to use     *
150       * @param key the public key for this identity.
151       @throws KeyManagementException if this public key is used by     * @throws KeyManagementException if another identity in the identity's scope
152       another identity in the current scope.     * has the same public key, or if another exception occurs.
153       @throws SecurityException - if the security manager denies     * @throws SecurityException if a security manager exists and its
154       access to "setIdentityPublicKey"     * <code>checkSecurityAccess()<code> method doesn't allow setting the public
155       * key.
156       * @see #getPublicKey()
157       * @see SecurityManager#checkSecurityAccess(String)
158     */     */
159    public void setPublicKey(PublicKey key) throws KeyManagementException    public void setPublicKey(PublicKey key) throws KeyManagementException
160    {    {
# Line 162  public abstract class Identity implement Line 166  public abstract class Identity implement
166    }    }
167    
168    /**    /**
169       Sets the general information string.     * <p>Specifies a general information string for this identity.</p>
170       *
171       This class checks the security manager with the call     * <p>First, if there is a security manager, its <code>checkSecurityAccess()
172       checkSecurityAccess with "setIdentityInfo".     * </code> method is called with <code>"setIdentityInfo"</code> as its
173       * argument to see if it's ok to specify the information string.</p>
174       @param info the general information string.     *
175       * @param info the information string.
176       @throws SecurityException - if the security manager denies     * @throws SecurityException if a security manager exists and its
177       access to "setIdentityInfo"     * <code>checkSecurityAccess()</code> method doesn't allow setting the
178       * information string.
179       * @see #getInfo()
180       * @see SecurityManager#checkSecurityAccess(String)
181     */     */
182    public void setInfo(String info)    public void setInfo(String info)
183    {    {
# Line 182  public abstract class Identity implement Line 189  public abstract class Identity implement
189    }    }
190    
191    /**    /**
192       Gets the general information string.     * Returns general information previously specified for this identity.
193       *
194       @return the string     * @return general information about this identity.
195       * @see #setInfo(String)
196     */     */
197    public String getInfo()    public String getInfo()
198    {    {
# Line 192  public abstract class Identity implement Line 200  public abstract class Identity implement
200    }    }
201    
202    /**    /**
203       Adds a certificate to the list of ceritificates for this     * <p>Adds a certificate for this identity. If the identity has a public key,
204       identity. The public key in this certificate must match the     * the public key in the certificate must be the same, and if the identity
205       existing public key if it exists.     * does not have a public key, the identity's public key is set to be that
206       * specified in the certificate.</p>
207       This class checks the security manager with the call     *
208       checkSecurityAccess with "addIdentityCertificate".     * <p>First, if there is a security manager, its <code>checkSecurityAccess()
209       * </code> method is called with <code>"addIdentityCertificate"</code> as its
210       @param certificate the certificate to add     * argument to see if it's ok to add a certificate.</p>
211       *
212       @throws KeyManagementException if the certificate is invalid     * @param certificate the certificate to be added.
213       or the public key conflicts     * @throws KeyManagementException if the certificate is not valid, if the
214       @throws SecurityException - if the security manager denies     * public key in the certificate being added conflicts with this identity's
215       access to "addIdentityCertificate"     * public key, or if another exception occurs.
216       * @throws SecurityException if a security manager exists and its
217       * <code>checkSecurityAccess()</code> method doesn't allow adding a
218       * certificate.
219       * @see SecurityManager#checkSecurityAccess(String)
220     */     */
221    public void addCertificate(java.security.Certificate certificate)    public void addCertificate(Certificate certificate)
222      throws KeyManagementException      throws KeyManagementException
223    {    {
224      SecurityManager sm = System.getSecurityManager();      SecurityManager sm = System.getSecurityManager();
225      if (sm != null)      if (sm != null)
226        sm.checkSecurityAccess("addIdentityCertificate");        sm.checkSecurityAccess("addIdentityCertificate");
227    
228      //Check public key of this certificate against the first one      // Check public key of this certificate against the first one in the vector
     //in the vector  
229      if (certificates.size() > 0)      if (certificates.size() > 0)
230        {        {
231          if (((Certificate) certificates.firstElement()).getPublicKey() !=          if (((Certificate) certificates.firstElement()).getPublicKey() != publicKey)
             publicKey)  
232            throw new KeyManagementException("Public key does not match");            throw new KeyManagementException("Public key does not match");
233        }        }
234      certificates.addElement(certificate);      certificates.addElement(certificate);
235    }    }
236    
237    /**    /**
238       Removes a certificate from the list of ceritificates for this     * <p>Removes a certificate from this identity.</p>
239       identity.     *
240       * <p>First, if there is a security manager, its <code>checkSecurityAccess()
241       This class checks the security manager with the call     * </code> method is called with <code>"removeIdentityCertificate"</code> as
242       checkSecurityAccess with "removeIdentityCertificate".     * its argument to see if it's ok to remove a certificate.</p>
243       *
244       @param certificate the certificate to add     * @param certificate the certificate to be removed.
245       * @throws KeyManagementException if the certificate is missing, or if
246       @throws KeyManagementException if the certificate is invalid     * another exception occurs.
247       @throws SecurityException - if the security manager denies     * @throws SecurityException if a security manager exists and its
248       access to "removeIdentityCertificate"     * <code>checkSecurityAccess()</code> method doesn't allow removing a
249       * certificate.
250       * @see SecurityManager#checkSecurityAccess(String)
251     */     */
252    public void removeCertificate(Certificate certificate)    public void removeCertificate(Certificate certificate)
253      throws KeyManagementException      throws KeyManagementException
# Line 251  public abstract class Identity implement Line 263  public abstract class Identity implement
263    }    }
264    
265    /**    /**
266       Returns an array of certificates for this identity.     * Returns a copy of all the certificates for this identity.
267       *
268       @returns array of certificates     * @return a copy of all the certificates for this identity.
269     */     */
270    public Certificate[] certificates()    public Certificate[] certificates()
271    {    {
# Line 261  public abstract class Identity implement Line 273  public abstract class Identity implement
273      int max = certificates.size();      int max = certificates.size();
274      for (int i = 0; i < max; i++)      for (int i = 0; i < max; i++)
275        certs[i] = (Certificate) certificates.elementAt(i);        certs[i] = (Certificate) certificates.elementAt(i);
276    
277      return certs;      return certs;
278    }    }
279    
280    /**    /**
281       Checks for equality between this Identity and the specified     * Tests for equality between the specified object and this identity. This
282       object. If first checks if they are the same object, then     * first tests to see if the entities actually refer to the same object, in
283       if the name and scope matches and returns true if successful.     * which case it returns <code>true</code>. Next, it checks to see if the
284       If these tests fail, identityEquals is called.     * entities have the same <i>name</i> and the same <i>scope</i>. If they do,
285       * the method returns <code>true</code>. Otherwise, it calls
286       @return true if they are equal, false otherwise     * <code>identityEquals()</code>, which subclasses should override.
287       *
288       * @param identity the object to test for equality with this identity.
289       * @return <code>true</code> if the objects are considered equal, <code>false
290       * </code>otherwise.
291       * @see #identityEquals(Identity)
292     */     */
293    public final boolean equals(Object identity)    public final boolean equals(Object identity)
294    {    {
# Line 289  public abstract class Identity implement Line 307  public abstract class Identity implement
307    }    }
308    
309    /**    /**
310       Checks for equality between this Identity and the specified     * Tests for equality between the specified <code>identity</code> and this
311       object. A subclass should override this method. The default     * <i>identity</i>. This method should be overriden by subclasses to test for
312       behavior is to return true if the public key and names match.     * equality. The default behavior is to return <code>true</code> if the names
313       * and public keys are equal.
314       @return true if they are equal, false otherwise     *
315       * @param identity the identity to test for equality with this identity.
316       * @return <code>true</code> if the identities are considered equal,
317       * <code>false</code> otherwise.
318       * @see #equals(Object)
319     */     */
320    protected boolean identityEquals(Identity identity)    protected boolean identityEquals(Identity identity)
321    {    {
# Line 302  public abstract class Identity implement Line 324  public abstract class Identity implement
324    }    }
325    
326    /**    /**
327       Returns a string representing this Identity.     * <p>Returns a short string describing this identity, telling its name and
328       * its scope (if any).</p>
329       This class checks the security manager with the call     *
330       checkSecurityAccess with "printIdentity".     * <p>First, if there is a security manager, its <code>checkSecurityAccess()
331       * </code> method is called with <code>"printIdentity"</code> as its argument
332       @returns a string representing this Identity.     * to see if it's ok to return the string.</p>
333       *
334       @throws SecurityException - if the security manager denies     * @return information about this identity, such as its name and the name of
335       access to "printIdentity"     * its scope (if any).
336       * @throws SecurityException if a security manager exists and its
337       * <code>checkSecurityAccess()</code> method doesn't allow returning a string
338       * describing this identity.
339       * @see SecurityManager#checkSecurityAccess(String)
340     */     */
341    public String toString()    public String toString()
342    {    {
# Line 323  public abstract class Identity implement Line 349  public abstract class Identity implement
349    }    }
350    
351    /**    /**
352       Returns a detailed string representing this Identity.     * <p>Returns a string representation of this identity, with optionally more
353       * details than that provided by the <code>toString()</code> method without
354       This class checks the security manager with the call     * any arguments.</p>
355       checkSecurityAccess with "printIdentity".     *
356       * <p>First, if there is a security manager, its <code>checkSecurityAccess()
357       @param detailed indicates whether or not to provide detailed     * </code> method is called with <code>"printIdentity"</code> as its argument
358       information     * to see if it's ok to return the string.</p>
359       *
360       @returns a string representing this Identity.     * @param detailed whether or not to provide detailed information.
361       * @return information about this identity. If detailed is <code>true</code>,
362       @throws SecurityException - if the security manager denies     * then this method returns more information than that provided by the
363       access to "printIdentity"     * <code>toString()</code> method without any arguments.
364       * @throws SecurityException if a security manager exists and its
365       * <code>checkSecurityAccess()</code> method doesn't allow returning a string
366       * describing this identity.
367       * @see #toString()
368       * @see SecurityManager#checkSecurityAccess(String)
369     */     */
370    public String toString(boolean detailed)    public String toString(boolean detailed)
371    {    {
# Line 355  public abstract class Identity implement Line 386  public abstract class Identity implement
386    }    }
387    
388    /**    /**
389       Gets the hashcode for this Identity.     * Returns a hashcode for this identity.
390       *
391       @returns the hashcode     * @return a hashcode for this identity.
392     */     */
393    public int hashCode()    public int hashCode()
394    {    {

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26