go to  ForumEasy.com   
LdapPro
   Home  |  MyForum  |  FAQ  |  Archive    You are not logged in. [Login] or [Register]  
Forum Home » LDAP RFCs & SPECs » Special Characters in Filter -- RFC-2254
Email To Friend  |   Set Alert To This Topic Rewarding Points Availabe: 0 (What's this) New Topic  |   Post Reply
Author Topic: Special Characters in Filter -- RFC-2254
SteveHB
member
offline   
 
posts: 108
joined: 05/31/2006
from: Mountain View, CA
  posted on: 08/17/2006 01:50:27 PM    Edit  |   Quote  |   Report 
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.


 Profile | Reply Points Earned: 0
SteveHB
member
offline   
 
posts: 108
joined: 05/31/2006
from: Mountain View, CA
  posted on: 08/17/2006 01:56:03 PM    Edit  |   Quote  |   Report 
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.

 Profile | Reply Points Earned: 0
SteveHB
member
offline   
 
posts: 108
joined: 05/31/2006
from: Mountain View, CA
  posted on: 08/17/2006 01:58:06 PM    Edit  |   Quote  |   Report 
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.


 Profile | Reply Points Earned: 0
SteveHB
member
offline   
 
posts: 108
joined: 05/31/2006
from: Mountain View, CA
  posted on: 08/17/2006 02:00:46 PM    Edit  |   Quote  |   Report 
Example of Special Character '\'

    (filename=C:\5cMyFile)

This example illustrates the escaping of the backslash character.

 Profile | Reply Points Earned: 0
SteveHB
member
offline   
 
posts: 108
joined: 05/31/2006
from: Mountain View, CA
  posted on: 08/17/2006 02:05:28 PM    Edit  |   Quote  |   Report 
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.


 Profile | Reply Points Earned: 0
SteveHB
member
offline   
 
posts: 108
joined: 05/31/2006
from: Mountain View, CA
  posted on: 08/17/2006 02:07:07 PM    Edit  |   Quote  |   Report 

   (sn=Lu\c4\8di\c4\87)

This example illustrates the use of the escaping mechanism to represent various non-ASCII UTF-8 characters.

 Profile | Reply Points Earned: 0
JNDI
member
offline   
 
posts: 7
joined: 05/18/2007
from: GA
  posted on: 03/08/2010 08:17:11 PM    Edit  |   Quote  |   Report 
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:
sn:: TGXDqQ==


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)";



  •  Profile | Reply Points Earned: 0

     
    Powered by ForumEasy © 2003-2005, All Rights Reserved. | Privacy Policy | Terms of Use
     
    Get your own forum today. It's easy and free.