Package org.springframework.ldap.support
Class LdapEncoder
java.lang.Object
org.springframework.ldap.support.LdapEncoder
Helper class to encode and decode ldap names and values.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
filterEncode
(String value) Escape a value for use in a filter.static String
nameDecode
(String value) Decodes a value.static String
nameEncode
(String value) LDAP Encodes a value for use with a DN.static byte[]
parseBase64Binary
(String val) Converts the Base64 encoded string argument into an array of bytes.static String
printBase64Binary
(byte[] val) Converts an array of bytes into a Base64 encoded string according to the rules for converting LDAP Attributes in RFC2849.protected static String
toTwoCharHex
(char c)
-
Method Details
-
toTwoCharHex
-
filterEncode
Escape a value for use in a filter.- Parameters:
value
- the value to escape.- Returns:
- a properly escaped representation of the supplied value.
-
nameEncode
LDAP Encodes a value for use with a DN. Escapes for LDAP, not JNDI!
Escapes:
' ' [space] - "\ " [if first or last]
'#' [hash] - "\#"
',' [comma] - "\,"
';' [semicolon] - "\;"
'= [equals] - "\="
'+' [plus] - "\+"
'<' [less than] - "\<"
'>' [greater than] - "\>"
'"' [double quote] - "\""
'\' [backslash] - "\\"- Parameters:
value
- the value to escape.- Returns:
- The escaped value.
-
nameDecode
Decodes a value. Converts escaped chars to ordinary chars.- Parameters:
value
- Trimmed value, so no leading an trailing blanks, except an escaped space last.- Returns:
- The decoded value as a string.
- Throws:
BadLdapGrammarException
-
printBase64Binary
Converts an array of bytes into a Base64 encoded string according to the rules for converting LDAP Attributes in RFC2849.- Parameters:
val
-- Returns:
- A string containing a lexical representation of base64Binary wrapped around 76 characters.
- Throws:
IllegalArgumentException
- if val is null.
-
parseBase64Binary
Converts the Base64 encoded string argument into an array of bytes.- Parameters:
val
-- Returns:
- An array of bytes represented by the string argument.
- Throws:
IllegalArgumentException
- if val is null or does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:base64Binary.
-