/** * Creates a new ldap attribute. * * @param name of this attribute */ public LdapAttribute(final String name) { this(); setName(name); }
/** * Creates a new ldap attribute. * * @param name of this attribute */ public LdapAttribute(final String name) { this(); setName(name); }
/** * Creates a new ldap attribute. * * @param name of this attribute */ public LdapAttribute(final String name) { this(); setName(name); }
/** * Creates a new ldap attribute. * * @param name of this attribute * @param values of this attribute */ public LdapAttribute(final String name, final String... values) { this(false); setName(name); addStringValue(values); }
/** * Creates a new ldap attribute. * * @param name of this attribute * @param values of this attribute */ public LdapAttribute(final String name, final byte[]... values) { this(true); setName(name); addBinaryValue(values); }
/** * Creates a new ldap attribute. * * @param name of this attribute * @param values of this attribute */ public LdapAttribute(final String name, final byte[]... values) { this(true); setName(name); addBinaryValue(values); }
/** * Creates a new ldap attribute. * * @param name of this attribute * @param values of this attribute */ public LdapAttribute(final String name, final String... values) { this(false); setName(name); addStringValue(values); }
/** * Creates a new ldap attribute. * * @param name of this attribute * @param values of this attribute */ public LdapAttribute(final String name, final byte[]... values) { this(true); setName(name); addBinaryValue(values); }
/** * Creates a new ldap attribute. * * @param name of this attribute * @param values of this attribute */ public LdapAttribute(final String name, final String... values) { this(false); setName(name); addStringValue(values); }
@Override public SearchResult deserialize(final JsonElement json, final Type type, final JsonDeserializationContext context) throws JsonParseException { final SearchResult result = new SearchResult(sortBehavior); final JsonArray jsonResult = json.getAsJsonArray(); for (JsonElement jsonEntry : jsonResult) { final LdapEntry entry = new LdapEntry(sortBehavior); for (Map.Entry<String, JsonElement> jsonAttr : jsonEntry.getAsJsonObject().entrySet()) { if ("dn".equals(jsonAttr.getKey())) { entry.setDn(jsonAttr.getValue().getAsString()); } else { final LdapAttribute attr = new LdapAttribute(sortBehavior); attr.setName(jsonAttr.getKey()); jsonAttr.getValue().getAsJsonArray().forEach(i -> attr.addStringValue(i.getAsString())); entry.addAttribute(attr); } } result.addEntry(entry); } return result; } }
@Override public SearchResult deserialize(final JsonElement json, final Type type, final JsonDeserializationContext context) throws JsonParseException { final SearchResult result = new SearchResult(sortBehavior); final JsonArray jsonResult = json.getAsJsonArray(); for (JsonElement jsonEntry : jsonResult) { final LdapEntry entry = new LdapEntry(sortBehavior); for (Map.Entry<String, JsonElement> jsonAttr : jsonEntry.getAsJsonObject().entrySet()) { if ("dn".equals(jsonAttr.getKey())) { entry.setDn(jsonAttr.getValue().getAsString()); } else { final LdapAttribute attr = new LdapAttribute(sortBehavior); attr.setName(jsonAttr.getKey()); jsonAttr.getValue().getAsJsonArray().forEach(i -> attr.addStringValue(i.getAsString())); entry.addAttribute(attr); } } result.addEntry(entry); } return result; } }
/** * Changes the name of an attribute in this entry. The old attribute is removed from this entry, the name is changed * with {@link LdapAttribute#setName(String)}, and the attribute is added back to this entry. If oldName does not * exist, this method does nothing. * * @param oldName attribute name to change from * @param newName attribute name to change to */ public void renameAttribute(final String oldName, final String newName) { final LdapAttribute la = getAttribute(oldName); if (la != null) { removeAttribute(oldName); la.setName(newName); addAttribute(la); } }
/** * Changes the name of an attribute in this entry. The old attribute is removed from this entry, the name is changed * with {@link LdapAttribute#setName(String)}, and the attribute is added back to this entry. If oldName does not * exist, this method does nothing. * * @param oldName attribute name to change from * @param newName attribute name to change to */ public void renameAttribute(final String oldName, final String newName) { final LdapAttribute la = getAttribute(oldName); if (la != null) { removeAttribute(oldName); la.setName(newName); addAttribute(la); } }
/** * Changes the name of an attribute in this entry. The old attribute is removed from this entry, the name is changed * with {@link LdapAttribute#setName(String)}, and the attribute is added back to this entry. If oldName does not * exist, this method does nothing. * * @param oldName attribute name to change from * @param newName attribute name to change to */ public void renameAttribute(final String oldName, final String newName) { final LdapAttribute la = getAttribute(oldName); if (la != null) { removeAttribute(oldName); la.setName(newName); addAttribute(la); } }
/** * Creates a new simple attribute value mutator. * * @param name of the attribute * @param values of the attribute * @param binary whether values contains base64 encoded data * @param behavior sort behavior of the attribute */ public SimpleAttributeValueMutator( final String name, final String[] values, final boolean binary, final SortBehavior behavior) { la = new LdapAttribute(behavior, binary); la.setName(name); if (binary) { for (String value : values) { la.addBinaryValue(LdapUtils.base64Decode(value)); } } else { la.addStringValue(values); } }
/** * Returns an ldap attribute using the supplied apache ldap attribute. * * @param a apache ldap attribute * * @return ldap attribute */ public LdapAttribute toLdapAttribute(final Attribute a) { boolean isBinary = false; if (a.getId().contains(";binary")) { isBinary = true; } else if (binaryAttrs != null && binaryAttrs.contains(a.getUpId())) { isBinary = true; } final LdapAttribute la = new LdapAttribute(sortBehavior, isBinary); la.setName(a.getUpId()); for (Value<?> v : a) { if (isBinary) { la.addBinaryValue(v.getBytes()); } else { la.addStringValue(v.getString()); } } return la; }
@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 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 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); } } }
/** Tests default sort behavior. */ @Test(groups = {"bean"}) public void defaultSortBehavior() { final LdapAttribute la = new LdapAttribute("givenName"); AssertJUnit.assertEquals(SortBehavior.getDefaultSortBehavior(), la.getSortBehavior()); AssertJUnit.assertEquals(0, la.size()); AssertJUnit.assertNull(la.getStringValue()); AssertJUnit.assertNull(la.getBinaryValue()); AssertJUnit.assertEquals("givenName", la.getName()); la.setName("sn"); AssertJUnit.assertEquals("sn", la.getName()); la.clear(); AssertJUnit.assertEquals(0, la.size()); }