@Override public Collection<String> getStringValues(final Object object) { return la.getStringValues(); }
/** * Returns a single string value of this attribute. See {@link #getStringValues()}. * * @return single string attribute value */ public String getStringValue() { final Collection<String> values = getStringValues(); if (values.isEmpty()) { return null; } return values.iterator().next(); }
/** * Returns a single string value of this attribute. See {@link #getStringValues()}. * * @return single string attribute value */ public String getStringValue() { final Collection<String> values = getStringValues(); if (values.isEmpty()) { return null; } return values.iterator().next(); }
/** * Returns a single string value of this attribute. See {@link #getStringValues()}. * * @return single string attribute value */ public String getStringValue() { final Collection<String> values = getStringValues(); if (values.isEmpty()) { return null; } return values.iterator().next(); }
/** * Iterates over the supplied attributes and returns all values as a set of ldap roles. * * @param attributes to read * * @return ldap roles */ public static Set<LdapRole> toRoles(final Collection<LdapAttribute> attributes) { final Set<LdapRole> r = new HashSet<>(); if (attributes != null) { for (LdapAttribute ldapAttr : attributes) { r.addAll(ldapAttr.getStringValues().stream().map(LdapRole::new).collect(Collectors.toList())); } } return r; } }
/** * Returns the RDN values for the attribute type with the supplied name. * * @param dn to parse * @param name of the attribute type to return values for * * @return DN attribute values */ public static Collection<String> getValues(final String dn, final String name) { final Collection<String> values = new ArrayList<>(); convertDnToAttributes(dn).stream().filter( la -> la.getName().equalsIgnoreCase(name)).forEach(la -> values.addAll(la.getStringValues())); return values; }
/** * Returns the RDN values for the attribute type with the supplied name. * * @param dn to parse * @param name of the attribute type to return values for * * @return DN attribute values */ public static Collection<String> getValues(final String dn, final String name) { final Collection<String> values = new ArrayList<>(); convertDnToAttributes(dn).stream().filter( la -> la.getName().equalsIgnoreCase(name)).forEach(la -> values.addAll(la.getStringValues())); return values; }
/** * Returns the RDN values for the attribute type with the supplied name. * * @param dn to parse * @param name of the attribute type to return values for * * @return DN attribute values */ public static Collection<String> getValues(final String dn, final String name) { final Collection<String> values = new ArrayList<>(); for (LdapAttribute la : convertDnToAttributes(dn)) { if (la.getName().equalsIgnoreCase(name)) { values.addAll(la.getStringValues()); } } return values; }
/** * Returns a <dsml:objectclass/> element for the supplied ldap attribute. * * @param doc to source elements from * @param attr ldap attribute to add * * @return element containing the attribute values */ protected Element createObjectclassElement(final Document doc, final LdapAttribute attr) { final Element ocElement = doc.createElement("dsml:objectclass"); for (String s : attr.getStringValues()) { final Element ocValueElement = doc.createElement("dsml:oc-value"); ocElement.appendChild(ocValueElement); setAttrValue(doc, ocValueElement, s, attr.isBinary()); } return ocElement; }
/** * Returns a <dsml:objectclass/> element for the supplied ldap attribute. * * @param doc to source elements from * @param attr ldap attribute to add * * @return element containing the attribute values */ protected Element createObjectclassElement(final Document doc, final LdapAttribute attr) { final Element ocElement = doc.createElement("dsml:objectclass"); for (String s : attr.getStringValues()) { final Element ocValueElement = doc.createElement("dsml:oc-value"); ocElement.appendChild(ocValueElement); setAttrValue(doc, ocValueElement, s, attr.isBinary()); } return ocElement; }
/** * Returns the values of this attribute decoded by the supplied transcoder. * * @param <T> type of decoded attributes * @param transcoder to decode attribute values with * * @return collection of decoded attribute values */ public <T> Collection<T> getValues(final ValueTranscoder<T> transcoder) { final Collection<T> values = createSortBehaviorCollection(transcoder.getType()); if (isBinary()) { values.addAll(getBinaryValues().stream().map(transcoder::decodeBinaryValue).collect(Collectors.toList())); } else { values.addAll(getStringValues().stream().map(transcoder::decodeStringValue).collect(Collectors.toList())); } return values; }
protected Map<String, Object> getAttributesFromEntry(final LdapEntry entry) { final Map<String, Object> attributes = new HashMap<>(); for (final LdapAttribute attribute : entry.getAttributes()) { final String name = attribute.getName(); if (attribute.size() > 1) { attributes.put(name, attribute.getStringValues()); } else { attributes.put(name, attribute.getStringValue()); } } return attributes; }
/** * Converts an ldaptive <code>LdapEntry</code> containing result entry attributes into an attribute map as needed * by Person Directory components. * * @param entry Ldap entry. * @return Attribute map. */ private Map<String, List<Object>> convertLdapEntryToMap(final LdapEntry entry) { final Map<String, List<Object>> attributeMap = new LinkedHashMap<>(entry.size()); for (final LdapAttribute attr : entry.getAttributes()) { attributeMap.put(attr.getName(), new ArrayList<Object>(attr.getStringValues())); } logger.debug("Converted ldap DN entry [{}] to attribute map {}", entry.getDn(), attributeMap.toString()); return attributeMap; }
/** * Returns a <dsml:attr/> element for the supplied ldap attribute. * * @param doc to source elements from * @param attr ldap attribute to add * * @return element containing the attribute */ protected Element createAttrElement(final Document doc, final LdapAttribute attr) { final Element attrElement = doc.createElement("dsml:attr"); attrElement.setAttribute("name", attr.getName()); for (String s : attr.getStringValues()) { final Element valueElement = doc.createElement("dsml:value"); attrElement.appendChild(valueElement); setAttrValue(doc, valueElement, s, attr.isBinary()); } return attrElement; }
/** * Converts an ldaptive <code>LdapEntry</code> containing result entry attributes into an attribute map as needed * by Person Directory components. * * @param entry Ldap entry. * * @return Attribute map. */ private Map<String, List<Object>> convertLdapEntryToMap(final LdapEntry entry) { final Map<String, List<Object>> attributeMap = new LinkedHashMap<>(entry.size()); for (final LdapAttribute attr : entry.getAttributes()) { attributeMap.put(attr.getName(), new ArrayList<Object>(attr.getStringValues())); } logger.debug("Converted ldap DN entry [{}] to attribute map {}", entry.getDn(), attributeMap.toString()); return attributeMap; }
@Override public JsonElement serialize(final SearchResult result, final Type type, final JsonSerializationContext context) { final JsonArray json = new JsonArray(); for (LdapEntry entry : result.getEntries()) { final JsonObject jsonEntry = new JsonObject(); jsonEntry.add("dn", entry.getDn() != null ? new JsonPrimitive(entry.getDn()) : null); for (LdapAttribute attr : entry.getAttributes()) { final JsonArray jsonAttrValues = new JsonArray(); attr.getStringValues().forEach(jsonAttrValues::add); jsonEntry.add(attr.getName(), jsonAttrValues); } json.add(jsonEntry); } return json; } }
/** * Returns a jndi attribute that represents the values in the supplied ldap attribute. * * @param attr ldap attribute * * @return jndi attribute */ public Attribute fromLdapAttribute(final LdapAttribute attr) { final Attribute attribute = new BasicAttribute(attr.getName()); if (attr.isBinary()) { attr.getBinaryValues().forEach(attribute::add); } else { attr.getStringValues().forEach(attribute::add); } return attribute; }
/** Tests ordered sort behavior. */ @Test(groups = {"bean"}) public void orderedSortBehavior() { final LdapAttribute la = new LdapAttribute(SortBehavior.ORDERED); AssertJUnit.assertEquals(SortBehavior.ORDERED, la.getSortBehavior()); la.addStringValue("William", "Bill"); final String[] values = la.getStringValues().toArray(new String[2]); AssertJUnit.assertEquals("William", values[0]); AssertJUnit.assertEquals("Bill", values[1]); la.clear(); AssertJUnit.assertEquals(0, la.size()); }
/** Tests sorted sort behavior. */ @Test(groups = {"bean"}) public void sortedSortBehavior() { final LdapAttribute la = new LdapAttribute(SortBehavior.SORTED); AssertJUnit.assertEquals(SortBehavior.SORTED, la.getSortBehavior()); la.addStringValue("William", "Bill"); final String[] values = la.getStringValues().toArray(new String[2]); AssertJUnit.assertEquals("Bill", values[0]); AssertJUnit.assertEquals("William", values[1]); la.clear(); AssertJUnit.assertEquals(0, la.size()); }
/** Tests create with two values. */ @Test(groups = {"bean"}) public void createTwo() { final LdapAttribute la = new LdapAttribute("givenName", "Bill", "William"); AssertJUnit.assertEquals(2, la.getStringValues().size()); AssertJUnit.assertEquals(2, la.size()); AssertJUnit.assertEquals(la, new LdapAttribute("givenName", "William", "Bill")); la.removeStringValue("William"); AssertJUnit.assertEquals(1, la.size()); la.clear(); AssertJUnit.assertEquals(0, la.size()); }