FileDocCategorySizeDatePackage
Identity.javaAPI DocAndroid 1.5 API14296Wed May 06 22:41:06 BST 2009java.security

Identity

public abstract class Identity extends Object implements Serializable, Principal
{@code Identity} represents an identity like a person or a company.
deprecated
The functionality of this class has been replace by {@link Principal}, {@link KeyStore} and the {@code java.security.cert} package.
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private String
name
private PublicKey
publicKey
private String
info
private IdentityScope
scope
private Vector
certificates
Constructors Summary
protected Identity()
Constructs a new instance of {@code Identity}.

since
Android 1.0


                    
      
    
public Identity(String name)
Creates a new instance of {@code Identity} with the specified name.

param
name the name of this {@code Identity}.
since
Android 1.0

        this.name = name;
    
public Identity(String name, IdentityScope scope)
Creates a new instance of {@code Identity} with the specified name and the scope of this {@code Identity}.

param
name the name of this {@code Identity}.
param
scope the {@code IdentityScope} of this {@code Identity}.
throws
KeyManagementException if an {@code Identity} with the same name is already present in the specified scope.
since
Android 1.0

        this(name);
        if (scope != null) {
            scope.addIdentity(this);
            this.scope = scope;
        }
    
Methods Summary
public voidaddCertificate(java.security.Certificate certificate)
Adds a {@code Certificate} to this {@code Identity}.

If a {@code SecurityManager} is installed, code calling this method needs the {@code SecurityPermission} {@code addIdentityCertificate} to be granted, otherwise a {@code SecurityException} will be thrown.

param
certificate the {@code Certificate} to be added to this {@code Identity}.
throws
KeyManagementException if the certificate is not valid.
throws
SecurityException if a {@code SecurityManager} is installed and the caller does not have permission to invoke this method.
since
Android 1.0

        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkSecurityAccess("addIdentityCertificate"); //$NON-NLS-1$
        }
        PublicKey certPK = certificate.getPublicKey();
        if (publicKey != null) {
            if (!checkKeysEqual(publicKey, certPK)) {
                throw new KeyManagementException(Messages.getString("security.13")); //$NON-NLS-1$
            }
        } else {
            publicKey = certPK;
        }
        if (certificates == null) {
            certificates = new Vector<Certificate>();
        }
        certificates.add(certificate);
    
public java.security.Certificate[]certificates()
Returns the certificates for this {@code Identity}. External modifications of the returned array has no impact on this {@code Identity}.

return
the {@code Certificates} for this {@code Identity}
since
Android 1.0

        if (certificates == null) {
            return new Certificate[0];
        }
        Certificate[] ret = new Certificate[certificates.size()];
        certificates.copyInto(ret);
        return ret;
    
private static booleancheckKeysEqual(java.security.PublicKey pk1, java.security.PublicKey pk2)

        // first, they should have the same format
        // second, their encoded form must be the same

        // assert(pk1 != null);
        // assert(pk2 != null);

        String format1 = pk1.getFormat();
        String format2;
        if ((pk2 == null)
                || (((format2 = pk2.getFormat()) != null) ^ (format1 != null))
                || ((format1 != null) && !format1.equals(format2))) {
            return false;
        }

        return Arrays.equals(pk1.getEncoded(), pk2.getEncoded());
    
public final booleanequals(java.lang.Object obj)
Compares the specified object with this {@code Identity} for equality and returns {@code true} if the specified object is equal, {@code false} otherwise. {@code Identity} objects are considered equal, if they have the same name and are in the same scope.

param
obj object to be compared for equality with this {@code Identity}.
return
{@code true} if the specified object is equal to this {@code Identity}, otherwise {@code false}.
since
Android 1.0

        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Identity)) {
            return false;
        }
        Identity i = (Identity) obj;
        if ((name == i.name || (name != null && name.equals(i.name)))
                && (scope == i.scope || (scope != null && scope.equals(i.scope)))) {
            return true;
        }
        return identityEquals(i);
    
public java.lang.StringgetInfo()
Returns the information string of this {@code Identity}.

return
the information string of this {@code Identity}.
since
Android 1.0

        return info;
    
public final java.lang.StringgetName()
Returns the name of this {@code Identity}.

return
the name of this {@code Identity}.
since
Android 1.0

        return name;
    
public java.security.PublicKeygetPublicKey()
Returns the {@code PublicKey} associated with this {@code Identity}.

return
the {@code PublicKey} associated with this {@code Identity}.
since
Android 1.0

        return publicKey;
    
public final java.security.IdentityScopegetScope()
Returns the {@code IdentityScope} of this {@code Identity}.

