/** * Returns the DN for the supplied ldap entry. * * @param entry to retrieve the DN from * * @return dn */ protected String resolveDn(final LdapEntry entry) { return entry.getDn(); }
/** * Returns the DN for the supplied ldap entry. * * @param entry to retrieve the DN from * * @return dn */ protected String resolveDn(final LdapEntry entry) { return entry.getDn(); }
/** * Returns the DN for the supplied ldap entry. * * @param entry to retrieve the DN from * * @return dn */ protected String resolveDn(final LdapEntry entry) { return entry.getDn(); }
/** * Adds an entry to this search result. * * @param entry entry to add */ public void addEntry(final LdapEntry... entry) { for (LdapEntry e : entry) { resultEntries.put(e.getDn().toLowerCase(), e); } }
/** * Adds an entry to this search result. * * @param entry entry to add */ public void addEntry(final LdapEntry... entry) { for (LdapEntry e : entry) { resultEntries.put(e.getDn().toLowerCase(), e); } }
/** * Adds an entry to this search result. * * @param entry entry to add */ public void addEntry(final LdapEntry... entry) { for (LdapEntry e : entry) { resultEntries.put(e.getDn().toLowerCase(), e); } }
/** * Removes an entry from this search result. * * @param entry entry to remove */ public void removeEntry(final LdapEntry... entry) { for (LdapEntry e : entry) { resultEntries.remove(e.getDn().toLowerCase()); } }
/** * Removes an entry from this search result. * * @param entry entry to remove */ public void removeEntry(final LdapEntry... entry) { for (LdapEntry e : entry) { resultEntries.remove(e.getDn().toLowerCase()); } }
/** * Removes an entry from this search result. * * @param entry entry to remove */ public void removeEntry(final LdapEntry... entry) { for (LdapEntry e : entry) { resultEntries.remove(e.getDn().toLowerCase()); } }
@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; } }
@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; } }
/** * 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; }
/** * 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; }
/** * Creates a CAS principal with attributes if the LDAP entry contains principal attributes. * * @param username Username that was successfully authenticated which is used for principal ID when principal id is not specified. * @param ldapEntry LDAP entry that may contain principal attributes. * @return Principal if the LDAP entry contains at least a principal ID attribute value, null otherwise. * @throws LoginException On security policy errors related to principal creation. */ protected Principal createPrincipal(final String username, final LdapEntry ldapEntry) throws LoginException { LOGGER.debug("Creating LDAP principal for [{}] based on [{}] and attributes [{}]", username, ldapEntry.getDn(), ldapEntry.getAttributeNames()); val id = getLdapPrincipalIdentifier(username, ldapEntry); LOGGER.debug("LDAP principal identifier created is [{}]", id); val attributeMap = collectAttributesForLdapEntry(ldapEntry, id); LOGGER.debug("Created LDAP principal for id [{}] and [{}] attributes", id, attributeMap.size()); return this.principalFactory.createPrincipal(id, attributeMap); }
/** * Executes a {@link DeleteOperation} for the supplied entry. * * @param request merge request * @param entry to delete from the LDAP * * @return response of the delete operation * * @throws LdapException if an error occurs executing the deleting operation */ protected Response<Void> delete(final MergeRequest request, final LdapEntry entry) throws LdapException { Response<Void> response; final DeleteOperation delete = new DeleteOperation(getConnection()); response = delete.execute(new DeleteRequest(entry.getDn())); logger.info("delete entry {} for request {}", entry, request); return response; } }
/** * Returns an apache ldap entry that represents the supplied ldap entry. * * @param le ldap entry * * @return apache ldap entry * * @throws LdapException if the apache object cannot be created */ public Entry fromLdapEntry(final LdapEntry le) throws LdapException { final DefaultEntry entry = new DefaultEntry(le.getDn()); entry.add(fromLdapAttributes(le.getAttributes())); return entry; }
/** * Execute add operation boolean. * * @param connectionFactory the connection factory * @param entry the entry * @return the boolean * @throws LdapException the ldap exception */ public static boolean executeAddOperation(final ConnectionFactory connectionFactory, final LdapEntry entry) throws LdapException { try (Connection connection = createConnection(connectionFactory)) { final AddOperation operation = new AddOperation(connection); operation.execute(new AddRequest(entry.getDn(), entry.getAttributes())); return true; } catch (final LdapException e) { LOGGER.error(e.getMessage(), e); } return false; }
@Override protected void insert(final Map<String, Object> attributes) { attributes.put("objectClass", "person"); final LdapEntry ldapEntry = new LdapEntry(getEntryId(attributes)); ldapEntry.addAttributes(getLdapAttributes(attributes)); Connection connection = null; try { connection = connectionFactory.getConnection(); connection.open(); final AddOperation add = new AddOperation(connection); add.execute(new AddRequest(ldapEntry.getDn(), ldapEntry.getAttributes())); } catch (final LdapException e) { throw new TechnicalException(e); } finally { if (connection != null) { connection.close(); } } }
@Override public Response<Void> add(final T object) throws LdapException { final LdapEntry entry = new LdapEntry(); getLdapEntryMapper().map(object, entry); final AddRequest request = new AddRequest(entry.getDn(), entry.getAttributes()); try (Connection conn = getConnectionFactory().getConnection()) { conn.open(); final AddOperation add = new AddOperation(conn); return add.execute(request); } }
/** 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()); }