| Author |
Topic: Special Characters in Filter -- RFC-2254 |
|
SteveHB member offline  |
| |
| posts: |
108 |
| joined: |
05/31/2006 |
| from: |
Mountain View, CA |
|
|
 |
|
|
| Special Characters in Filter -- RFC-2254 |
Special Characters defined in RFC 2254:
http://www.ietf.org/rfc/rfc2254.txt
If a value should contain any of the following characters
Character ASCII value
---------------------------
* 0x2a
( 0x28
) 0x29
\ 0x5c
NUL 0x00
the character must be encoded as the backslash '\' character (ASCII
0x5c) followed by the two hexadecimal digits representing the ASCII
value of the encoded character. The case of the two hexadecimal
digits is not significant.
This simple escaping mechanism eliminates filter-parsing ambiguities
and allows any filter that can be represented in LDAP to be
represented as a NUL-terminated string. Other characters besides the
ones listed above may be escaped using this mechanism, for example,
non-printing characters.
For example, the filter checking whether the "cn" attribute contained
a value with the character "*" anywhere in it would be represented as
"(cn=*\2a*)".
Note that although both the substring and present productions in the
grammar above can produce the "attr=*" construct, this construct is
used only to denote a presence filter.
|
|
|
|
|
|
|
SteveHB member offline  |
| |
| posts: |
108 |
| joined: |
05/31/2006 |
| from: |
Mountain View, CA |
|
|
 |
|
|
| Example of Special Characters '(' and ')' |
(o=Parens R Us \28for all your parenthetical needs\29)
This example shows the use of the escaping mechanism to represent parenthesis characters.
|
|
|
|
|
|
|
SteveHB member offline  |
| |
| posts: |
108 |
| joined: |
05/31/2006 |
| from: |
Mountain View, CA |
|
|
 |
|
|
| Example of Special Character '*' |
(cn=*\2A*)
This example shows how to represent a "*" in a value, preventing it from being nterpreted as a substring indicator.
|
|
|
|
|
|
|
SteveHB member offline  |
| |
| posts: |
108 |
| joined: |
05/31/2006 |
| from: |
Mountain View, CA |
|
|
 |
|
|
| Example of Special Character '\' |
(filename=C:\5cMyFile)
This example illustrates the escaping of the backslash character.
|
|
|
|
|
|
|
SteveHB member offline  |
| |
| posts: |
108 |
| joined: |
05/31/2006 |
| from: |
Mountain View, CA |
|
|
 |
|
|
| Example of binary data |
(bin=\00\00\00\04)
This example shows a filter searching for the four-byte value 0x00000004, illustrating the use of the escaping mechanism to represent arbitrary data, including NUL characters.
|
|
|
|
|
|
|
SteveHB member offline  |
| |
| posts: |
108 |
| joined: |
05/31/2006 |
| from: |
Mountain View, CA |
|
|
 |
|
|
|
(sn=Lu\c4\8di\c4\87)
This example illustrates the use of the escaping mechanism to represent various non-ASCII UTF-8 characters.
|
|
|
|
|
|
|
JNDI member offline  |
| |
| posts: |
7 |
| joined: |
05/18/2007 |
| from: |
GA |
|
|
 |
|
|
| 3 Ways to input filter in JDNI for special characters |
The following is a sample of JNDI doing filter search.
public static void main(String[] args)
{
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://myServer.mycompany.com:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "user");
env.put(Context.SECURITY_CREDENTIALS, "password");
DirContext ctx = null;
try {
ctx = new InitialDirContext(env);
SearchControls ctls = new SearchControls();
String base_dn = "dc=example,dc=com";
String filter = "(objectclass=*)";
NamingEnumeration enu = ctx.search(base_dn,filter,ctls);
while(enu.hasMore()){
SearchResult sr = (SearchResult)enu.next();
System.out.println("rdn='" +sr.getName()+"'");
}
}catch(NamingException e){
e.printStackTrace();
}finally{
try{
ctx.close();
}catch(Exception e){
}
}
}
For an user in directory server with surename (sn) being 'Leé', the actual format in the storage is:
The exactly matching filter to bring out the user can be written in three different ways:
1) Simlply type in the special character if your keyboard allows:
String filter = "(sn=Leé)";
2) Type in the unicode of the special character:
String filter = "(sn=Le\u00E9)";
3) Type in the UTF-8 string representation of the escaped special character as in the RFC 2254:
String filter = "(sn=Le\C3\A9)";
|
|
|
|
|
|
|