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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
DirContext dirContext;
try {
dirContext = new InitialDirContext(env);
String MY_SEARCHBASE = "ou=***";
NamingEnumeration nameEnum = dirContext.list(MY_SEARCHBASE);
//creer attribut pour comparaison
Attribute attributCompar = new BasicAttribute("FonctA");
attributCompar.add("truc");
log.info("attributCompar " +attributCompar.get());
// pour chaque entree du contexte
// while (nameEnum.hasMoreElements()) {
while (nameEnum != null && nameEnum.hasMore()) {
NameClassPair sr = (NameClassPair)nameEnum.next( ) ;
String dn = sr.getName( ) ;
// System.out.println( "Le DN est " + dn ) ;
// on recuperere le sous contexte
Attributes attributs = dirContext
.getAttributes(sr.getName()+" , "
+MY_SEARCHBASE);
if (attributs.get("FonctA") != null) {
if (attributs.get("FonctA").get(0).equals(attributCompar) ==
true) {
// // Attribute attribut = (Attribute)
// attributs.get("description");
log.info(attributs.get("cn"));
log.info(attributs.get("FonctA").get(0));
System.out.println("\n ");
}
}
}
dirContext.close();
} catch (NamingException e) {
System.err.println("Erreur lors de l'acces au serveur LDAP" + e);
e.printStackTrace();
} |
Partager