1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
   |  
try {
	  Hashtable hashtableEnvironment = new Hashtable();
	  hashtableEnvironment.put(
		Context.INITIAL_CONTEXT_FACTORY, 
		"com.sun.jndi.ldap.LdapCtxFactory"
	  );
	  hashtableEnvironment.put(
		Context.PROVIDER_URL, 
		"ldap://host:389/"
	  );
 
            DirContext  context = new InitialDirContext(hashtableEnvironment);
            SearchControls searchControls = new SearchControls();
            searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
           NamingEnumeration resultat = context.search ("o=xxxx,C=FR","uid=toto",searchControls);
	  System.err.println(resultat);
	  while(resultat.hasMore()) {	  	
 
                       SearchResult sr = (SearchResult) resultat.next();
                       Attributes attributs = sr.getAttributes();
                       NamingEnumeration e = attributs.getAll();
                           while(e.hasMore()){
                                  System.err.println(e.next());
                           }
 
	} | 
Partager