Methods Summary |
---|
public void | addCertificate(java.security.Certificate certificate)Adds a certificate for this identity. If the identity has a public
key, the public key in the certificate must be the same, and if
the identity does not have a public key, the identity's
public key is set to be that specified in the certificate.
First, if there is a security manager, its checkSecurityAccess
method is called with "addIdentityCertificate"
as its argument to see if it's ok to add a certificate.
check("addIdentityCertificate");
if (certificates == null) {
certificates = new Vector();
}
if (publicKey != null) {
if (!keyEquals(publicKey, certificate.getPublicKey())) {
throw new KeyManagementException(
"public key different from cert public key");
}
} else {
publicKey = certificate.getPublicKey();
}
certificates.addElement(certificate);
|
public java.security.Certificate[] | certificates()Returns a copy of all the certificates for this identity.
if (certificates == null) {
return new Certificate[0];
}
int len = certificates.size();
Certificate[] certs = new Certificate[len];
certificates.copyInto(certs);
return certs;
|
private static void | check(java.lang.String directive)
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkSecurityAccess(directive);
}
|
public final boolean | equals(java.lang.Object identity)Tests for equality between the specified object and this identity.
This first tests to see if the entities actually refer to the same
object, in which case it returns true. Next, it checks to see if
the entities have the same name and the same scope. If they do,
the method returns true. Otherwise, it calls
{@link #identityEquals(Identity) identityEquals}, which subclasses should
override.
if (identity == this) {
return true;
}
if (identity instanceof Identity) {
Identity i = (Identity)identity;
if (this.fullName().equals(i.fullName())) {
return true;
} else {
return identityEquals(i);
}
}
return false;
|
java.lang.String | fullName()Returns a parsable name for identity: identityName.scopeName
String parsable = name;
if (scope != null) {
parsable += "." + scope.getName();
}
return parsable;
|
public java.lang.String | getInfo()Returns general information previously specified for this identity.
return info;
|
public final java.lang.String | getName()Returns this identity's name.
return name;
|
public java.security.PublicKey | getPublicKey()Returns this identity's public key.
return publicKey;
|
public final java.security.IdentityScope | getScope()Returns this identity's scope.
return scope;
|
public int | hashCode()Returns a hashcode for this identity.
return name.hashCode();
|
protected boolean | identityEquals(java.security.Identity identity)Tests for equality between the specified identity and this identity.
This method should be overriden by subclasses to test for equality.
The default behavior is to return true if the names and public keys
are equal.
if (!name.equalsIgnoreCase(identity.name))
return false;
if ((publicKey == null) ^ (identity.publicKey == null))
return false;
if (publicKey != null && identity.publicKey != null)
if (!publicKey.equals(identity.publicKey))
return false;
return true;
|
private boolean | keyEquals(java.security.Key aKey, java.security.Key anotherKey)
String aKeyFormat = aKey.getFormat();
String anotherKeyFormat = anotherKey.getFormat();
if ((aKeyFormat == null) ^ (anotherKeyFormat == null))
return false;
if (aKeyFormat != null && anotherKeyFormat != null)
if (!aKeyFormat.equalsIgnoreCase(anotherKeyFormat))
return false;
return java.util.Arrays.equals(aKey.getEncoded(),
anotherKey.getEncoded());
|
java.lang.String | printCertificates()
String out = "";
if (certificates == null) {
return "\tno certificates";
} else {
out += "\tcertificates: \n";
Enumeration e = certificates.elements();
int i = 1;
while (e.hasMoreElements()) {
Certificate cert = (Certificate)e.nextElement();
out += "\tcertificate " + i++ +
"\tfor : " + cert.getPrincipal() + "\n";
out += "\t\t\tfrom : " +
cert.getGuarantor() + "\n";
}
}
return out;
|
java.lang.String | printKeys()
String key = "";
if (publicKey != null) {
key = "\tpublic key initialized";
} else {
key = "\tno public key";
}
return key;
|
public void | removeCertificate(java.security.Certificate certificate)Removes a certificate from this identity.
First, if there is a security manager, its checkSecurityAccess
method is called with "removeIdentityCertificate"
as its argument to see if it's ok to remove a certificate.
check("removeIdentityCertificate");
if (certificates != null) {
certificates.removeElement(certificate);
}
|
public void | setInfo(java.lang.String info)Specifies a general information string for this identity.
First, if there is a security manager, its checkSecurityAccess
method is called with "setIdentityInfo"
as its argument to see if it's ok to specify the information string.
check("setIdentityInfo");
this.info = info;
|
public void | setPublicKey(java.security.PublicKey key)Sets this identity's public key. The old key and all of this
identity's certificates are removed by this operation.
First, if there is a security manager, its checkSecurityAccess
method is called with "setIdentityPublicKey"
as its argument to see if it's ok to set the public key.
check("setIdentityPublicKey");
this.publicKey = key;
certificates = new Vector();
|
public java.lang.String | toString()Returns a short string describing this identity, telling its
name and its scope (if any).
First, if there is a security manager, its checkSecurityAccess
method is called with "printIdentity"
as its argument to see if it's ok to return the string.
check("printIdentity");
String printable = name;
if (scope != null) {
printable += "[" + scope.getName() + "]";
}
return printable;
|
public java.lang.String | toString(boolean detailed)Returns a string representation of this identity, with
optionally more details than that provided by the
toString method without any arguments.
First, if there is a security manager, its checkSecurityAccess
method is called with "printIdentity"
as its argument to see if it's ok to return the string.
String out = toString();
if (detailed) {
out += "\n";
out += printKeys();
out += "\n" + printCertificates();
if (info != null) {
out += "\n\t" + info;
} else {
out += "\n\tno additional information available.";
}
}
return out;
|