Java Reference
In-Depth Information
public Vector search(String[] returnAttributes, String searchFilter)
throws NamingException {
Vector ldapObjects = new Vector();
SearchControls ctls = new SearchControls();
NamingEnumeration results = null;
// bind to the LDAP server.
DirContext ctx = getInitialContext(getEnvironment());
// perform the search on the LDAP server.
results =, searchFilter, ctls);
while ((results != null) && (results.hasMore())) {
// get the next set of results from the search.
SearchResult sr = (SearchResult);
// get all of the attributes for this object.
Attributes attributes = sr.getAttributes();
NamingEnumeration attEnum = attributes.getAll();
// create an LDAPObject to hold the results.
LDAPObject tmpObj = new LDAPObject();
// set the Distinguished Name for the object. Append
// the relative dn and the searcb base together.
tmpObj.setDn(sr.getName() + “,” + searchBase);
// iterate through the attributes setting them in the LDAPObject
while (attEnum.hasMore()) {
// get the next attribute
Attribute att = (Attribute);
// set the attribute in the LDAPObject
tmpObj.setAttribute(att.getID(), att.get());
// add the object to the list of return objects
return ldapObjects;
* Updates the given object in the LDAP server.
Search WWH ::

Custom Search