/** * Adds attribute(s) to this ldap attributes. * * @param attrs collection of attributes to add */ public void addAttributes(final Collection<LdapAttribute> attrs) { for (LdapAttribute la : attrs) { addAttribute(la); } }
/** * Creates a new ldap entry. * * @param dn dn for this entry * @param attr ldap attribute for this entry */ public LdapEntry(final String dn, final LdapAttribute... attr) { this(); setDn(dn); for (LdapAttribute a : attr) { addAttribute(a); } }
/** * Creates a new ldap entry. * * @param dn dn for this entry * @param attr ldap attribute for this entry */ public LdapEntry(final String dn, final LdapAttribute... attr) { this(); setDn(dn); for (LdapAttribute a : attr) { addAttribute(a); } }
/** * Creates a new ldap entry. * * @param dn dn for this entry * @param attr ldap attribute for this entry */ public LdapEntry(final String dn, final LdapAttribute... attr) { this(); setDn(dn); for (LdapAttribute a : attr) { addAttribute(a); } }
/** {@inheritDoc} */ @Override public boolean create(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nullable @Positive Long expiration) throws IOException { if (expiration != null) { throw new UnsupportedOperationException("Expiration not supported"); } final LdapEntry entry = new LdapEntry(context, defaultAttributes); entry.addAttribute(new LdapAttribute(key, value)); try { merge(entry); return true; } catch (LdapException e) { log.error("LDAP merge operation failed", e); throw new IOException(e); } }
/** {@inheritDoc} */ @Override public boolean update(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nullable @Positive final Long expiration) throws IOException { if (expiration != null) { throw new UnsupportedOperationException("Expiration not supported"); } final LdapEntry entry = new LdapEntry(context, defaultAttributes); entry.addAttribute(new LdapAttribute(key, value)); try { merge(entry); return true; } catch (LdapException e) { log.error("LDAP merge operation failed", e); throw new IOException(e); } }
@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); } }
attr.setName(attrName); attr.addStringValues((List<String>) jsonObject.get(k)); entry.addAttribute(attr);
.flatMap(List::stream) .toArray(size -> new String[size]); userEntry.addAttribute(new LdapAttribute(MEMBEROF_ATTRIBUTE, groups)); } catch (Exception e) { LOGGER.warn("No group found for user {}", userEntry.getDn(), e);
dest.addAttribute(attr);
/** * Tests ordered sort behavior. * * @param attr1 ldap attribute * @param attr2 ldap attribute */ @Test(groups = {"bean"}, dataProvider = "attributes") public void orderedSortBehavior(final LdapAttribute attr1, final LdapAttribute attr2) { final LdapEntry le = new LdapEntry(SortBehavior.ORDERED); AssertJUnit.assertEquals(SortBehavior.ORDERED, le.getSortBehavior()); le.addAttribute(attr2, attr1); final LdapAttribute[] attrs = le.getAttributes().toArray(new LdapAttribute[2]); AssertJUnit.assertEquals(attr2, attrs[0]); AssertJUnit.assertEquals(attr1, attrs[1]); le.clear(); AssertJUnit.assertEquals(0, le.size()); }
/** * Tests sorted sort behavior. * * @param attr1 ldap attribute * @param attr2 ldap attribute */ @Test(groups = {"bean"}, dataProvider = "attributes") public void sortedSortBehavior(final LdapAttribute attr1, final LdapAttribute attr2) { final LdapEntry le = new LdapEntry(SortBehavior.SORTED); AssertJUnit.assertEquals(SortBehavior.SORTED, le.getSortBehavior()); le.addAttribute(attr2, attr1); final LdapAttribute[] attrs = le.getAttributes().toArray(new LdapAttribute[2]); AssertJUnit.assertEquals(attr1, attrs[0]); AssertJUnit.assertEquals(attr2, attrs[1]); le.clear(); AssertJUnit.assertEquals(0, le.size()); }
final LdapAttribute oldAttr = mergedEntry.getAttribute(la.getName()); if (oldAttr == null) { mergedEntry.addAttribute(la); } else { if (oldAttr.isBinary()) {
final LdapAttribute oldAttr = mergedEntry.getAttribute(la.getName()); if (oldAttr == null) { mergedEntry.addAttribute(la); } else { if (oldAttr.isBinary()) {
final LdapAttribute oldAttr = mergedEntry.getAttribute(la.getName()); if (oldAttr == null) { mergedEntry.addAttribute(la); } else { if (oldAttr.isBinary()) {
/** * Tests create with a collection. * * @param attr1 ldap attribute * @param attr2 ldap attribute */ @Test(groups = {"bean"}, dataProvider = "attributes") public void createCollection(final LdapAttribute attr1, final LdapAttribute attr2) { final Set<LdapAttribute> s = new HashSet<>(); s.add(attr1); final LdapEntry le = new LdapEntry("uid=1", s); le.addAttribute(attr2); AssertJUnit.assertEquals(attr1, le.getAttribute("GIVENNAME")); AssertJUnit.assertEquals(attr2, le.getAttribute("sn")); AssertJUnit.assertEquals(2, le.getAttributeNames().length); AssertJUnit.assertEquals(2, le.size()); AssertJUnit.assertEquals(le, new LdapEntry("uid=1", attr1, attr2)); le.removeAttribute("GIVENNAME"); AssertJUnit.assertEquals(1, le.size()); le.clear(); AssertJUnit.assertEquals(0, le.size()); }