Search in sources :

Example 16 with LdapEntry

use of org.ldaptive.LdapEntry in project cas by apereo.

the class LdapConsentRepository method readConsentEntry.

/**
 * Fetches a user entry along with its consent attributes.
 *
 * @param principal user name
 * @return the user's LDAP entry
 */
private LdapEntry readConsentEntry(final String principal) {
    try {
        final SearchFilter filter = LdapUtils.newLdaptiveSearchFilter(this.searchFilter, CollectionUtils.wrap(Arrays.asList(principal)));
        LOGGER.debug("Locating consent LDAP entry via filter [{}] based on attribute [{}]", filter, this.ldap.getConsentAttributeName());
        final Response<SearchResult> response = LdapUtils.executeSearchOperation(this.connectionFactory, this.ldap.getBaseDn(), filter, this.ldap.getConsentAttributeName());
        if (LdapUtils.containsResultEntry(response)) {
            final LdapEntry entry = response.getResult().getEntry();
            LOGGER.debug("Locating consent LDAP entry [{}]", entry);
            return entry;
        }
    } catch (final LdapException e) {
        LOGGER.debug(e.getMessage(), e);
    }
    return null;
}
Also used : SearchFilter(org.ldaptive.SearchFilter) SearchResult(org.ldaptive.SearchResult) LdapEntry(org.ldaptive.LdapEntry) LdapException(org.ldaptive.LdapException)

Example 17 with LdapEntry

use of org.ldaptive.LdapEntry in project cas by apereo.

the class LdapServiceRegistryDao method update.

/**
     * Update the ldap entry with the given registered service.
     *
     * @param rs the rs
     * @return the registered service
     */
private RegisteredService update(final RegisteredService rs) {
    String currentDn = null;
    try {
        final Response<SearchResult> response = searchForServiceById(rs.getId());
        if (LdapUtils.containsResultEntry(response)) {
            currentDn = response.getResult().getEntry().getDn();
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    if (StringUtils.isNotBlank(currentDn)) {
        LOGGER.debug("Updating registered service at [{}]", currentDn);
        final LdapEntry entry = this.ldapServiceMapper.mapFromRegisteredService(this.baseDn, rs);
        LdapUtils.executeModifyOperation(currentDn, this.connectionFactory, entry);
    }
    return rs;
}
Also used : SearchResult(org.ldaptive.SearchResult) LdapEntry(org.ldaptive.LdapEntry) LdapException(org.ldaptive.LdapException)

Example 18 with LdapEntry

use of org.ldaptive.LdapEntry in project cas by apereo.

the class LdapConsentRepository method deleteConsentDecision.

@Override
public boolean deleteConsentDecision(final long id, final String principal) {
    LOGGER.debug("Deleting consent decision [{}] for principal [{}]", id, principal);
    final LdapEntry entry = readConsentEntry(principal);
    if (entry != null) {
        final Set<String> newConsent = removeDecision(entry.getAttribute(this.ldap.getConsentAttributeName()), id);
        return executeModifyOperation(newConsent, entry);
    }
    return false;
}
Also used : LdapEntry(org.ldaptive.LdapEntry)

Example 19 with LdapEntry

use of org.ldaptive.LdapEntry in project cas by apereo.

the class LdapConsentRepository method readConsentEntries.

/**
 * Fetches all user entries that contain consent attributes along with these.
 *
 * @return the collection of user entries
 */
private Collection<LdapEntry> readConsentEntries() {
    try {
        final String att = this.ldap.getConsentAttributeName();
        final SearchFilter filter = LdapUtils.newLdaptiveSearchFilter('(' + att + "=*)");
        LOGGER.debug("Locating consent LDAP entries via filter [{}] based on attribute [{}]", filter, att);
        final Response<SearchResult> response = LdapUtils.executeSearchOperation(this.connectionFactory, this.ldap.getBaseDn(), filter, att);
        if (LdapUtils.containsResultEntry(response)) {
            final Collection<LdapEntry> results = response.getResult().getEntries();
            LOGGER.debug("Locating [{}] consent LDAP entries", results.size());
            return results;
        }
    } catch (final LdapException e) {
        LOGGER.debug(e.getMessage(), e);
    }
    return new HashSet<>(0);
}
Also used : SearchFilter(org.ldaptive.SearchFilter) SearchResult(org.ldaptive.SearchResult) LdapEntry(org.ldaptive.LdapEntry) LdapException(org.ldaptive.LdapException) HashSet(java.util.HashSet)

Example 20 with LdapEntry

use of org.ldaptive.LdapEntry in project cas by apereo.

the class OptionalWarningLdapLdapAccountStateHandlerTests method verifyWarningOnMatch.

@Test
public void verifyWarningOnMatch() {
    final OptionalWarningLdapLdapAccountStateHandler h = new OptionalWarningLdapLdapAccountStateHandler();
    h.setWarnAttributeName("attribute");
    h.setWarningAttributeValue("value");
    h.setDisplayWarningOnMatch(true);
    final AuthenticationResponse response = mock(AuthenticationResponse.class);
    final LdapEntry entry = mock(LdapEntry.class);
    when(response.getLdapEntry()).thenReturn(entry);
    when(entry.getAttribute(anyString())).thenReturn(new LdapAttribute("attribute", "value"));
    final List<MessageDescriptor> messages = new ArrayList<>();
    final LdapPasswordPolicyConfiguration config = new LdapPasswordPolicyConfiguration();
    config.setPasswordWarningNumberOfDays(5);
    h.handleWarning(new AccountState.DefaultWarning(ZonedDateTime.now(), 1), response, config, messages);
    assertEquals(2, messages.size());
}
Also used : MessageDescriptor(org.apereo.cas.authentication.MessageDescriptor) LdapAttribute(org.ldaptive.LdapAttribute) ArrayList(java.util.ArrayList) LdapEntry(org.ldaptive.LdapEntry) AccountState(org.ldaptive.auth.AccountState) AuthenticationResponse(org.ldaptive.auth.AuthenticationResponse) Test(org.junit.Test)

Aggregations

LdapEntry (org.ldaptive.LdapEntry)26 LdapAttribute (org.ldaptive.LdapAttribute)17 SearchResult (org.ldaptive.SearchResult)14 LdapException (org.ldaptive.LdapException)9 SearchFilter (org.ldaptive.SearchFilter)7 ArrayList (java.util.ArrayList)6 PasswordManagementProperties (org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties)4 ConnectionFactory (org.ldaptive.ConnectionFactory)4 AuthenticationResponse (org.ldaptive.auth.AuthenticationResponse)4 MessageDescriptor (org.apereo.cas.authentication.MessageDescriptor)3 Test (org.junit.Test)3 AccountState (org.ldaptive.auth.AccountState)3 LinkedHashMap (java.util.LinkedHashMap)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 AddRequest (com.unboundid.ldap.sdk.AddRequest)1 Attribute (com.unboundid.ldap.sdk.Attribute)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 CertificateException (java.security.cert.CertificateException)1 HashSet (java.util.HashSet)1