active directory - Java how to get get an Attribute from ldap using the DN? -
i have java application use search groups. works pretty search based on group name (cn) more 1 result since same cn used in other branches. have dn of group , wondering how search based on dn or if it's possible access attribute directly since have full path. here code use :
public group getgroup( string groupname) throws exception { list<user> memberlist = new arraylist<user>(); // create search controls searchcontrols searchctls = new searchcontrols(); // specify search scope searchctls.setsearchscope( searchcontrols.subtree_scope ); // specify attributes return string returnedatts[] = { member_field }; searchctls.setreturningattributes( returnedatts ); // specify ldap search filter string searchfilter = "(&(objectclass=group)(cn=" + groupname + "))"; // search objects using filter namingenumeration<searchresult> answer = ctxmap.get( configmap.get( group ) ).search( configmap.get( searchbase ), searchfilter, searchctls ); searchresult sr = null; // loop through search results while ( answer.hasmoreelements() ) { sr = (searchresult) answer.next(); } if ( sr == null ) { return group; } // create attribute memberof javax.naming.directory.attribute member = sr.getattributes().get( member_field ); // enumeration of elements in memberof namingenumeration<?> ne = member.getall(); // loop though enumeration, cut unwanted characters , add // elements user list while ( ne.hasmoreelements() ) { ... } }
so want pass group's distinguished name parameter function instead of group's name , have search made on or attributes directly. possible?
ps: code used members of group.
thank you
you don't need search if have dn. up, lookup().
Comments
Post a Comment