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 dn)
Constructs a Name from its RFC 2253/4514 String representation.
|
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.
|
void |
decode(ASN1Object obj)
Decodes a Name from the given ASN1Object.
|
RDN |
element(ObjectID oid)
Returns an RDN that contains an AVA with the given attribute type.
|
java.util.Enumeration |
elements()
Returns an enumeration of all RDNs included in this Name.
|
java.util.Enumeration |
elements(ObjectID oid)
Returns an enumeration of all RDNs that contain an AVA with
the given attribute type.
|
boolean |
equals(java.lang.Object obj)
Compares this Name to the specified object.
|
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 |
getRDN(ObjectID oid,
boolean rfc2253)
Returns the RDN value assigned to a given ObjectID.
|
RDN[] |
getRDNs()
Returns an array containing all RDNs included this Name.
|
java.lang.String[] |
getRDNs(ObjectID oid)
Returns the values of all RDNs assigned to a given ObjectID.
|
java.lang.String[] |
getRDNs(ObjectID oid,
boolean rfc2253)
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 strictEscaping)
Returns a string representation of this Name according to RFC 2253.
|
int |
hashCode()
Returns a hashcode for this Name.
|
void |
insertRDNAt(ObjectID oid,
java.lang.Object value,
int position)
Inserts a RelativeDistinguishedName with given attribute type and
value to this Name at the given position.
|
void |
insertRDNAt(RDN rdn,
int position)
Inserts a RelativeDistinguishedName to this Name at the given position.
|
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.
|
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 NameCodingException
public Name(ASN1Object obj) throws CodingException
obj
- the Name as ASN1ObjectCodingException
- if the ASN1Object has the wrong formatpublic Name(java.lang.String dn) throws RFC2253NameParserException
For instance:
String rcf2253Name = "CN=Joe TestUser,O=IAIK,C=AT"; Name = new Name(rcf2253Name);
dn
- the (RFC 2253 formatted) distinguished nameCodingException
- if the ASN1Object has the wrong formatRFC2253NameParserException
public void decode(ASN1Object obj) throws CodingException
decode
in interface ASN1Type
obj
- 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 (AVA attribute) type to be searched fornull
if no RDN of the requested type (oid) is
includedjava.lang.ClassCastException
- if the RDN value does not represent a String; in
this case use method getRDNValue
to get the RDN valuepublic java.lang.String getRDN(ObjectID oid, boolean rfc2253) throws RFC2253NameParserException
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 (AVA attribute) type to be searched forrfc2253
- whether to get the String in RFC2253 representationnull
if no RDN of the requested type (oid) is
includedjava.lang.ClassCastException
- if the RDN value does not represent a String; in
this case use method getRDNValue
to get the RDN valueRFC2253NameParserException
- if the AVA cannot be represented
according to RFC2253public 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 (AVA attribute) type to be searched fornull
if no RDN of the requested type (oid) is
includedpublic java.lang.String[] getRDNs(ObjectID oid, boolean rfc2253) throws RFC2253NameParserException
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 (AVA attribute) type to be searched forrfc2253
- whether to get the String in RFC2253 representationnull
if no RDN of the requested type (oid) is
includedRFC2253NameParserException
- if the AVA cannot be represented
according to RFC2253public java.lang.Object getRDNValue(ObjectID oid)
null
is returned.oid
- the ObjectID of the RDN (AVA 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 (AVA attribute) type to be searched fornull
if no RDN of the requested type (oid) is
includedpublic RDN[] getRDNs()
public java.util.Enumeration elements()
public java.util.Enumeration elements(ObjectID oid)
oid
- the ObjectID of the RDN (AVA attribute) type to be searched forpublic RDN element(ObjectID oid)
oid
- the ObjectID of the RDN (AVA attribute) type to be searched fornull
if none of the included RDNs contains an AVA with
the given typepublic 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 void insertRDNAt(ObjectID oid, java.lang.Object value, int position)
oid
- the ObjectID (attribute type) of the RDN to be addedvalue
- the value of the RDN to be addedposition
- the position at which the RDN shall be insertedjava.lang.ArrayIndexOutOfBoundsException
- if position
is out of boundspublic void insertRDNAt(RDN rdn, int position)
rdn
- the RDN to be insertedposition
- the position at which the RDN shall be insertedjava.lang.ArrayIndexOutOfBoundsException
- if position
is out of boundspublic 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 ASN1Type
public byte[] getEncoded()
public int hashCode()
hashCode
in interface java.security.Principal
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in interface java.security.Principal
equals
in class java.lang.Object
obj
- - the object to compare this Name against.true
, if the object represents the same Name
false
otherwisepublic java.lang.String getName()
toString
.getName
in interface java.security.Principal
public java.lang.String toString()
toString
in interface java.security.Principal
toString
in class java.lang.Object
public 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. This implementation is also compliant with the updated standard RFC 4514, which obsoleted RFC 2253.
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 AVA
s) 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 representation 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 strictEscaping) throws RFC2253NameParserException
RFC 2253 specifies a string representation of Distinguished Names as used for LDAP lookups. This implementation is also compliant with the updated standard RFC 4514, which obsoleted RFC 2253.
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 AVA
s) 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 representation 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:
strictEscaping
is set to true
strictEscaping
- whether to escape non printable ASCII (< 0x21 or > 0x7e)
and non-ASCII characters by an hexadecimal representation
of their UTF-8 encodingRFC2253NameParserException
- if the AVA cannot be represented
according to the rules above