Class LdapV3DNStrConverter

java.lang.Object
org.mozilla.jss.netscape.security.x509.LdapDNStrConverter
org.mozilla.jss.netscape.security.x509.LdapV3DNStrConverter
Direct Known Subclasses:
RFC1779StrConverter

public class LdapV3DNStrConverter extends LdapDNStrConverter
A converter that converts Ldap v3 DN strings as specified in draft-ietf-asid-ldapv3-dn-03.txt to a X500Name, RDN or AVA and vice versa.
See Also:
  • Field Details

  • Constructor Details

    • LdapV3DNStrConverter

      public LdapV3DNStrConverter()
      Constructs a LdapV3DNStrConverter using the global default X500NameAttrMap and accept OIDs not in the default X500NameAttrMap.
      See Also:
    • LdapV3DNStrConverter

      public LdapV3DNStrConverter(X500NameAttrMap attributeMap, boolean doAcceptUnknownOids)
      Constructs a LdapV3DNStrConverter using the specified X500NameAttrMap and a boolean indicating whether to accept OIDs not listed in the X500NameAttrMap.
      Parameters:
      attributeMap - a X500NameAttrMap
      doAcceptUnknownOids - whether to convert unregistered OIDs (oids not in the X500NameAttrMap)
      See Also:
  • Method Details

    • parseDN

      public X500Name parseDN(String dn) throws IOException
      Parse a Ldap v3 DN string to a X500Name.
      Specified by:
      parseDN in class LdapDNStrConverter
      Parameters:
      dn - a LDAP v3 DN String
      Returns:
      a X500Name
      Throws:
      IOException - if an error occurs during the conversion.
    • parseDN

      public X500Name parseDN(String dn, byte[] encodingOrder) throws IOException
      Like parseDN(String) with a DER encoding order given as argument for Directory Strings.
      Specified by:
      parseDN in class LdapDNStrConverter
      Throws:
      IOException
    • parseRDN

      public RDN parseRDN(String rdn) throws IOException
      Parse a Ldap v3 DN string with a RDN component to a RDN
      Specified by:
      parseRDN in class LdapDNStrConverter
      Parameters:
      rdn - a LDAP v3 DN String
      Returns:
      a RDN
      Throws:
      IOException - if an error occurs during the conversion.
    • parseRDN

      public RDN parseRDN(String rdn, byte[] encodingOrder) throws IOException
      Like parseRDN(String) with a DER encoding order given as argument for Directory Strings.
      Specified by:
      parseRDN in class LdapDNStrConverter
      Throws:
      IOException
    • parseAVA

      public AVA parseAVA(String ava) throws IOException
      Parse a Ldap v3 DN string with a AVA component to a AVA.
      Specified by:
      parseAVA in class LdapDNStrConverter
      Parameters:
      ava - a LDAP v3 DN string
      Returns:
      a AVA
      Throws:
      IOException
    • parseAVA

      public AVA parseAVA(String ava, byte[] encodingOrder) throws IOException
      Like parseDN(String) with a DER encoding order given as argument for Directory Strings.
      Specified by:
      parseAVA in class LdapDNStrConverter
      Throws:
      IOException
    • parseDN

      public X500Name parseDN(PushbackReader in) throws IOException
      Parses a Ldap DN string in a string reader to a X500Name.
      Parameters:
      in - Pushback string reader for a Ldap DN string. The pushback reader must have a pushback buffer size > 2.
      Returns:
      a X500Name
      Throws:
      IOException - if any reading or parsing error occurs.
    • parseDN

      public X500Name parseDN(PushbackReader in, byte[] encodingOrder) throws IOException
      Like parseDN(PushbackReader in) with a DER encoding order given as argument for Directory Strings.
      Throws:
      IOException
    • parseRDN

      public RDN parseRDN(PushbackReader in) throws IOException
      Parses Ldap DN string with a rdn component from a string reader to a RDN. The string reader will point to the separator after the rdn component or -1 if at end of string.
      Parameters:
      in - Pushback string reader containing a Ldap DN string with at least one rdn component. The pushback reader must have a pushback buffer size > 2.
      Returns:
      RDN object of the first rdn component in the Ldap DN string.
      Throws:
      IOException - if any read or parse error occurs.
    • parseRDN

      public RDN parseRDN(PushbackReader in, byte[] encodingOrder) throws IOException
      Like parseRDN(PushbackReader) with a DER encoding order given as argument for Directory Strings.
      Throws:
      IOException
    • parseAVA

      public AVA parseAVA(PushbackReader in) throws IOException
      Parses a Ldap DN string with a AVA component from a string reader to an AVA. The string reader will point to the AVA separator after the ava string or -1 if end of string.
      Parameters:
      in - a Pushback reader containg a Ldap string with at least one AVA component. The Pushback reader must have a pushback buffer size > 2.
      Returns:
      AVA object of the first AVA component in the Ldap DN string.
      Throws:
      IOException
    • parseAVA

      public AVA parseAVA(PushbackReader in, byte[] encodingOrder) throws IOException
      Like parseAVA(PushbackReader) with a DER encoding order given as argument for Directory Strings.
      Throws:
      IOException
    • parseAVAKeyword

      public ObjectIdentifier parseAVAKeyword(String avaKeyword) throws IOException
      Converts a AVA keyword from a Ldap DN string to an ObjectIdentifier from the attribute map or, if this keyword is an OID not in the attribute map, create a new ObjectIdentifier for the keyword if acceptUnknownOids is true.
      Parameters:
      avaKeyword - AVA keyword from a Ldap DN string.
      Returns:
      a ObjectIdentifier object
      Throws:
      IOException - if the keyword is an OID not in the attribute map and acceptUnknownOids is false, or if an error occurs during conversion.
    • parseAVAValue

      public DerValue parseAVAValue(String avaValueString, ObjectIdentifier oid) throws IOException
      Converts a AVA value from a Ldap dn string to a DerValue according the attribute type. For example, a value for CN, OU or O is expected to be a Directory String and will be converted to a DerValue of ASN.1 type PrintableString, T61String or UniversalString. A Directory String is a ASN.1 CHOICE of Printable, T.61 or Universal string.
      Parameters:
      avaValueString - a attribute value from a Ldap DN string.
      oid - OID of the attribute.
      Returns:
      DerValue for the value.
      Throws:
      IOException - if an error occurs during conversion.
      See Also:
    • parseAVAValue

      public DerValue parseAVAValue(String avaValueString, ObjectIdentifier oid, byte[] encodingOrder) throws IOException
      Like parseAVAValue(String) with a DER encoding order given as argument for Directory Strings.
      Throws:
      IOException
    • parseAVAValue

      public DerValue parseAVAValue(byte[] berValue, ObjectIdentifier oid) throws IOException
      Converts a value in BER encoding, for example given in octothorpe form in a Ldap v3 dn string, to a DerValue. Checks if the BER encoded value is a legal value for the attribute.

      NOTE: only DER encoded values are supported for the BER encoded value.

      Parameters:
      berValue - a value in BER encoding
      oid - ObjectIdentifier of the attribute.
      Returns:
      DerValue for the BER encoded value
      Throws:
      IOException - if an error occurs during conversion.
    • encodeDN

      public String encodeDN(X500Name x500name) throws IOException
      Converts a X500Name object to a Ldap v3 DN string (except in unicode).
      Specified by:
      encodeDN in class LdapDNStrConverter
      Parameters:
      x500name - a X500Name
      Returns:
      a Ldap v3 DN String (except in unicode).
      Throws:
      IOException - if an error is encountered during conversion.
    • encodeRDN

      public String encodeRDN(RDN rdn) throws IOException
      Converts a RDN to a Ldap v3 DN string (except in unicode).
      Specified by:
      encodeRDN in class LdapDNStrConverter
      Parameters:
      rdn - a RDN
      Returns:
      a LDAP v3 DN string (except in unicode).
      Throws:
      IOException - if an error is encountered during conversion.
    • encodeAVA

      public String encodeAVA(AVA ava) throws IOException
      Converts a AVA to a Ldap v3 DN String (except in unicode).
      Specified by:
      encodeAVA in class LdapDNStrConverter
      Parameters:
      ava - an AVA
      Returns:
      a Ldap v3 DN string (except in unicode).
      Throws:
      IOException - If an error is encountered during exception.
    • encodeOID

      public String encodeOID(ObjectIdentifier oid) throws IOException
      Converts an OID to a attribute keyword in a Ldap v3 DN string - either a keyword if known or a string of "1.2.3.4" syntax.
      Parameters:
      oid - a ObjectIdentifier
      Returns:
      a keyword to use in a Ldap V3 DN string.
      Throws:
      IOException - if an error is encountered during conversion.
    • encodeValue

      public String encodeValue(DerValue attrValue, ObjectIdentifier oid) throws IOException
      Converts a value as a DerValue to a string in a Ldap V3 DN String. If the value cannot be converted to a string it will be encoded in octothorpe form.
      Parameters:
      attrValue - a value as a DerValue.
      oid - OID for the attribute.
      Returns:
      a string for the value in a LDAP v3 DN String
      Throws:
      IOException - if an error occurs during conversion.
    • encodeString

      public String encodeString(String valueStr)
      converts a raw value string to a string in Ldap V3 DN string format.
      Parameters:
      valueStr - a 'raw' value string.
      Returns:
      a attribute value string in Ldap V3 DN string format.
    • getAttrMap

      public X500NameAttrMap getAttrMap()
      gets the X500NameAttrMap used by the converter.
      Returns:
      X500NameAttrMap used by this converter.
    • getAcceptUnknownOids

      public boolean getAcceptUnknownOids()
      returns true if the converter accepts unregistered attributes i.e. OIDS not in the X500NameAttrMap.
      Returns:
      true if converter converts attributes not in the X500NameAttrMap.
    • getStringFromHexpairs

      protected static char[] getStringFromHexpairs(char[] hexPairs) throws UnsupportedEncodingException
      Parse a sequence of hex pairs, each pair a UTF8 byte to a java string. For example, "4C75C48D" is "Luc", the last c with caron.
      Throws:
      UnsupportedEncodingException