spring security - How to get all LDAP users with LdapTemplate -


i'm using spring-security , wish retrieve users , groups stored in reference table can users without having consult ldap directory. have created ldapauthoritiespopulator implementation mirroring defaultldapauthoritiespopulator following additional method:

public final collection<grantedauthority> getallauthorities() {     if (groupsearchbase == null) {         return new hashset<>();     }     set<grantedauthority> authorities = new hashset<>();     set<string> roles = ldaptemplate.searchforsingleattributevalues(             groupsearchbase,             allauthorityfilter,             new string[0],             grouproleattribute);     (string role : roles) {         if (converttouppercase) {             role = role.touppercase();         }         authorities.add(new simplegrantedauthority(roleprefix + role));     }     return authorities; } 

this allows me retrieve groups, allauthorityfilter property defaulting (&(objectclass=group)(objectcategory=group)).

i trying achieve same thing users creating custom ldapusersearch based of of filterbasedldapusersearch following additional method:

public list<string> findallusers() {     springsecurityldaptemplate template             = new springsecurityldaptemplate(contextsource);     template.setsearchcontrols(searchcontrols);     list<string> r = template.search(searchbase,                                      allusersfilter,                                      new attributesmapper() {         @override         public object mapfromattributes(attributes atrbts)                 throws namingexception {             return (string) atrbts.get(usernameattribute).get();         }     });     return r; } 

there 2 problems have this:

  1. if user-list large javax.naming.sizelimitexceededexception not know how resolve.
  2. i want method return dircontextoperations similar how searchforuser(string) works ldapuserdetailsmapper implementation can reused return user properties.

i'm finding documentation ldaptemplate little hairy , having trouble finding answers i'm after, assistance appreciated.

update: have solved point (2) above

public list<userdetails> getalluserdetails(boolean includeauthorities) {     list<userdetails> r = new arraylist<>();     (dircontextoperations ctx : usersearch.findalluseroperations()) {         try {             attribute att = ctx.getattributes().get(usernameattribute);             string username = (string) att.get();             r.add(usermapper.mapuserfromcontext(                     ctx,                     username,                     includeauthorities                         ? authpop.getgrantedauthorities(ctx, username)                         : collections.<grantedauthority>emptyset()));         } catch (namingexception ex) {             log.warn("username attribute " + usernameattribute + " not found!");         }     }     return r; } 

in usersearch implementation have:

public list<dircontextoperations> findalluseroperations() {     springsecurityldaptemplate template = new springsecurityldaptemplate(contextsource);     template.setsearchcontrols(searchcontrols);     return template.search(searchbase,                            allusersfilter, new contextmapper() {         @override         public object mapfromcontext(object o) {             return (dircontextoperations) o;         }     }); } 

however have not solved point #1. if need batch somehow fine long there way tell ldaptemplate resume on subsequent calls.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -