[JNDI/LDAP] Requête LDAP ordonnée
Bonjour,
je recupére une liste de compte dans l'active directory via JNDI. Cependant les comptes me vienne en vrac. Je voudrais ordonner les resultats suivant un attribut (leur code d'identification).
Je ne suis pas encore tres à l'aise avec JNDI et LDAP, votre aide me serait d'un grand secours ! :)
Mon code :
Code:
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
|
List<CompteAD> comptes = new ArrayList<CompteAD>();
try {
SearchControls sctrl = new SearchControls();
sctrl.setCountLimit(0);
String filter = "(&(sAMAccountName>=" + debut + "))";
NamingEnumeration answer = _ctx.search("", filter, sctrl);
while (answer.hasMore()) {
SearchResult sr = (SearchResult) answer.next();
Attributes attrs = sr.getAttributes();
CompteAD compte = new CompteAD();
compte.setCodeRedacteur((String)attrs.get("sAMAccountName").get());
if (attrs.get("streetAddress") != null)
compte.setAdresse((String)attrs.get("streetAddress").get());
if (attrs.get("postalCode") != null)
compte.setCodePostal((String)attrs.get("postalCode").get());
if (attrs.get("company") != null)
compte.setCompanie((String)attrs.get("company").get());
if (attrs.get("mobile") != null)
compte.setEMail((String)attrs.get("mobile").get());
if (attrs.get("postOfficeBox") != null)
compte.setLocalisation((String)attrs.get("postOfficeBox").get());
if (attrs.get("sn") != null)
compte.setNom((String)attrs.get("sn").get());
if (attrs.get("givenName") != null)
compte.setPrenom((String)attrs.get("givenName").get());
if (attrs.get("homePhone") != null)
compte.setTelephone((String)attrs.get("homePhone").get());
if (attrs.get("l") != null)
compte.setVille((String)attrs.get("l").get());
comptes.add(compte);
}
}
catch (SizeLimitExceededException e) {
return comptes;
}
catch (NamingException e) {
throw new TechnicalException(e);
}
return comptes; |
sAMAccountName étant l'attribut sur lequel je veux faire mon order by.
Merci d'avance !