go to  ForumEasy.com   
LdapPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  3 Ways to input filter in JDNI for special characters
 
Subject: 3 Ways to input filter in JDNI for special characters
Author: JNDI
In response to: Special Characters in Filter -- RFC-2254
Posted on: 03/08/2010 08:17:11 PM

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




     

    > On 08/17/2006 02:07:07 PM SteveHB wrote:

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

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





    References:

  •  


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