@Override protected void handleAttributes(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { if (entry.getAttribute(dnAttributeName) == null) { entry.addAttribute(new LdapAttribute(dnAttributeName, entry.getDn())); } else if (addIfExists) { entry.getAttribute(dnAttributeName).addStringValue(entry.getDn()); } }
@Override public String toString() { return String.format( "[dn=%s%s, responseControls=%s, messageId=%s]", getDn(), getAttributes(), Arrays.toString(responseControls), messageId); } }
/** * Creates a new entry. If the supplied search entry contains a {@link SyncStateControl} it is made available via * {@link #getSyncStateControl()}. * * @param entry to search for sync state control in */ public Entry(final SearchEntry entry) { searchEntry = entry; syncStateControl = (SyncStateControl) entry.getControl(SyncStateControl.OID); }
for (LdapAttribute la : entry.getAttributes()) { final LdapAttribute la = mEntry.getKey(); final Matcher matcher = mEntry.getValue(); final String msg = String.format("attribute '%s' entry '%s'", la.getName(), entry.getDn()); LdapAttribute newAttr = entry.getAttribute(attrTypeName); if (newAttr == null) { newAttr = new LdapAttribute(la.getSortBehavior(), la.isBinary()); newAttr.setName(attrTypeName); entry.addAttribute(newAttr); entry.removeAttribute(la); final SearchRequest sr = SearchRequest.newObjectScopeSearchRequest(entry.getDn(), new String[] {nextAttrID}); final SearchResult result = search.execute(sr).getResult(); entry.addAttributes(result.getEntry().getAttributes());
/** * Returns a search entry using the supplied apache ldap entry. * * @param e apache ldap entry * @param c response controls * @param id message id * * @return search entry */ public SearchEntry toSearchEntry(final Entry e, final ResponseControl[] c, final int id) { final SearchEntry se = new SearchEntry(id, c, sortBehavior); se.setDn(e.getDn().getName()); for (Attribute a : e) { se.addAttribute(toLdapAttribute(a)); } return se; }
@Override protected void handleAttributes(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { boolean newAttribute = false; LdapAttribute mergedAttribute = entry.getAttribute(mergeAttributeName); if (mergedAttribute == null) { mergedAttribute = new LdapAttribute(mergeAttributeName); newAttribute = true; } for (String s : attributeNames) { final LdapAttribute la = entry.getAttribute(s); if (la != null) { if (la.isBinary()) { mergedAttribute.addBinaryValues(la.getBinaryValues()); } else { mergedAttribute.addStringValues(la.getStringValues()); } } } if (mergedAttribute.size() > 0 && newAttribute) { entry.addAttribute(mergedAttribute); } }
@Override protected void handleAttributes(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { for (LdapAttribute la : entry.getAttributes()) { if (attributeName.equalsIgnoreCase(la.getName())) { if (la.isBinary()) { final LdapAttribute newAttr = new LdapAttribute(la.getSortBehavior()); newAttr.setName(la.getName()); for (byte[] b : la.getBinaryValues()) { newAttr.addStringValue(convertValue(b)); } entry.addAttribute(newAttr); logger.debug("Processed attribute {}", newAttr); handleAttribute(conn, request, newAttr); } else { logger.warn("Attribute {} must be set as a binary attribute", attributeName); handleAttribute(conn, request, la); } } else { handleAttribute(conn, request, la); } } }
@Override public HandlerResult<SearchEntry> handle(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { // Recursively searches a list of attributes and merges those results with // the existing entry. final List<String> searchedDns = new ArrayList<>(); if (entry.getAttribute(searchAttribute) != null) { searchedDns.add(entry.getDn()); readSearchAttribute(conn, entry, searchedDns); } else { recursiveSearch(conn, entry.getDn(), entry, searchedDns); } return new HandlerResult<>(entry); }
@Override public HandlerResult<SearchEntry> handle(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { if (entry != null) { entry.setDn(handleDn(conn, request, entry)); handleAttributes(conn, request, entry); } return new HandlerResult<>(entry); }
/** * Handle the dn of a search entry. * * @param conn the search was performed on * @param request used to find the search entry * @param entry search entry to extract the dn from * * @return handled dn */ protected String handleDn(final Connection conn, final SearchRequest request, final SearchEntry entry) { return entry.getDn(); }
@Override public ResponseControl getControl(final String oid) { if (getControls() != null) { for (ResponseControl c : getControls()) { if (c.getOID().equals(oid)) { return c; } } } return null; }
/** * Handle the attributes of a search entry. * * @param conn the search was performed on * @param request used to find the search entry * @param entry search entry to extract the attributes from * * @throws LdapException if the LDAP returns an error */ protected void handleAttributes(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { for (LdapAttribute la : entry.getAttributes()) { handleAttribute(conn, request, la); } }
@Override protected void handleAttributes(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { if (attributeNames == null) { super.handleAttributes(conn, request, entry); } else { for (String s : attributeNames) { final LdapAttribute la = entry.getAttribute(s); if (la != null) { handleAttribute(conn, request, la); } } } }
for (LdapAttribute la : entry.getAttributes()) { final LdapAttribute la = mEntry.getKey(); final Matcher matcher = mEntry.getValue(); final String msg = String.format("attribute '%s' entry '%s'", la.getName(), entry.getDn()); LdapAttribute newAttr = entry.getAttribute(attrTypeName); if (newAttr == null) { newAttr = new LdapAttribute(la.getSortBehavior(), la.isBinary()); newAttr.setName(attrTypeName); entry.addAttribute(newAttr); entry.removeAttribute(la); final SearchRequest sr = SearchRequest.newObjectScopeSearchRequest(entry.getDn(), new String[] {nextAttrID}); final SearchResult result = search.execute(sr).getResult(); entry.addAttributes(result.getEntry().getAttributes());
/** * Returns a search entry using the supplied jndi search result. * * @param result jndi search result * * @return search entry * * @throws NamingException if the search result cannot be read */ public SearchEntry toSearchEntry(final SearchResult result) throws NamingException { final SearchEntry se = new SearchEntry(-1, null, sortBehavior); se.setDn(result.getName()); final Attributes a = result.getAttributes(); final NamingEnumeration<? extends Attribute> ne = a.getAll(); while (ne.hasMore()) { se.addAttribute(toLdapAttribute(ne.next())); } return se; }
@Override protected void handleAttributes(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { boolean newAttribute = false; LdapAttribute mergedAttribute = entry.getAttribute(mergeAttributeName); if (mergedAttribute == null) { mergedAttribute = new LdapAttribute(mergeAttributeName); newAttribute = true; } for (String s : attributeNames) { final LdapAttribute la = entry.getAttribute(s); if (la != null) { if (la.isBinary()) { mergedAttribute.addBinaryValues(la.getBinaryValues()); } else { mergedAttribute.addStringValues(la.getStringValues()); } } } if (mergedAttribute.size() > 0 && newAttribute) { entry.addAttribute(mergedAttribute); } }
@Override protected void handleAttributes(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { for (LdapAttribute la : entry.getAttributes()) { if (attributeName.equalsIgnoreCase(la.getName())) { if (la.isBinary()) { final LdapAttribute newAttr = new LdapAttribute(la.getSortBehavior()); newAttr.setName(la.getName()); for (byte[] b : la.getBinaryValues()) { newAttr.addStringValue(convertValue(b)); } entry.addAttribute(newAttr); logger.debug("Processed attribute {}", newAttr); handleAttribute(conn, request, newAttr); } else { logger.warn("Attribute {} must be set as a binary attribute", attributeName); handleAttribute(conn, request, la); } } else { handleAttribute(conn, request, la); } } }
@Override public HandlerResult<SearchEntry> handle(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { // Recursively searches a list of attributes and merges those results with // the existing entry. final List<String> searchedDns = new ArrayList<>(); if (entry.getAttribute(searchAttribute) != null) { searchedDns.add(entry.getDn()); readSearchAttribute(conn, entry, searchedDns); } else { recursiveSearch(conn, entry.getDn(), entry, searchedDns); } return new HandlerResult<>(entry); }
@Override public HandlerResult<SearchEntry> handle(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { if (entry != null) { entry.setDn(handleDn(conn, request, entry)); handleAttributes(conn, request, entry); } return new HandlerResult<>(entry); }
/** * Handle the dn of a search entry. * * @param conn the search was performed on * @param request used to find the search entry * @param entry search entry to extract the dn from * * @return handled dn */ protected String handleDn(final Connection conn, final SearchRequest request, final SearchEntry entry) { return entry.getDn(); }