import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;

class RechercheBasique {
    public static void main(String[] args) {

	// Set up the environment for creating the initial context
	Hashtable env = new Hashtable(11);
	env.put(Context.INITIAL_CONTEXT_FACTORY, 
	    "com.sun.jndi.ldap.LdapCtxFactory");
	env.put(Context.PROVIDER_URL, "ldap://ldap.rennes.enst-bretagne.fr");
	try {
	    // Create initial context
	    DirContext ctx = new InitialDirContext(env);
	    Attributes matchAttrs = new BasicAttributes(true);
	    matchAttrs.put(new BasicAttribute("cn", "alenorcy"));
	    //matchAttrs.put(new BasicAttribute("mail"));

	    // Search for objects that have those matching attributes
	    NamingEnumeration answer = ctx.search("ou=autre personnel,o=personnel,dc=enst-bretagne,dc=fr", matchAttrs);

	    while (answer.hasMore()) {
	        SearchResult sr = (SearchResult)answer.next();
	        System.out.println(">>>" + sr.getName());
	        System.out.println(sr.getAttributes());
	    }
	    // Close the context when we're done
	    ctx.close();
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }// main
}// class