return
the {@code IdentityScope} of this {@code Identity}.
since
Android 1.0

        return scope;
    
public inthashCode()
Returns the hash code value for this {@code Identity}. Returns the same hash code for {@code Identity}s that are equal to each other as required by the general contract of {@link Object#hashCode}.

return
the hash code value for this {@code Identity}.
see
Object#equals(Object)
see
Identity#equals(Object)
since
Android 1.0

        int hash = 0;
        if (name != null) {
            hash += name.hashCode();
        }
        if (scope != null) {
            hash += scope.hashCode();
        }
        return hash;
    
protected booleanidentityEquals(java.security.Identity identity)
Compares the specified {@code Identity} with this {@code Identity} for equality and returns {@code true} if the specified object is equal, {@code false} otherwise.

To be equal, two {@code Identity} objects need to have the same name and the same public keys.

param
identity the identity to check for equality.
return
{@code true} if the {@code Identity} objects are equal, {@code false} otherwise.
since
Android 1.0

        if (!name.equals(identity.name)) {
            return false;
        }

        if (publicKey == null) {
            return (identity.publicKey == null);
        }

        return checkKeysEqual(publicKey, identity.publicKey);
    
public voidremoveCertificate(java.security.Certificate certificate)
Removes the specified {@code Certificate} from this {@code Identity}.

If a {@code SecurityManager} is installed, code calling this method needs the {@code SecurityPermission} {@code "removeIdentityCertificate"} to be granted, otherwise a {@code SecurityException} will be thrown.

param
certificate the {@code Certificate} to be removed.
throws
KeyManagementException if the certificate is not found.
throws
SecurityException if a {@code SecurityManager} is installed and the caller does not have permission to invoke this method.
since
Android 1.0

        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkSecurityAccess("removeIdentityCertificate"); //$NON-NLS-1$
        }
        if (certificates != null) {
            // BEGIN android-added
            if (!certificates.contains(certificate)) {
                throw new KeyManagementException("Certificate not found");
            }
            // END android-added
            certificates.removeElement(certificate);
        }
    
public voidsetInfo(java.lang.String info)
Sets an information string for this {@code Identity}.

If a {@code SecurityManager} is installed, code calling this method needs the {@code SecurityPermission} {@code setIdentityInfo} to be granted, otherwise a {@code SecurityException} will be thrown.

param
info the information to be set.
throws
SecurityException if a {@code SecurityManager} is installed and the caller does not have permission to invoke this method.
since
Android 1.0

        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkSecurityAccess("setIdentityInfo"); //$NON-NLS-1$
        }
        this.info = info;
    
public voidsetPublicKey(java.security.PublicKey key)
Sets the specified {@code PublicKey} to this {@code Identity}.

If a {@code SecurityManager} is installed, code calling this method needs the {@code SecurityPermission} {@code setIdentityPublicKey} to be granted, otherwise a {@code SecurityException} will be thrown.

param
key the {@code PublicKey} to be set.
throws
KeyManagementException if another {@code Identity} in the same scope as this {@code Identity} already has the same {@code PublicKey}.
throws
SecurityException if a {@code SecurityManager} is installed and the caller does not have permission to invoke this method.
since
Android 1.0

        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkSecurityAccess("setIdentityPublicKey"); //$NON-NLS-1$
        }
        // this check does not always work  
        if ((scope != null) && (key != null)) {
            Identity i = scope.getIdentity(key);
            //System.out.println("###DEBUG## Identity: "+i);
            if ((i != null) && (i != this)) {
                throw new KeyManagementException(Messages.getString("security.14")); //$NON-NLS-1$
            }
        }
        this.publicKey = key;
        certificates = null;
    
public java.lang.StringtoString()
Returns a string containing a concise, human-readable description of the this {@code Identity} including its name and its scope.

If a {@code SecurityManager} is installed, code calling this method needs the {@code SecurityPermission} {@code printIdentity} to be granted, otherwise a {@code SecurityException} will be thrown.

return
a printable representation for this {@code Identity}.
throws
SecurityException if a {@code SecurityManager} is installed and the caller does not have permission to invoke this method.
since
Android 1.0

        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkSecurityAccess("printIdentity"); //$NON-NLS-1$
        }
        String s = (this.name == null? "" : this.name);
        if (scope != null) {
            s += " [" + scope.getName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
        }
        return s;
    
public java.lang.StringtoString(boolean detailed)
Returns a string containing a concise, human-readable description of the this {@code Identity}.

param
detailed whether or not this method should return detailed information.
return
a printable representation for this {@code Permission}.
since
Android 1.0

        String s = toString();
        if (detailed) {
            s += " " + info; //$NON-NLS-1$
        }
        return s;