Package org.ldaptive

Class DnParser


  • public final class DnParser
    extends Object
    Parses DNs following the rules in RFC 4514. Attempts to be as generous as possible in the format of allowed DNs.
    • Field Detail

      • LOGGER

        private static final Logger LOGGER
        Logger for this class.
    • Constructor Detail

      • DnParser

        private DnParser()
        Default constructor.
    • Method Detail

      • getValues

        public static Collection<String> getValues​(String dn,
                                                   String name)
        Returns the RDN values for the attribute type with the supplied name.
        Parameters:
        dn - to parse
        name - of the attribute type to return values for
        Returns:
        DN attribute values
      • getValue

        public static String getValue​(String dn,
                                      String name)
        Returns the RDN value for the attribute type with the supplied name. If the component has multiple values, the first one is returned.
        Parameters:
        dn - to parse
        name - of the attribute to return value for
        Returns:
        DN attribute value
      • substring

        public static String substring​(String dn,
                                       int beginIndex)
        Returns a string representation of the supplied DN beginning at the supplied index. The leftmost RDN component begins at index 0.
        Parameters:
        dn - to parse
        beginIndex - index of first RDN to include in the result in the range [0, N-1] where N is the number of elements in the DN
        Returns:
        DN from the supplied beginIndex
        Throws:
        IndexOutOfBoundsException - if beginIndex is less than 0 or greater than the number of RDNs
      • substring

        public static String substring​(String dn,
                                       int beginIndex,
                                       int endIndex)
        Returns a string representation of the supplied DN beginning at beginIndex (inclusive) and ending at endIndex (exclusive). The leftmost RDN component begins at index 0. Where n is the number of RDNs, both beginIndex and endIndex are on the range [0, N-1].
        Parameters:
        dn - to parse
        beginIndex - index of first RDN to include in the result in the range [0, N-2] where N is the number of elements in the DN
        endIndex - index of last RDN to include in the result in the range [1, N-1] where N is the number of elements in the RDN
        Returns:
        DN from beginIndex (inclusive) to endIndex (exclusive)
        Throws:
        IndexOutOfBoundsException - if beginIndex is less than 0, if beginIndex is greater than endIndex, or endIndex is greater than the number of RDNs
      • convertDnToAttributes

        public static List<LdapAttribute> convertDnToAttributes​(String dn)
        Parses the supplied DN and converts each RDN into a LdapAttribute.
        Parameters:
        dn - to parse
        Returns:
        list of ldap attributes for each RDN
      • decodeHexValue

        protected static byte[] decodeHexValue​(char[] value)
        Decodes the supplied hexadecimal value.
        Parameters:
        value - hex to decode
        Returns:
        decoded bytes
      • decodeStringValue

        protected static String decodeStringValue​(String value)
        Decodes the supplied string attribute value. Unescapes escaped characters. If escaped character is a hex value, it is decoded.
        Parameters:
        value - to decode
        Returns:
        decoded string
      • readToChar

        private static int readToChar​(String s,
                                      char[] chars,
                                      int pos)
        Reads the supplied string starting at the supplied position until one of the supplied characters is found. Characters escaped with '\' are ignored.
        Parameters:
        s - to read
        chars - to match
        pos - to start reading at
        Returns:
        string index that matched a character or the last index in the string