Package org.springframework.ldap.support
Class LdapEncoder
- java.lang.Object
-
- org.springframework.ldap.support.LdapEncoder
-
public final class LdapEncoder extends java.lang.Object
Helper class to encode and decode ldap names and values.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
filterEncode(java.lang.String value)
Escape a value for use in a filter.static java.lang.String
nameDecode(java.lang.String value)
Decodes a value.static java.lang.String
nameEncode(java.lang.String value)
LDAP Encodes a value for use with a DN.static byte[]
parseBase64Binary(java.lang.String val)
Converts the Base64 encoded string argument into an array of bytes.static java.lang.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 java.lang.String
toTwoCharHex(char c)
-
-
-
Method Detail
-
toTwoCharHex
protected static java.lang.String toTwoCharHex(char c)
-
filterEncode
public static java.lang.String filterEncode(java.lang.String value)
Escape a value for use in a filter.- Parameters:
value
- the value to escape.- Returns:
- a properly escaped representation of the supplied value.
-
nameEncode
public static java.lang.String nameEncode(java.lang.String value)
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
public static java.lang.String nameDecode(java.lang.String value) throws BadLdapGrammarException
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
public static java.lang.String printBase64Binary(byte[] val)
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:
java.lang.IllegalArgumentException
- if val is null.
-
parseBase64Binary
public static byte[] parseBase64Binary(java.lang.String val)
Converts the Base64 encoded string argument into an array of bytes.- Parameters:
val
-- Returns:
- An array of bytes represented by the string argument.
- Throws:
java.lang.IllegalArgumentException
- if val is null or does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:base64Binary.
-
-