@Override public String getDn() { return elem.getDN(); } }
private LdapAccount accountFromEntry(SearchResultEntry entry) { LdapAccount account = new LdapAccount(); account.setUsername(entry.getAttributeValue("uid")); String[] emails = entry.getAttributeValues("mail"); account.setEmails(emails != null ? new HashSet<>(Arrays.asList(emails)) : Collections.emptySet()); account.setGivenName(entry.getAttributeValue("givenName")); account.setFamilyName(entry.getAttributeValue("sn")); account.setSubject(entry.getAttributeValue("employeeNumber")); account.setName(entry.getAttributeValue("cn")); account.setRole(LdapAccount.Role.valueOf(entry.getAttributeValue("employeeType"))); return account; } }
@Nullable private String getAttribute(@NotNull SearchResultEntry entry, @NotNull String name) { Attribute attribute = entry.getAttribute(name); return attribute == null ? null : attribute.getValue(); }
/** * {@inheritDoc} */ public void searchEntryReturned(final SearchResultEntry searchEntry) { SearchResultEntry sre; if (entryTransformations == null) { sre = searchEntry; } else { Entry e = searchEntry; for (final EntryTransformation t : entryTransformations) { e = t.transformEntry(e); } sre = new SearchResultEntry(searchEntry.getMessageID(), e, searchEntry.getControls()); } outputHandler.formatSearchResultEntry(sre); }
/** * {@inheritDoc} */ @Override() public void formatSearchResultEntry(final SearchResultEntry entry) { columnValues[0] = entry.getDN(); int i=1; for (final String attribute : attributes) { final String value = entry.getAttributeValue(attribute); if (value == null) { columnValues[i] = ""; } else { columnValues[i] = value; } i++; } ldapSearch.writeOut(formatter.formatRow(columnValues)); }
private void setAccountRoles(LDAPConnection ldapConnection, SearchResultEntry accountSearchResult, Account account) { String accountDN = accountSearchResult.getDN(); String groupMemberPattern = this.groupMemberPattern.replace("${dn}", escapeLDAPSearchFilter(accountDN)); groupMemberPattern = groupMemberPattern.replace("${username}", escapeLDAPSearchFilter(account.getUsername())); // Fill in attributes into groupMemberPattern for (Attribute attribute : accountSearchResult.getAttributes()) { groupMemberPattern = groupMemberPattern.replace("${" + attribute.getName() + "}", escapeLDAPSearchFilter(attribute.getValue())); } SearchResult groupsSearchResult = doSearch(ldapConnection, groupBase, true, groupMemberPattern, Arrays.asList("cn")); if (groupsSearchResult != null && groupsSearchResult.getEntryCount() > 0) { for (int i = 0; i < groupsSearchResult.getEntryCount(); i++) { SearchResultEntry groupEntry = groupsSearchResult.getSearchEntries().get(i); String roleName = groupEntry.getAttribute("cn").getValue(); account.getAuthorizations().addRole(roleName); } } }
/** * Read group from LDAP. If there is no group it returns NULL. * * @param groupName name of gruop * @param conn ldap connection * @return LDAP group or null if there is no group * @throws LDAPException */ protected LdapGroup getGroup(String groupName, LDAPConnection conn) throws LdapSystemException { try { LdapGroup result = null; String baseDN = config.getLdapGroupsBaseDN(); Filter groupFilter = Filter.createEqualityFilter(GROUP_NAME_ATTR, groupName); SearchResultEntry entry = conn.searchForEntry(baseDN, ONE, groupFilter, GROUP_NAME_ATTR, config.getLdapGroupsMemberAttr(), GROUP_DESC_ATTR); if (entry != null) { String dn = entry.getDN(); String name = entry.getAttributeValue(GROUP_NAME_ATTR); String description = entry.getAttributeValue(GROUP_DESC_ATTR); Set<String> members = new HashSet<>(Arrays.asList(entry.getAttributeValues(config.getLdapGroupsMemberAttr()))); result = new LdapGroup(name, dn, description, members); } return result; } catch (LDAPException e) { throw new LdapSystemException(e); } }
/** * {@inheritDoc} */ public void searchEntryReturned(final SearchResultEntry searchEntry) { entryCounter.incrementAndGet(); // Make sure we haven't already seen this entry. We shouldn't get the same // entry multiple times in the course of processing a search, but if we got // a failure while processing the search, we might re-try it and get some of // the same entries back. DN parsedDN = null; try { parsedDN = searchEntry.getParsedDN(); if (dnsProcessed.containsKey(parsedDN)) { return; } } catch (final Exception e) { Debug.debugException(e); } manageAccountProcessor.process(searchEntry.getDN()); if (parsedDN != null) { dnsProcessed.put(parsedDN, parsedDN); } }
buffer.append(getDN()); buffer.append('\''); final Iterator<Attribute> iterator = getAttributes().iterator();
/** * {@inheritDoc} */ @Override() public void formatSearchResultEntry(final SearchResultEntry entry) { jsonBuffer.clear(); jsonBuffer.beginObject(); jsonBuffer.appendString("result-type", "entry"); jsonBuffer.appendString("dn", entry.getDN()); jsonBuffer.beginArray("attributes"); for (final Attribute a : entry.getAttributes()) { jsonBuffer.beginObject(); jsonBuffer.appendString("name", a.getName()); jsonBuffer.beginArray("values"); for (final String value : a.getValues()) { jsonBuffer.appendString(value); } jsonBuffer.endArray(); jsonBuffer.endObject(); } jsonBuffer.endArray(); handleControls(entry.getControls()); jsonBuffer.endObject(); ldapSearch.writeOut(jsonBuffer.toString()); }
for (Attribute userAttribute : userSearchResult.getAttributes()) { pattern = pattern.replace("${" + userAttribute.getName() + "}", userAttribute.getValue()); } else { Attribute attribute = userSearchResult.getAttribute(nameMapping); if (attribute != null && attribute.hasValue()) { account.setName(attribute.getValue()); for (Attribute userAttribute : userSearchResult.getAttributes()) { pattern = pattern.replace("${" + userAttribute.getName() + "}", userAttribute.getValue()); } else { Attribute attribute = userSearchResult.getAttribute(emailMapping); if (attribute != null && attribute.hasValue()) { account.addEmailAddress(attribute.getValue());
List<String> getRoles() throws LDAPException { final SearchRequest searchRequest = new SearchRequest( roleBaseDN, ONE, "(uniqueMember=" + userDN + ")", CN); final SearchResult searchResult = ldapInterface.search(searchRequest); return searchResult.getSearchEntries() .stream() .flatMap(entry -> stream(entry.getAttributeValues("CN"))) .collect(toList()); }
searchEntry.getAttributesWithOptions(attributes[i], null); if (l1 != null) searchEntry.getAttributesWithOptions(attributes[j], null); if (l2 != null) " of entry '", searchEntry.getDN(), " is also present in attribute ", a2.getName(), " of the same entry."); searchEntry.getAttributesWithOptions(attrName, null); for (final Attribute a : attrList) new CancelExtendedRequest(searchEntry.getMessageID())); if (DN.equals(searchEntry.getDN(), e.getDN())) " of entry '" + searchEntry.getDN(), "' is also present in entry '", e.getDN(), "'."); conflictCounts.get(attrName).incrementAndGet(); break baseDNLoop; "' (as found in entry '" + searchEntry.getDN() + "') below '" + baseDN + "': " + searchResult.getDiagnosticMessage());
searchEntry.getAttributesWithOptions(attr, null); for (final Attribute a : attrList) if (e == null) err("Entry '", searchEntry.getDN(), "' includes attribute ", a.getName(), " that references entry '", value, "' which does not exist."); err("An error occurred while attempting to determine whether " + "entry '" + value + "' referenced in attribute " + a.getName() + " of entry '" + searchEntry.getDN() + "' exists: " + StaticUtils.getExceptionMessage(le)); missingReferenceCounts.get(attr).incrementAndGet();
/** * Verify that the entry identified by {@code dn} has an attribute named {@code attributeName} with * the attribute value(s) {@code attributeName}. * * @param dn The distinguished name. * @param attributeName The attribute name. * @param attributeValue The attribute value(s). * @return {@code true} if an antry identified by {@code dn} exists with an an attribute named {@code attributeName} * that has value(s) {@code attributeValue}. Otherwise, {@code false} is returned. */ public boolean verifyDNHasAttributeValue(final String dn, final String attributeName, final String... attributeValue) { try { final SearchResultEntry entry = connection.getEntry(dn, attributeName); if (entry != null && entry.hasAttribute(attributeName)) { final Set<String> expectedValues = new HashSet<String>(Arrays.asList(attributeValue)); final Set<String> actualValues = new HashSet<String>(Arrays.asList(entry.getAttributeValues(attributeName))); if (actualValues.containsAll(expectedValues)) { actualValues.removeAll(expectedValues); if (actualValues.size() == 0) { return true; } } } } catch (final LDAPException e) { throw new DirectoryTesterException("Error communicating with LDAP directory server", e); } return false; }
@Override public List<ILdapAttribute> getAttributes() { if (attributes == null) { attributes = new ArrayList<>(elem.getAttributes().size()); for (Attribute e : elem.getAttributes()) { attributes.add(new DefaultLdapAttribute(e)); } } return attributes; }
private UserInfo getUserInfo(SearchResultEntry entry) { UserInfo result = new UserInfo(); result.setUserId(entry.getAttributeValue("cn")); String name = entry.getAttributeValue(givenNameAttribute); String name2 = entry.getAttributeValue(surNameAttribute); if (null != name) { if (null != name2) { name = name + " " + name2; } } else { name = name2; } result.setUserName(name); result.setUserLocale(entry.getAttributeValue(localeAttribute)); result.setUserOrganization(entry.getAttributeValue(organizationAttribute)); result.setUserDivision(entry.getAttributeValue(divisionAttribute)); result.setRoles(getRoles(entry)); return result; }
/** * Creates a search result entry from this protocol op. * * @param controls The set of controls to include in the search result * entry. It may be empty or {@code null} if no controls * should be included. * * @return The search result entry that was created. */ public SearchResultEntry toSearchResultEntry(final Control... controls) { return new SearchResultEntry(dn, attributes, controls); }
for (final SearchResultEntry e : searchEntries) if (parsedDN.equals(e.getParsedDN()))
private void setAccountRoles(LDAPConnection ldapConnection, SearchResultEntry accountSearchResult, Account account) { String accountDN = accountSearchResult.getDN(); String groupMemberPattern = this.groupMemberPattern.replace("${dn}", escapeLDAPSearchFilter(accountDN)); groupMemberPattern = groupMemberPattern.replace("${username}", escapeLDAPSearchFilter(account.getUsername())); // Fill in attributes into groupMemberPattern for (Attribute attribute : accountSearchResult.getAttributes()) { groupMemberPattern = groupMemberPattern.replace("${" + attribute.getName() + "}", escapeLDAPSearchFilter(attribute.getValue())); } SearchResult groupsSearchResult = doSearch(ldapConnection, groupBase, true, groupMemberPattern, Arrays.asList("cn")); if (groupsSearchResult != null && groupsSearchResult.getEntryCount() > 0) { for (int i = 0; i < groupsSearchResult.getEntryCount(); i++) { SearchResultEntry groupEntry = groupsSearchResult.getSearchEntries().get(i); String roleName = groupEntry.getAttribute("cn").getValue(); account.getAuthorizations().addRole(roleName); } } }