public class Name extends java.lang.Object implements java.security.Principal, ASN1Type
Name ::= SEQUENCE OF RelativeDistinguishedName
A Name object may be used for specifying, e.g. issuer and
subject within a X.509 certificate. For creating a Name
structure, use a proper constructor. You later may supply the
relative distinguished names constituting your actual Name
object by repeatedly calling the addRDN
method, e.g.:
This class also allows to add more than one RDN of the same attribute type.Name subject = new Name(); subject.addRDN(ObjectID.country, "AT"); subject.addRDN(ObjectID.locality, "Graz"); subject.addRDN(ObjectID.organization ,"TU Graz"); subject.addRDN(ObjectID.organizationalUnit ,"IAIK"); subject.addRDN(ObjectID.commonName ,"TestUser");
| Constructor and Description |
|---|
Name()
The default constructor.
|
Name(ASN1Object obj)
Constructs a Name from an ASN1Object.
|
Name(byte[] name)
Creates a name from a DER encoded byte array.
|
Name(java.lang.String name)
Deprecated.
This class should not be used as it does not handle RDN's
separated by comma's correctly. Instead, the Java toolkit's
RFC2253NameParser class should be used to construct
a Name object from a String. Alternatively the JDK X500Principal can be
used for parsing an X.500 Name. |
| Modifier and Type | Method and Description |
|---|---|
void |
addRDN(ObjectID oid,
java.lang.Object value)
Adds a RelativeDistinguishedName with given attribute type and value to this Name.
|
void |
addRDN(RDN rdn)
Adds a RelativeDistinguishedName to this Name.
|
java.lang.Object |
clone()
Returns a clone of the
Name. |
void |
decode(ASN1Object obj)
Decodes a Name from the given ASN1Object.
|
java.util.Enumeration |
elements()
Returns an enumeration of all RDNs included in this Name.
|
boolean |
equals(java.lang.Object obj)
Compares this Name to the specified object.
|
java.lang.String |
getComparableString()
Returns a string that represents the contents of this Name, according to
the name comparison rules in RFC 2459/3280.
|
java.lang.String |
getComparableString(boolean sort)
Returns a string that represents the contents of this Name, according to
the name comparison rules in RFC 2459/3280.
|
byte[] |
getEncoded()
Returns this Name as DER encoded byte array.
|
java.lang.String |
getName()
Returns a string that represents this Name.
|
java.lang.String |
getRDN(ObjectID oid)
Returns the RDN value assigned to a given ObjectID.
|
java.lang.String[] |
getRDNs(ObjectID oid)
Returns the values of all RDNs assigned to a given ObjectID.
|
java.lang.Object |
getRDNValue(ObjectID oid)
Returns the RDN value assigned to a given ObjectID.
|
java.lang.Object[] |
getRDNValues(ObjectID oid)
Returns the values of all RDNs assigned to a given ObjectID.
|
java.lang.String |
getRFC2253String()
Returns a string representation of this Name according to RFC 2253.
|
java.lang.String |
getRFC2253String(boolean escapeNonPrintableAscii)
Returns a RFC 2253 representation of the Name.
|
int |
hashCode()
Returns a hashcode for this Name based on the use of
getComparableString()
|
int |
hashCode(boolean sort)
Returns a hashcode for this Name based on the use of
getComparableString(boolean sort)
|
boolean |
isEmpty()
Checks if there are any RDNs included in this Name.
|
boolean |
removeRDN(ObjectID oid)
Removes all RelativeDistinguishedNames with the given attribute type (oid)
from this Name.
|
int |
size()
Returns the number of RDNs included in this Name.
|
ASN1Object |
toASN1Object()
Returns this Name as ASN1Object.
|
java.lang.String |
toString()
Returns a string that represents this Name.
|
java.lang.String |
toString(boolean detailed)
Returns a string that represents this Name.
|
public Name()
public Name(byte[] name)
throws CodingException
name - a DER encoded NameCodingExceptionpublic Name(ASN1Object obj) throws CodingException
obj - the Name as ASN1ObjectCodingException - if the ASN1Object has the wrong formatpublic Name(java.lang.String name)
RFC2253NameParser class should be used to construct
a Name object from a String. Alternatively the JDK X500Principal can be
used for parsing an X.500 Name.toString() method.name - The Name as a String.RFC2253NameParser,
X500Principalpublic void decode(ASN1Object obj) throws CodingException
decode in interface ASN1Typeobj - the Name as ASN1ObjectCodingException - if the ASN1Object has the wrong formatpublic java.lang.String getRDN(ObjectID oid)
null is returned.
Attention! This method only may be used for querying for a String RDN value.
If you expect a non-string value (e.g. when searching for a uniqueIdentifier), use
method getRDNValue which returns the value as
Java object.
oid - the ObjectID of the RDN (attribute) type to be searched fornull if no RDN of the requested type (oid) is
includedpublic java.lang.String[] getRDNs(ObjectID oid)
Some CAs support certificates where the subject name may have multiple RDNs
of same attribute type (ObjectID), e.g. two organizationalUnit entries.
More than one RDN of same attribute type may be added to a Name
structure by repeatedly calling the addRDN
method with the same objectID (attribute type), e.g.:
name.addRDN(ObjectID.organizationalUnit,"..."); name.addRDN(ObjectID.organizationalUnit,"..."); ...When calling this
getRDNs method, all the inherent RDN objects
are searched for the given objectID (attribute type). Any detected value
contributes to a String array returning the values of all included RDN
objects with the requested attribute type (oid).
If no RDN with such an ObjectID (attribute type) is included, null
is returned.
Attention! This method only may be used for querying for String RDN values.
If you expect non-string values (e.g. when searching for a uniqueIdentifier), use
method getRDNValues which returns the values as
an array of Java objects.
oid - the ObjectID of the RDN (attribute) type to be searched fornull if no RDN of the requested type (oid) is
includedpublic java.lang.Object getRDNValue(ObjectID oid)
null is returned.oid - the ObjectID of the RDN (attribute) type to be searched fornull if no RDN of the requested type (oid) is
includedpublic java.lang.Object[] getRDNValues(ObjectID oid)
Some CAs support certificates where the subject name may have multiple RDNs
of same attribute type (ObjectID), e.g. two organizationalUnit entries.
More than one RDN of same attribute type may be added to a Name
structure by repeatedly calling the addRDN
method with the same objectID (attribute type), e.g.:
name.addRDN(ObjectID.organizationalUnit,"..."); name.addRDN(ObjectID.organizationalUnit,"..."); ...When calling this
getRDNs method, all the inherent RDN objects
are searched for the given objectID (attribute type). Any detected value
contributes to a String array returning the values of all included RDN
objects with the requested attribute type (oid).
If no RDN with such an ObjectID (attribute type) is included, null
is returned.
oid - the ObjectID of the RDN (attribute) type to be searched fornull if no RDN of the requested type (oid) is
includedpublic java.util.Enumeration elements()
public int size()
public boolean isEmpty()
true if there are no RDNs, false otherwisepublic void addRDN(ObjectID oid, java.lang.Object value)
oid - the ObjectID (attribute type) of the RDN to be addedvalue - the value of the RDN to be addedpublic void addRDN(RDN rdn)
rdn - the RDN to be addedpublic boolean removeRDN(ObjectID oid)
oid - the ObjectID (attribute type) of the RDN which shall be removedtrue if some RDN(s) have been removed; false
if no RDN has been removed, since no RDN of the requested type is
included in this Namepublic ASN1Object toASN1Object()
toASN1Object in interface ASN1Typepublic byte[] getEncoded()
public int hashCode()
hashCode in interface java.security.PrincipalhashCode in class java.lang.Objectpublic int hashCode(boolean sort)
public boolean equals(java.lang.Object obj)
equals in interface java.security.Principalequals in class java.lang.Objectobj - - the object to compare this Name against.true, if the object represents the same Name
false otherwisepublic java.lang.String getName()
getName in interface java.security.Principalpublic java.lang.String toString()
toString in interface java.security.PrincipaltoString in class java.lang.Objectpublic java.lang.String toString(boolean detailed)
detailed - true if no shortNames shall be used when
printing the attribute types of the AVAspublic java.lang.String getRFC2253String()
throws RFC2253NameParserException
RFC 2253 specifies a string representation of Distinguished Names as used for LDAP lookups.
The included RDNs are represented in reversed order starting with the last element and moving to the first. Adjoining RDNs are separated by a comma (",").
The AttributeTypeAndValues of each included RDN are represented as specified in
sections 2.3, 2.4 of RFC 2253 (adjoining AttributeTypeAndValues
(or AVAs) are separated by a plus ("+")
character):
The attribute type is represented as described in section 2.3 of RFC 2253. If there is no known name string for the attribute type a dotted-decimal encoding of the attribute type´s identifier.
The string representation of the attribute value is either a hexadecimal represenation of its BER encoding (introduced by a "#" character) or based on the algorithm given in section 2.4 of RFC 2253 applying the following escaping mechanisms:
RFC2253NameParserException - if the AVA cannot be represented
according to the rules abovepublic java.lang.String getRFC2253String(boolean escapeNonPrintableAscii)
escapeNonPrintableAscii - indicates whether or not every non-printable character and
non-ASCII character should be represented in escaped formatpublic java.lang.String getComparableString()
According to the name comparison rules in RFC 2459/3280, the names differ only by whitespace and capitalization should be considered the same name (e.g., " Marianne Swanson" is the same as "MARIANNE SWANSON ").
Note:
This method converts all characters to upper case, removes leading and trailing whitespace, and converts internal substrings of one or more consecutive white space characters to a single space. The string output is compatible to RFC 1779/2253 except for escaping.
public java.lang.String getComparableString(boolean sort)
According to the name comparison rules in RFC 2459/3280, the names differ only by whitespace and capitalization should be considered the same name (e.g., " Marianne Swanson" is the same as "MARIANNE SWANSON ").
Note
This method converts all characters to upper case, removes leading and trailing whitespace, and converts internal substrings of one or more consecutive white space characters to a single space. The string output is compatible to RFC 1779/2253 except for escaping.
public java.lang.Object clone()
Name.clone in class java.lang.Object