private Map<String, Object> addClaim(Map<String, Object> claims, LdapEntry ldapEntry, String claimKey, String attributeKey) { if (ldapEntry.getAttribute(attributeKey) != null) { claims.put(claimKey, ldapEntry.getAttribute(attributeKey).getStringValue()); } return claims; }
/** * Execute modify operation boolean. * * @param currentDn the current dn * @param connectionFactory the connection factory * @param entry the entry * @return the boolean */ public static boolean executeModifyOperation(final String currentDn, final ConnectionFactory connectionFactory, final LdapEntry entry) { final Map<String, Set<String>> attributes = new HashMap<>(entry.getAttribute().size()); for (final LdapAttribute ldapAttribute : entry.getAttributes()) { attributes.put(ldapAttribute.getName(), ImmutableSet.copyOf(ldapAttribute.getStringValues())); } return executeModifyOperation(currentDn, connectionFactory, attributes); }
/** * Tests create with one entry. * * @param attr1 ldap attribute * @param attr2 ldap attribute */ @Test(groups = {"bean"}, dataProvider = "attributes") public void createOne(final LdapAttribute attr1, final LdapAttribute attr2) { final LdapEntry le = new LdapEntry("uid=1", attr1); AssertJUnit.assertEquals(attr1, le.getAttribute()); AssertJUnit.assertEquals(attr1, le.getAttribute("givenName")); AssertJUnit.assertEquals(attr1, le.getAttribute("givenname")); AssertJUnit.assertEquals("givenName", le.getAttributeNames()[0]); AssertJUnit.assertEquals(1, le.size()); AssertJUnit.assertEquals(le, new LdapEntry("uid=1", attr1)); le.clear(); AssertJUnit.assertEquals(0, le.size()); }
private static String attributeStringValue(final LdapEntry entry, final String ldapAttribute) { final LdapAttribute attribute = entry.getAttribute(ldapAttribute); if (attribute == null) { return ""; } return attribute.getStringValue(); }
private String getAttribute(final LdapEntry ldapEntry, final String attribute, final LogEventHandler handler) { return ofNullable(ldapEntry.getAttribute(attribute)).map( LdapAttribute::getStringValue).orElseGet(() -> { handler.info("account", "Could not find '" + attribute + "' for mapping"); return null; }); }
/** * Returns a single value for the first attribute name found in the supplied entry. * * @param entry containing the attributes * @param names to search for in the entry * * @return single attribute value */ private static String getAttributeValue(final LdapEntry entry, final String... names) { String value = null; for (String name : names) { final LdapAttribute la = entry.getAttribute(name); if (la != null) { value = la.getStringValue(); break; } } return value; }
/** * Returns a single value for the first attribute name found in the supplied entry. * * @param entry containing the attributes * @param names to search for in the entry * * @return single attribute value */ private static String getAttributeValue(final LdapEntry entry, final String... names) { String value = null; for (String name : names) { final LdapAttribute la = entry.getAttribute(name); if (la != null) { value = la.getStringValue(); break; } } return value; }
/** * Returns the values for the first attribute name found in the supplied entry. * * @param entry containing the attributes * @param names to search for in the entry * * @return attribute values */ private static String[] getAttributeValues(final LdapEntry entry, final String... names) { Collection<String> values = null; for (String name : names) { final LdapAttribute la = entry.getAttribute(name); if (la != null) { values = la.getStringValues(); break; } } return values != null ? values.toArray(new String[values.size()]) : null; } }
/** * Returns the values for the first attribute name found in the supplied entry. * * @param entry containing the attributes * @param names to search for in the entry * * @return attribute values */ private static String[] getAttributeValues(final LdapEntry entry, final String... names) { Collection<String> values = null; for (String name : names) { final LdapAttribute la = entry.getAttribute(name); if (la != null) { values = la.getStringValues(); break; } } return values != null ? values.toArray(new String[values.size()]) : null; } }
/** * Returns a single value for the first attribute name found in the supplied entry. * * @param entry containing the attributes * @param names to search for in the entry * * @return single attribute value */ private static String getAttributeValue(final LdapEntry entry, final String... names) { String value = null; for (String name : names) { final LdapAttribute la = entry.getAttribute(name); if (la != null) { value = la.getStringValue(); break; } } return value; }
/** * Verify spnego attribute value. * * @param searchResult the search result * @return true if attribute value exists and has a value */ protected boolean processSpnegoAttribute(final Response<SearchResult> searchResult) { final SearchResult result = searchResult.getResult(); if (result == null || result.getEntries().isEmpty()) { logger.debug("Spnego attribute is not found in the search results"); return false; } final LdapEntry entry = result.getEntry(); final LdapAttribute attribute = entry.getAttribute(this.spnegoAttributeName); return verifySpnegyAttributeValue(attribute); }
@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(); } } } }
/** * 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); } } } }
/** * 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 schema. The subschema subentry is searched for on the root DSE, followed by searching for the * subschema entry itself. * * @param factory to obtain an LDAP connection from * * @return schema created from the connection factory * * @throws LdapException if the search fails */ public static Schema createSchema(final ConnectionFactory factory) throws LdapException { final LdapEntry rootDSE = getLdapEntry(factory, "", "(objectClass=*)", new String[] {SUBSCHEMA_SUBENTRY_ATTR_NAME}); final String entryDn = rootDSE.getAttribute(SUBSCHEMA_SUBENTRY_ATTR_NAME).getStringValue(); return createSchema(getLdapEntry(factory, entryDn, "(objectClass=subSchema)", ReturnAttributes.ALL.value())); }
/** * Creates a new schema. The subschema subentry is searched for on the root DSE, followed by searching for the * subschema entry itself. * * @param factory to obtain an LDAP connection from * * @return schema created from the connection factory * * @throws LdapException if the search fails */ public static Schema createSchema(final ConnectionFactory factory) throws LdapException { final LdapEntry rootDSE = getLdapEntry(factory, "", "(objectClass=*)", new String[] {SUBSCHEMA_SUBENTRY_ATTR_NAME}); final String entryDn = rootDSE.getAttribute(SUBSCHEMA_SUBENTRY_ATTR_NAME).getStringValue(); return createSchema(getLdapEntry(factory, entryDn, "(objectClass=subSchema)", ReturnAttributes.ALL.value())); }
/** * Creates a new schema. The subschema subentry is searched for on the root DSE, followed by searching for the * subschema entry itself. * * @param factory to obtain an LDAP connection from * * @return schema created from the connection factory * * @throws LdapException if the search fails */ public static Schema createSchema(final ConnectionFactory factory) throws LdapException { final LdapEntry rootDSE = getLdapEntry(factory, "", "(objectClass=*)", new String[] {SUBSCHEMA_SUBENTRY_ATTR_NAME}); final String entryDn = rootDSE.getAttribute(SUBSCHEMA_SUBENTRY_ATTR_NAME).getStringValue(); return createSchema(getLdapEntry(factory, entryDn, "(objectClass=subSchema)", ReturnAttributes.ALL.value())); }
/** Tests default sort behavior. */ @Test(groups = {"bean"}) public void defaultSortBehavior() { final LdapEntry le = new LdapEntry("uid=1"); AssertJUnit.assertEquals(SortBehavior.getDefaultSortBehavior(), le.getSortBehavior()); AssertJUnit.assertEquals(0, le.size()); AssertJUnit.assertNull(le.getAttribute()); AssertJUnit.assertEquals("uid=1", le.getDn()); le.setDn("uid=2"); AssertJUnit.assertEquals("uid=2", le.getDn()); le.clear(); AssertJUnit.assertEquals(0, le.size()); }