Search in sources :

Example 6 with SearchFilter

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

the class SpnegoWebflowActionsConfiguration method ldapSpnegoClientAction.

@Lazy
@Bean
@RefreshScope
public Action ldapSpnegoClientAction() {
    final SpnegoProperties spnegoProperties = casProperties.getAuthn().getSpnego();
    final ConnectionFactory connectionFactory = Beans.newLdaptivePooledConnectionFactory(spnegoProperties.getLdap());
    final SearchFilter filter = Beans.newLdaptiveSearchFilter(spnegoProperties.getLdap().getSearchFilter(), "host", Collections.emptyList());
    final SearchRequest searchRequest = Beans.newLdaptiveSearchRequest(spnegoProperties.getLdap().getBaseDn(), filter);
    return new LdapSpnegoKnownClientSystemsFilterAction(spnegoProperties.getIpsToCheckPattern(), spnegoProperties.getAlternativeRemoteHostAttribute(), spnegoProperties.getDnsTimeout(), connectionFactory, searchRequest, spnegoProperties.getSpnegoAttributeName());
}
Also used : SearchRequest(org.ldaptive.SearchRequest) ConnectionFactory(org.ldaptive.ConnectionFactory) LdapSpnegoKnownClientSystemsFilterAction(org.apereo.cas.web.flow.client.LdapSpnegoKnownClientSystemsFilterAction) SpnegoProperties(org.apereo.cas.configuration.model.support.spnego.SpnegoProperties) SearchFilter(org.ldaptive.SearchFilter) Lazy(org.springframework.context.annotation.Lazy) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Example 7 with SearchFilter

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

the class LdapPasswordManagementService method change.

@Audit(action = "CHANGE_PASSWORD", actionResolverName = "CHANGE_PASSWORD_ACTION_RESOLVER", resourceResolverName = "CHANGE_PASSWORD_RESOURCE_RESOLVER")
@Override
public boolean change(final Credential credential, final PasswordChangeBean bean) {
    Assert.notNull(credential, "Credential cannot be null");
    Assert.notNull(bean, "PasswordChangeBean cannot be null");
    try {
        final PasswordManagementProperties.Ldap ldap = passwordManagementProperties.getLdap();
        final UsernamePasswordCredential c = (UsernamePasswordCredential) credential;
        final SearchFilter filter = Beans.newLdaptiveSearchFilter(ldap.getUserFilter(), Beans.LDAP_SEARCH_FILTER_DEFAULT_PARAM_NAME, Arrays.asList(c.getId()));
        LOGGER.debug("Constructed LDAP filter [{}] to update account password", filter);
        final ConnectionFactory factory = Beans.newLdaptivePooledConnectionFactory(ldap);
        final Response<SearchResult> response = LdapUtils.executeSearchOperation(factory, ldap.getBaseDn(), filter);
        LOGGER.debug("LDAP response to update password is [{}]", response);
        if (LdapUtils.containsResultEntry(response)) {
            final String dn = response.getResult().getEntry().getDn();
            LOGGER.debug("Updating account password for [{}]", dn);
            if (LdapUtils.executePasswordModifyOperation(dn, factory, c.getPassword(), bean.getPassword(), passwordManagementProperties.getLdap().getType())) {
                LOGGER.debug("Successfully updated the account password for [{}]", dn);
                return true;
            }
            LOGGER.error("Could not update the LDAP entry's password for [{}] and base DN [{}]", filter.format(), ldap.getBaseDn());
        } else {
            LOGGER.error("Could not locate an LDAP entry for [{}] and base DN [{}]", filter.format(), ldap.getBaseDn());
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return false;
}
Also used : ConnectionFactory(org.ldaptive.ConnectionFactory) PasswordManagementProperties(org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties) SearchFilter(org.ldaptive.SearchFilter) SearchResult(org.ldaptive.SearchResult) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Audit(org.apereo.inspektr.audit.annotation.Audit)

Aggregations

SearchFilter (org.ldaptive.SearchFilter)7 ConnectionFactory (org.ldaptive.ConnectionFactory)4 PasswordManagementProperties (org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties)3 LdapAttribute (org.ldaptive.LdapAttribute)3 SearchResult (org.ldaptive.SearchResult)3 LdapEntry (org.ldaptive.LdapEntry)2 SearchRequest (org.ldaptive.SearchRequest)2 MongoCredential (com.mongodb.MongoCredential)1 LinkedHashMap (java.util.LinkedHashMap)1 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)1 GraphicalUserAuthenticationProperties (org.apereo.cas.configuration.model.support.gua.GraphicalUserAuthenticationProperties)1 AbstractLdapProperties (org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties)1 SpnegoProperties (org.apereo.cas.configuration.model.support.spnego.SpnegoProperties)1 LdapSpnegoKnownClientSystemsFilterAction (org.apereo.cas.web.flow.client.LdapSpnegoKnownClientSystemsFilterAction)1 Audit (org.apereo.inspektr.audit.annotation.Audit)1 BindRequest (org.ldaptive.BindRequest)1 CompareRequest (org.ldaptive.CompareRequest)1 Credential (org.ldaptive.Credential)1 DefaultConnectionFactory (org.ldaptive.DefaultConnectionFactory)1 BindPassivator (org.ldaptive.pool.BindPassivator)1