@Override public boolean isBinary() { return la.isBinary(); }
/** * 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; }
/** * 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; }
/** * 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: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; }
/** * 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; }
@Override protected void writeResponse(final SearchResult result, final HttpServletResponse response) throws IOException { final LdapEntry e = result.getEntry(); if (e != null && e.size() > 0) { final LdapAttribute a = e.getAttribute(); if (a != null && a.size() > 0) { if (a.isBinary()) { response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s.bin\"", a.getName())); } else { response.setContentType("text/plain"); } final OutputStream out = response.getOutputStream(); out.write(a.getBinaryValue()); out.flush(); } } } }
@Override protected void writeResponse(final SearchResult result, final HttpServletResponse response) throws IOException { final LdapEntry e = result.getEntry(); if (e != null && e.size() > 0) { final LdapAttribute a = e.getAttribute(); if (a != null && a.size() > 0) { if (a.isBinary()) { response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s.bin\"", a.getName())); } else { response.setContentType("text/plain"); } final OutputStream out = response.getOutputStream(); out.write(a.getBinaryValue()); out.flush(); } } } }
/** * 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; }
/** * 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; }
/** * Reads the values of {@link #searchAttribute} from the supplied attributes and calls {@link #recursiveSearch} for * each. * * @param conn to perform search operation on * @param entry to read * @param searchedDns list of DNs whose attributes have been read * * @throws LdapException if a search error occurs */ private void readSearchAttribute(final Connection conn, final LdapEntry entry, final List<String> searchedDns) throws LdapException { if (entry != null) { final LdapAttribute attr = entry.getAttribute(searchAttribute); if (attr != null && !attr.isBinary()) { final Set<String> values = new HashSet<>(attr.getStringValues()); for (String s : values) { recursiveSearch(conn, s, entry, searchedDns); } } } }
/** * 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()) { for (byte[] b : getBinaryValues()) { values.add(transcoder.decodeBinaryValue(b)); } } else { for (String s : getStringValues()) { values.add(transcoder.decodeStringValue(s)); } } return values; }
/** * Adds the supplied values for this attribute by encoding them with the supplied transcoder. * * @param <T> type attribute to encode * @param transcoder to encode value with * @param value to encode and add * * @throws NullPointerException if value is null */ @SuppressWarnings("unchecked") public <T> void addValue(final ValueTranscoder<T> transcoder, final T... value) { for (T t : value) { if (isBinary()) { attributeValues.add(transcoder.encodeBinaryValue(t)); } else { attributeValues.add(transcoder.encodeStringValue(t)); } } }
/** * Adds the supplied values for this attribute by encoding them with the supplied transcoder. * * @param <T> type attribute to encode * @param transcoder to encode value with * @param value to encode and add * * @throws NullPointerException if value is null */ @SuppressWarnings("unchecked") public <T> void addValue(final ValueTranscoder<T> transcoder, final T... value) { for (T t : value) { if (isBinary()) { attributeValues.add(transcoder.encodeBinaryValue(t)); } else { attributeValues.add(transcoder.encodeStringValue(t)); } } }
/** * Adds the supplied values for this attribute by encoding them with the supplied transcoder. * * @param <T> type attribute to encode * @param transcoder to encode value with * @param value to encode and add * * @throws NullPointerException if value is null */ @SuppressWarnings("unchecked") public <T> void addValue(final ValueTranscoder<T> transcoder, final T... value) { for (T t : value) { if (isBinary()) { attributeValues.add(transcoder.encodeBinaryValue(t)); } else { attributeValues.add(transcoder.encodeStringValue(t)); } } }
/** * 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()) { for (byte[] value : attr.getBinaryValues()) { attribute.add(value); } } else { for (String value : attr.getStringValues()) { attribute.add(value); } } return attribute; }
@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); } } }
/** * Returns an apache ldap attribute that represents the values in the supplied ldap attribute. * * @param la ldap attribute * * @return apache ldap attribute */ public Attribute fromLdapAttribute(final LdapAttribute la) { final DefaultAttribute attribute = new DefaultAttribute(la.getName()); if (la.isBinary()) { for (byte[] value : la.getBinaryValues()) { attribute.add(createValue(value)); } } else { for (String value : la.getStringValues()) { attribute.add(createValue(value)); } } return attribute; }