public class RFC2253NameParser
extends java.lang.Object
iaik.asn1.structures.Name
object. This
implementation is also compliant with the updated standard RFC 4514, which obsoleted
RFC 2253. This implementation tries to parse every string representation
as long as it can be interpreted unambiguously.
For converting a RFC 2253 string first create a new
#RFC2253NameParser
object and supply the
string to be converted. Subsequently simply call method parse
to get the Name object, e.g.:
String rcf2253Name = "CN=Joe TestUser,O=IAIK,C=AT"; RFC2253NameParser nameParser = new RFC2253NameParser(rcf2253Name); iaik.asn1.structures.Name = nameParser.parse();Attention! When using this parser, please be aware that a valid transformation from an RFC 2253 string to a Distinguished Name (rspectively its encoding) only can be done when the RFC 2253 string gives a hexadecimal representation of the encoding. See RFC 2253, section 7.2: 7.2. Use of Distinguished Names in Security Applications The transformations of an AttributeValue value from its X.501 form to an LDAP string representation are not always reversible back to the same BER or DER form. An example of a situation which requires the DER form of a distinguished name is the verification of an X.509 certificate. For example, a distinguished name consisting of one RDN with one AVA, in which the type is commonName and the value is of the TeletexString choice with the letters 'Sam' would be represented in LDAP as the string CN=Sam. Another distinguished name in which the value is still 'Sam' but of the PrintableString choice would have the same representation CN=Sam. Applications which require the reconstruction of the DER form of the value SHOULD NOT use the string representation of attribute syntaxes when converting a distinguished name to the LDAP format. Instead, they SHOULD use the hexadecimal form prefixed by the octothorpe ('#') as described in the first paragraph of section 2.4. As specified by RFC 2253 this parser expects a hexadecimal representation when the AttributeType is given in the dotted-decimal form, e.g.:
1.3.6.1.4.1.1466.0=#04024869
Modifier and Type | Class and Description |
---|---|
protected static class |
RFC2253NameParser.AVA
Represents the parsing result for a Attribute-Value-Assertion.
|
protected static class |
RFC2253NameParser.ParsedName
Represents the parsing result for a Name.
|
protected static class |
RFC2253NameParser.ParsedRDN
Represents the parsing result for a Relative Distinguished Name.
|
protected static class |
RFC2253NameParser.ShortNameOIDAssociation
Provides functionality to map a Short Name of an well known Object
Identifier to the corresponding Object Identifier.
|
Modifier and Type | Field and Description |
---|---|
protected RFC2253NameParser.ParsedName |
name_
Collects the parsing results.
|
protected java.lang.StringBuffer |
nameStrBuf_
The name to be parsed as StringBuffer.
|
protected int |
position_
The current parsing position within
nameStrBuf_ to be parsed. |
Constructor and Description |
---|
RFC2253NameParser(java.lang.String name)
Standard constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkObjectIDForAssociatedOIDs(boolean checkObjectID)
Decides whether to also ask class
ObjectID
for associated OIDs. |
Name |
parse()
Parses the name string, which has been set in the constructor.
|
protected java.lang.String |
parseAttrType()
Parses the type of an Attribute-Value-Assertion, starting from the position
indicated by the current value of the member variable
position_ . |
protected RFC2253NameParser.AVA |
parseAttrValue()
Parses the value of an Attribute-Value-Assertion, starting from the
position indicated by the current value of the member variable
position_ . |
protected RFC2253NameParser.AVA |
parseAVA()
Parses an Attribute-Value-Assertion, starting from the position indicated
by the current value of the member variable
position_ . |
protected char |
parseHexPair()
Parses a pair of two characters representing the hex value of a character,
starting from the position indicated by the current value of the member
variable
position_ . |
protected char |
parseHexPairEscapeSequence() |
protected RFC2253NameParser.ParsedRDN |
parseRDN()
Parses a Relative distinguished Name, starting from the position indicated
by the current value of the member variable
position_ . |
static void |
register(java.lang.String shortName,
ObjectID oid)
Associates the supplied short name with the given OID.
|
static void |
register(java.lang.String shortName,
ObjectID oid,
boolean caseSensitive)
Associates the supplied short name with the given OID.
|
protected void |
skipOIDIntro()
Checks if the next for characters, starting at position
position_ equal the String "OID." (case will be ignored). |
protected void |
skipSpace()
Increases the member variable
position_ as long as the
character at position position_ does not equal the space
character. |
protected void |
skipSpaceAndLineBreak()
Increases the member variable
position_ as long as the
character at position position_ does not equal the space
character or does not represent a line break. |
protected RFC2253NameParser.ParsedName name_
protected int position_
nameStrBuf_
to be parsed.protected java.lang.StringBuffer nameStrBuf_
public RFC2253NameParser(java.lang.String name)
name
- The name string to be parsed.public static void register(java.lang.String shortName, ObjectID oid)
This method allows an application to register additional shortName -- OID associations. The following associations are already registered:
"CN" ..................... commonName ("2.5.4.3") "SN" ..................... surName ("2.5.4.4") "C" ..................... countryName ("2.5.4.6") "L" ..................... localityName ("2.5.4.7") "ST" ..................... stateOrProvinceName ("2.5.4.8") "STREET" ................. streetAddress ("2.5.4.9") "O" ..................... organizationName ("2.5.4.10") "OU" ..................... organizationUnitName ("2.5.4.11") "T" ..................... title ("2.5.4.12") "title" ................. title ("2.5.4.12") "DC" ..................... domainComponent ("0.9.2342.19200300.100.1.25") "UID" .................... userid ("0.9.2342.19200300.100.1.1") "EMail" .................. emailAddress ("1.2.840.113549.1.9.1") "E" ...................... emailAddress ("1.2.840.113549.1.9.1") "EA" ..................... emailAddress ("1.2.840.113549.1.9.1") "MAIL" ................... emailAddress ("1.2.840.113549.1.9.1") "EMAIL" .................. emailAddress ("1.2.840.113549.1.9.1") "emailAddress" ........... emailAddress ("1.2.840.113549.1.9.1") "EmailAddress" ........... emailAddress ("1.2.840.113549.1.9.1") "EMAILADDRESS" ........... emailAddress ("1.2.840.113549.1.9.1") "serialNumber" ........... serialNumber ("2.5.4.5") "postalAddress" .......... postalAddress ("2.5.4.16") "postalCode" ............. postalCode ("2.5.4.17") "telephoneNumber" ........ telephoneNumber ("2.5.4.20") "telexNumber" ............ telexNumber ("2.5.4.21"); "description" ............ description ("2.5.4.13"); "givenName" .............. givenName ("2.5.4.42"); "initials" ............... initials ("2.5.4.43"); "generationQualifier" .... generationQualifier ("2.5.4.44"); "uniqueIdentifier" ....... uniqueIdentifier ("2.5.4.45"); "dnQualifier" ............ dnQualifier ("2.5.4.46"); "pseudonym" .............. pseudonym ("2.5.4.65"); "dateOfBirth" ............ dateOfBirth ("1.3.6.1.5.5.7.9.1"); "placeOfBirth" ........... placeOfBirth ("1.3.6.1.5.5.7.9.2"); "gender" ................. gender ("1.3.6.1.5.5.7.9.3"); "countryOfCitizenship" ... countryOfCitizenship ("1.3.6.1.5.5.7.9.4"); "countryOfResidence" ..... countryOfResidence ("1.3.6.1.5.5.7.9.4"); "personalTitle" .......... personalTitle ("0.9.2342.19200300.100.1.40");Notice that calling this method for one of the registered shortName will replace the corresponding registration entry.
shortName
- the short name to be associated with an OIDoid
- the object identifier for the short name in mindpublic static void register(java.lang.String shortName, ObjectID oid, boolean caseSensitive)
This method allows an application to register additional shortName -- OID associations. The foolowing associations are already registered:
"CN" ..................... commonName ("2.5.4.3") "SN" ..................... surName ("2.5.4.4") "C" ..................... countryName ("2.5.4.6") "L" ..................... localityName ("2.5.4.7") "ST" ..................... stateOrProvinceName ("2.5.4.8") "STREET" ................. streetAddress ("2.5.4.9") "O" ..................... organizationName ("2.5.4.10") "OU" ..................... organizationUnitName ("2.5.4.11") "T" ..................... title ("2.5.4.12") "title" ................. title ("2.5.4.12") "DC" ..................... domainComponent ("0.9.2342.19200300.100.1.25") "UID" .................... userid ("0.9.2342.19200300.100.1.1") "EMail" .................. emailAddress ("1.2.840.113549.1.9.1") "E" ...................... emailAddress ("1.2.840.113549.1.9.1") "EA" ..................... emailAddress ("1.2.840.113549.1.9.1") "MAIL" ................... emailAddress ("1.2.840.113549.1.9.1") "EMAIL" .................. emailAddress ("1.2.840.113549.1.9.1") "emailAddress" ........... emailAddress ("1.2.840.113549.1.9.1") "EmailAddress" ........... emailAddress ("1.2.840.113549.1.9.1") "EMAILADDRESS" ........... emailAddress ("1.2.840.113549.1.9.1") "serialNumber" ........... serialNumber ("2.5.4.5") "postalAddress" .......... postalAddress ("2.5.4.16") "postalCode" ............. postalCode ("2.5.4.17") "telephoneNumber" ........ telephoneNumber ("2.5.4.20") "telexNumber" ............ telexNumber ("2.5.4.21"); "description" ............ description ("2.5.4.13"); "givenName" .............. givenName ("2.5.4.42"); "initials" ............... initials ("2.5.4.43"); "generationQualifier" .... generationQualifier ("2.5.4.44"); "uniqueIdentifier" ....... uniqueIdentifier ("2.5.4.45"); "dnQualifier" ............ dnQualifier ("2.5.4.46"); "pseudonym" .............. pseudonym ("2.5.4.65"); "dateOfBirth" ............ dateOfBirth ("1.3.6.1.5.5.7.9.1"); "placeOfBirth" ........... placeOfBirth ("1.3.6.1.5.5.7.9.2"); "gender" ................. gender ("1.3.6.1.5.5.7.9.3"); "countryOfCitizenship" ... countryOfCitizenship ("1.3.6.1.5.5.7.9.4"); "countryOfResidence" ..... countryOfResidence ("1.3.6.1.5.5.7.9.4");Notice that calling this method for one of the registered shortName will replace the corresponding registration entry.
shortName
- the short name to be associated with an OIDoid
- the object identifier for the short name in mindcaseSensitive
- true
to register the short name case sensitive only
(default), false
if also registering it
case-insensitivepublic static void checkObjectIDForAssociatedOIDs(boolean checkObjectID)
ObjectID
for associated OIDs.
If no registered OID
for a short name can be found the RFC2253NameParser may be advised to also
ask the OID repository of class ObjectID
for
an associated OID.
checkObjectID
- whether to ask the OID repository of class
ObjectID
for
an associated OID (if no one can be found in
the internal RFC2253NameParser repository).
Default: false
, do not check the
ObjectID OID repositorypublic Name parse() throws RFC2253NameParserException
Name
object representing the structure of the parsed
X.501 Name.RFC2253NameParserException
- if the name string could not be parsed successfully.protected RFC2253NameParser.ParsedRDN parseRDN() throws RFC2253NameParserException
position_
.ParsedRDN
object representing the structure of the
parsed RDN.RFC2253NameParserException
- if the RDN could not be parsed successfully.protected RFC2253NameParser.AVA parseAVA() throws RFC2253NameParserException
position_
.AVA
object representing the structure of the parsed
AVA.RFC2253NameParserException
- if the AVA could not be parsed successfully.protected java.lang.String parseAttrType() throws RFC2253NameParserException
position_
.String
representing the type of a AVA.RFC2253NameParserException
- if the AVA type could not be parsed successfully.protected RFC2253NameParser.AVA parseAttrValue() throws RFC2253NameParserException
position_
.AVA
object with its value_
and
hasHexValue_
fields set.RFC2253NameParserException
- if the AVA value could not be parsed successfully.protected char parseHexPair() throws RFC2253NameParserException
position_
.RFC2253NameParserException
- if the next two characters cannot be interpreted as hex pair.protected char parseHexPairEscapeSequence() throws RFC2253NameParserException
RFC2253NameParserException
protected void skipSpace()
position_
as long as the
character at position position_
does not equal the space
character.protected void skipSpaceAndLineBreak()
position_
as long as the
character at position position_
does not equal the space
character or does not represent a line break.protected void skipOIDIntro()
position_
equal the String "OID." (case will be ignored). If
yes, increases position_
by 4.