private boolean handleEndOfResults() { if (!lsr.hasMore()) { return true; } return false; } private Object readValue(LDAPAttribute att) {
public Map<String, Object> get() { if (handleEndOfResults()) return null; try { Map<String, Object> entry = new LinkedHashMap<>(attributes.size() + 1); LDAPEntry en = null; en = lsr.next(); entry.put("dn", en.getDN()); if (attributes != null && attributes.size() > 0) { for (int col = 0; col < attributes.size(); col++) { Object val = readValue(en.getAttributeSet().getAttribute(attributes.get(col))); if (val != null) entry.put(attributes.get(col),val ); } } else { // make it dynamic Iterator<LDAPAttribute> iter = en.getAttributeSet().iterator(); while (iter.hasNext()) { LDAPAttribute attr = iter.next(); Object val = readValue(attr); if (val != null) entry.put(attr.getName(), readValue(attr)); } } //System.out.println("entry " + entry); return entry; } catch (LDAPException e) { e.printStackTrace(); throw new RuntimeException("Error getting next ldap entry " + e.getLDAPErrorMessage()); } }
/** * Returns a count of the entries in the search result. * * @see <a href="../../../../api/com/novell/ldap/LDAPSearchResults.html#getCount()"> com.novell.ldap.LDAPSearchResults.getCount()</a> */ public int getCount() { return results.getCount(); }
if (result.hasMore()) { try { resultEntry = result.next(); } catch (LDAPException e) { LOGGER.debug("Failed to get group members", e); isGroup |= getGroupMembers(memberMap, subgroups, resultEntry, context); resultEntry = result.hasMore() ? result.next() : null; } catch (LDAPException e) { LOGGER.debug("Failed to get group members", e);
buff.append(ValueXMLhandler.newLine(1)); while (hasMore()){ LDAPEntry entry = null; try{ entry = (LDAPEntry)next(); }catch(LDAPException le){ writeAttribute( (LDAPAttribute) i.next(),buff); LDAPControl[] controls = getResponseControls(); if ( controls != null ) { for( int i = 0; i < controls.length; i++ ) { writeControl(controls[i], buff);
/** * Returns the latest server controls returned by the server * in the context of this search request, or null * if no server controls were returned. * * @see <a href="../../../../api/com/novell/ldap/LDAPSearchResults.html#getResponseControls()"> com.novell.ldap.LDAPSearchResults.getResponseControls()</a> */ public LDAPControl[] getResponseControls() { com.novell.ldap.LDAPControl[] controls = results.getResponseControls(); if( controls == null) { return null; } LDAPControl[] ietfControls = new LDAPControl[controls.length]; for( int i=0; i < controls.length; i++) { ietfControls[i] = new LDAPControl( controls[i]); } return ietfControls; }
private void readData() { searchResults = new LDAPSearchResults(); try { Thread.sleep(450); } catch (InterruptedException ex) { Logger.getLogger(Profylaxia.class.getName()).log(Level.SEVERE, null, ex); } try { searchResults = lc.search(searchBase, searchScope, searchFilter, null, false); try { Thread.sleep(500); } catch (InterruptedException ex) { Logger.getLogger(Profylaxia.class.getName()).log(Level.SEVERE, null, ex); } int noResult = searchResults.getCount(); System.out.println(" noResult : " + noResult);
LDAPConnection conn = new LDAPConnection(); conn.connect("blah.blah.address", 389); String[] attrIDs = {"uniqueMember"}; LDAPSearchResults search = conn.search("dc=foo,dc=bar", LDAPConnection.SCOPE_ONE, "cn=testgroup", attrIDs, false); while(search.hasMore()) { LDAPEntry entry = search.next(); for (String string : entry.getAttribute("uniqueMember").getStringValueArray()) { System.out.println(string); } }
lc.connect( ldapHost, ldapPort ); lc.bind( ldapVersion, loginDN, password.getBytes("UTF8")); LDAPControl ldapCtrl = new LDAPControl("1.3.6.1.4.1.637.81.2.10.10", false, null); LDAPSearchConstraints cons = lc.getSearchConstraints(); cons.setControls( ldapCtrl ); lc.setConstraints(cons); LDAPSearchResults searchResults = lc.search("",LDAPConnection.SCOPE_BASE, "(objectclass=*)", returnedAttributes,attributeOnly , cons); LDAPControl[] controls = searchResults.getResponseControls();
return new LDAPSearchResults(this, queue, cons);
/** * Reports if there are more search results. * * @see <a href="../../../../api/com/novell/ldap/LDAPSearchResults.html#hasMore()"> com.novell.ldap.LDAPSearchResults.hasMoreElements()</a> */ public boolean hasMore() { return results.hasMore(); }
@Test public void testLoadLDAP() throws Exception { Map<String, Object> connParms = new HashMap<>(); connParms.put("ldapHost", "ldap.forumsys.com"); connParms.put("ldapPort", 389l); connParms.put("loginDN", "cn=read-only-admin,dc=example,dc=com"); connParms.put("loginPW", "password"); LoadLdap.LDAPManager mgr = new LoadLdap.LDAPManager(LoadLdap.getConnectionMap(connParms)); Map<String, Object> searchParms = new HashMap<>(); searchParms.put("searchBase", "dc=example,dc=com"); searchParms.put("searchScope", "SCOPE_ONE"); searchParms.put("searchFilter", "(&(objectClass=*)(uid=training))"); ArrayList<String> ats = new ArrayList<>(); ats.add("uid"); searchParms.put("attributes", ats); LDAPSearchResults results = mgr.doSearch(searchParms); LDAPEntry le = results.next(); assertEquals("uid=training,dc=example,dc=com", le.getDN()); assertEquals("training", le.getAttribute("uid").getStringValue()); }
isGroup = getGroupMembersSearchResult(result, memberMap, subgroups, context); } finally { if (result.hasMore()) { try { getConnection().getConnection().abandon(result);
/** * Returns the next result as an LDAPEntry. * * @see <a href="../../../../api/com/novell/ldap/LDAPSearchResults.html#next()"> com.novell.ldap.LDAPSearchResults.next()</a> */ public LDAPEntry next() throws LDAPException { try { return new LDAPEntry( results.next()); } catch( com.novell.ldap.LDAPException ex) { if( ex instanceof com.novell.ldap.LDAPReferralException) { throw new LDAPReferralException( (com.novell.ldap.LDAPReferralException)ex); } else { throw new LDAPException( ex); } } } }
isGroup = getGroupMembersSearchResult(result, memberMap, subgroups, context); } finally { if (result.hasMore()) { try { getConnection().getConnection().abandon(result);