Class LdapMapUtil


  • public class LdapMapUtil
    extends Object

    Utility class for working with LDAP.

    Author:
    Pedro Igor
    • Constructor Detail

      • LdapMapUtil

        public LdapMapUtil()
    • Method Detail

      • formatDate

        public static String formatDate​(Date date)

        Formats the given date.

        Parameters:
        date - The Date to format.
        Returns:
        A String representing the formatted date.
      • parseDate

        public static Date parseDate​(String date)

        Parses dates/time stamps stored in LDAP. Some possible values:

        • 20020228150820
        • 20030228150820Z
        • 20050228150820.12
        • 20060711011740.0Z
        Parameters:
        date - The date string to parse from.
        Returns:
        the Date.
      • convertObjectGUIDToByteString

        public static String convertObjectGUIDToByteString​(byte[] objectGUID)

        Creates a byte-based String representation of a raw byte array representing the value of the objectGUID attribute retrieved from Active Directory.

        The returned string is useful to perform queries on AD based on the objectGUID value. Eg.:

        String filter = "(&(objectClass=*)(objectGUID" + EQUAL + convertObjectGUIDToByteString(objectGUID) + "))";

        Parameters:
        objectGUID - A raw byte array representing the value of the objectGUID attribute retrieved from Active Directory.
        Returns:
        A byte-based String representation in the form of \[0]\[1]\[2]\[3]\[4]\[5]\[6]\[7]\[8]\[9]\[10]\[11]\[12]\[13]\[14]\[15]
      • convertGUIDToEdirectoryHexString

        public static String convertGUIDToEdirectoryHexString​(String guid)
        see http://support.novell.com/docs/Tids/Solutions/10096551.html
        Parameters:
        guid - A GUID in the form of a dashed String as the result of (@see LDAPUtil#convertToDashedString)
        Returns:
        A String representation in the form of \[0][1]\[2][3]\[4][5]\[6][7]\[8][9]\[10][11]\[12][13]\[14][15]
      • encodeObjectGUID

        public static byte[] encodeObjectGUID​(String displayString)

        Encode a string representing the display value of the objectGUID attribute retrieved from Active Directory.

        Parameters:
        displayString - A string representing the decoded value in the form of [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15].
        Returns:
        A raw byte array representing the value of the objectGUID attribute retrieved from Active Directory.
      • decodeObjectGUID

        public static String decodeObjectGUID​(byte[] objectGUID)

        Decode a raw byte array representing the value of the objectGUID attribute retrieved from Active Directory.

        The returned string is useful to directly bind an entry. Eg.:

        String bindingString = decodeObjectGUID(objectGUID);
        Attributes attributes = ctx.getAttributes(bindingString);

        Parameters:
        objectGUID - A raw byte array representing the value of the objectGUID attribute retrieved from Active Directory.
        Returns:
        A string representing the decoded value in the form of [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15].
      • decodeGuid

        public static String decodeGuid​(byte[] guid)

        Decode a raw byte array representing the value of the guid attribute retrieved from Novell eDirectory.

        Parameters:
        guid - A raw byte array representing the value of the guid attribute retrieved from Novell eDirectory.
        Returns:
        A string representing the decoded value in the form of [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15].
      • setLDAPHostnameToKeycloakSession

        public static void setLDAPHostnameToKeycloakSession​(KeycloakSession session,
                                                            LdapMapConfig ldapConfig)