public class RDN extends java.lang.Object implements ASN1Type
A Distinguished Name is used to specify a path within a X.500 directory information tree. A distinguished name is defined as a sequence of relative distinguished names, where a relative distinguished name is defined as follows:
RelativeDistinguishedName ::= SET OF AttributeValueAssertion AttributeValueAssertion ::= SEQUENCE { AttributeType OBJECT IDENTIFIER, AttributeValue ANY }
Note that some (newer) standards (e.g. RFC 5280) use the term AttributeTypeAndValue
instead of AttributeValueAssertion
; the ASN.1 syntax is the same:
RelativeDistinguishedName ::= SET OF AttributeTypeAndValue AttributeTypeAndValue ::= SEQUENCE { AttributeType AttributeType, AttributeValue AttributeValue } AttributeType ::= OBJECT IDENTIFIER AttributeValue ::= ANY -- DEFINED BY AttributeType
You may directly supply a AttributeValueAssertion (AVA
) when creating a
RelativeDistinguishedName object, or (and) you may use the addAVA
method for later adding some AVA, e.g.:
RDN rel_dis_name = new RDN(ObjectID.country, "AT"); rel_dis_name.addAVA(ObjectID.locality, "Graz");
When specifying issuer or subject within a X.509 certificate by a distinguished name composed of relative distinguished names, it is recommended that each set of AttributeValueAssertions constituting a RelativeDistinguishedName only should contain one element.
Modifier and Type | Field and Description |
---|---|
protected java.util.Vector |
avas
Repository for AttributeValueAssertion objects.
|
Constructor and Description |
---|
RDN()
Creates an empty RelativeDistinguishedName.
|
RDN(ASN1Object obj)
Creates a RelativeDistinguishedName from an ASN1Object.
|
RDN(ObjectID oid,
java.lang.Object value)
Creates a new RelativeDistinguishedName for one AVA.
|
Modifier and Type | Method and Description |
---|---|
void |
addAVA(AVA ava)
Adds a AttributeValueAssertion (AttributeTypeAndValue) object
to this RelativeDistinguishedName.
|
void |
addAVA(AVA ava,
boolean replace)
Adds a AttributeValueAssertion (AttributeTypeAndValue) object
to this RelativeDistinguishedName.
|
void |
addAVA(ObjectID oid,
java.lang.Object value)
Creates a new AttributeValueAssertion (AttributeTypeAndValue) with
given type and value and adds it to this RelativeDistinguishedName.
|
void |
decode(ASN1Object obj)
Decodes a RelativeDistinguishedName from the given ASN1Object.
|
java.util.Enumeration |
elements()
Returns an enumeration of the AVAs in this RDN.
|
boolean |
equals(java.lang.Object obj)
Compares two RelativeDistinguishedNames.
|
AVA |
getAVA()
This method returns one AVA.
|
AVA |
getAVA(ObjectID oid)
Returns an AttributeValueAssertion (AttributeTypeAndValue) of given type
from this RelativeDistinguishedName.
|
AVA[] |
getAVAs()
Returns an array containing the AVAs of this RDN.
|
AVA[] |
getAVAs(ObjectID oid)
Returns all AttributeValueAssertion (AttributeTypeAndValue) objects
of given type from this RelativeDistinguishedName.
|
java.lang.String |
getRFC2253String()
Returns a string representation of this RDN according to RFC 2253.
|
java.lang.String |
getRFC2253String(boolean strictEscaping)
Returns a string representation of this RDN according to RFC 2253.
|
int |
hashCode()
Returns the hashcode for this RDN.
|
ASN1Object |
toASN1Object()
Returns the RelativeDistinguishedName as an ASN1Object.
|
java.lang.String |
toString()
Returns a string that represents the contents of this RDN.
|
java.lang.String |
toString(boolean detailed)
Returns a string that represents the contents of this RDN.
|
public RDN()
public RDN(ObjectID oid, java.lang.Object value)
AttributeValueAssertion
(AttributeTypeAndValue)
objects may be added by using a proper addAVA
method.oid
- the type (object ID) of the AVA to be addedvalue
- the value of the AVA to be addedpublic RDN(ASN1Object obj) throws CodingException
The supplied ASN1Object represents an already existing RDN
that may have been created by means of the toASN1Object
method.
obj
- the RelativeDistinguishedName as ASN1ObjectCodingException
- if this ASN1Object could not be parsedpublic void decode(ASN1Object obj) throws CodingException
The supplied ASN1Object represents an already existing RDN object that
may have been created by means of the toASN1Object()
method.
decode
in interface ASN1Type
obj
- the RDN as ASN1ObjectCodingException
- if the ASN1Object has the wrong formatpublic ASN1Object toASN1Object()
toASN1Object
in interface ASN1Type
public void addAVA(ObjectID oid, java.lang.Object value)
addAVA(AVA ava, boolean replace)
, e.g.:
RDN rdn = ...; AVA ava = new AVA(ObjectID.organization, "IAIK"); boolean replace = false; rdn.addAVA(ava, replace);
oid
- the attribute type of the AVA to be added, as object IDvalue
- the attribute valuepublic void addAVA(AVA ava)
If an AVA of the same type already is included, it will be replaced
by the new AVA. If you do not want to replace an already existing
AVA with the same type use method addAVA(AVA ava, boolean replace)
, e.g.:
RDN rdn = ...; AVA ava = new AVA(ObjectID.organization, "IAIK"); boolean replace = false; rdn.addAVA(ava, replace);
ava
- the AttributeValueAssertion (AttributeTypeAndValue) to addpublic void addAVA(AVA ava, boolean replace)
replace
parameter the
new AVA will replace an already existing AVA with the same type
or will be added to the set of AVAs.ava
- the AttributeValueAssertion (AttributeTypeAndValue) to addreplace
- whether to replace an already existing AVA with the same
type or to add the new AVA add the end of the set of AVAspublic AVA getAVA(ObjectID oid)
oid
- the type of the AVA to be searched for, as ObjectIDnull
if
no AVA with the given type is includedpublic AVA[] getAVAs(ObjectID oid)
oid
- the type of the AVA to be searched for, as ObjectIDpublic AVA getAVA()
public java.util.Enumeration elements()
public AVA[] getAVAs()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
The two RDNs are considered as being equal if they contain the same AVAs (in any order).
equals
in class java.lang.Object
obj
- the other RelativeDistinguishedNametrue
, if the two RelativeDistinguishedNames are equal, false
otherwisepublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean detailed)
public 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.
Each included AttributeTypeAndValue is 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.
Each included AttributeTypeAndValue is 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