Search in sources :

Example 1 with Authenticator

use of org.ldaptive.auth.Authenticator in project cas by apereo.

the class Beans method getAuthenticatedOrAnonSearchAuthenticator.

private static Authenticator getAuthenticatedOrAnonSearchAuthenticator(final AbstractLdapAuthenticationProperties l) {
    if (StringUtils.isBlank(l.getBaseDn())) {
        throw new IllegalArgumentException("Base dn cannot be empty/blank for authenticated/anonymous authentication");
    }
    if (StringUtils.isBlank(l.getUserFilter())) {
        throw new IllegalArgumentException("User filter cannot be empty/blank for authenticated/anonymous authentication");
    }
    final PooledConnectionFactory connectionFactoryForSearch = Beans.newLdaptivePooledConnectionFactory(l);
    final PooledSearchDnResolver resolver = new PooledSearchDnResolver();
    resolver.setBaseDn(l.getBaseDn());
    resolver.setSubtreeSearch(l.isSubtreeSearch());
    resolver.setAllowMultipleDns(l.isAllowMultipleDns());
    resolver.setConnectionFactory(connectionFactoryForSearch);
    resolver.setUserFilter(l.getUserFilter());
    final Authenticator auth;
    if (StringUtils.isBlank(l.getPrincipalAttributePassword())) {
        auth = new Authenticator(resolver, getPooledBindAuthenticationHandler(l, Beans.newLdaptivePooledConnectionFactory(l)));
    } else {
        auth = new Authenticator(resolver, getPooledCompareAuthenticationHandler(l, Beans.newLdaptivePooledConnectionFactory(l)));
    }
    if (l.isEnhanceWithEntryResolver()) {
        auth.setEntryResolver(Beans.newLdaptiveSearchEntryResolver(l, Beans.newLdaptivePooledConnectionFactory(l)));
    }
    return auth;
}
Also used : PooledConnectionFactory(org.ldaptive.pool.PooledConnectionFactory) PooledSearchDnResolver(org.ldaptive.auth.PooledSearchDnResolver) Authenticator(org.ldaptive.auth.Authenticator)

Example 2 with Authenticator

use of org.ldaptive.auth.Authenticator in project cas by apereo.

the class LdapUtils method getDirectBindAuthenticator.

private static Authenticator getDirectBindAuthenticator(final AbstractLdapAuthenticationProperties l) {
    if (StringUtils.isBlank(l.getDnFormat())) {
        throw new IllegalArgumentException("Dn format cannot be empty/blank for direct bind authentication");
    }
    final FormatDnResolver resolver = new FormatDnResolver(l.getDnFormat());
    final Authenticator authenticator = new Authenticator(resolver, getPooledBindAuthenticationHandler(l, newLdaptivePooledConnectionFactory(l)));
    if (l.isEnhanceWithEntryResolver()) {
        authenticator.setEntryResolver(newLdaptiveSearchEntryResolver(l, newLdaptivePooledConnectionFactory(l)));
    }
    return authenticator;
}
Also used : FormatDnResolver(org.ldaptive.auth.FormatDnResolver) Authenticator(org.ldaptive.auth.Authenticator)

Example 3 with Authenticator

use of org.ldaptive.auth.Authenticator in project cas by apereo.

the class LdapUtils method getAuthenticatedOrAnonSearchAuthenticator.

/**
 * Gets authenticated authenticator.
 *
 * @param l the lDAP properties
 * @return the authenticated or anon search authenticator
 */
public static Authenticator getAuthenticatedOrAnonSearchAuthenticator(final AbstractLdapAuthenticationProperties l) {
    if (StringUtils.isBlank(l.getBaseDn())) {
        throw new IllegalArgumentException("Base dn cannot be empty/blank for authenticated/anonymous authentication");
    }
    if (StringUtils.isBlank(l.getSearchFilter())) {
        throw new IllegalArgumentException("User filter cannot be empty/blank for authenticated/anonymous authentication");
    }
    val connectionFactoryForSearch = newLdaptiveConnectionFactory(l);
    val resolver = buildAggregateDnResolver(l, connectionFactoryForSearch);
    val auth = StringUtils.isBlank(l.getPrincipalAttributePassword()) ? new Authenticator(resolver, getBindAuthenticationHandler(newLdaptiveConnectionFactory(l))) : new Authenticator(resolver, getCompareAuthenticationHandler(l, newLdaptiveConnectionFactory(l)));
    if (l.isEnhanceWithEntryResolver()) {
        auth.setEntryResolver(newLdaptiveSearchEntryResolver(l, newLdaptiveConnectionFactory(l)));
    }
    return auth;
}
Also used : lombok.val(lombok.val) Authenticator(org.ldaptive.auth.Authenticator)

Example 4 with Authenticator

use of org.ldaptive.auth.Authenticator in project cas by apereo.

the class LdapUtils method getAuthenticatorViaDnFormat.

private static Authenticator getAuthenticatorViaDnFormat(final AbstractLdapAuthenticationProperties l) {
    val resolver = new FormatDnResolver(l.getDnFormat());
    val authenticator = new Authenticator(resolver, getBindAuthenticationHandler(newLdaptiveConnectionFactory(l)));
    if (l.isEnhanceWithEntryResolver()) {
        authenticator.setEntryResolver(newLdaptiveSearchEntryResolver(l, newLdaptiveConnectionFactory(l)));
    }
    return authenticator;
}
Also used : lombok.val(lombok.val) FormatDnResolver(org.ldaptive.auth.FormatDnResolver) Authenticator(org.ldaptive.auth.Authenticator)

Example 5 with Authenticator

use of org.ldaptive.auth.Authenticator in project cas by apereo.

the class Beans method getActiveDirectoryAuthenticator.

private static Authenticator getActiveDirectoryAuthenticator(final AbstractLdapAuthenticationProperties l) {
    if (StringUtils.isBlank(l.getDnFormat())) {
        throw new IllegalArgumentException("Dn format cannot be empty/blank for active directory authentication");
    }
    final FormatDnResolver resolver = new FormatDnResolver(l.getDnFormat());
    final Authenticator authn = new Authenticator(resolver, getPooledBindAuthenticationHandler(l, Beans.newLdaptivePooledConnectionFactory(l)));
    if (l.isEnhanceWithEntryResolver()) {
        authn.setEntryResolver(Beans.newLdaptiveSearchEntryResolver(l, Beans.newLdaptivePooledConnectionFactory(l)));
    }
    return authn;
}
Also used : FormatDnResolver(org.ldaptive.auth.FormatDnResolver) Authenticator(org.ldaptive.auth.Authenticator)

Aggregations

Authenticator (org.ldaptive.auth.Authenticator)10 FormatDnResolver (org.ldaptive.auth.FormatDnResolver)5 lombok.val (lombok.val)2 PooledSearchDnResolver (org.ldaptive.auth.PooledSearchDnResolver)2 PooledConnectionFactory (org.ldaptive.pool.PooledConnectionFactory)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)1 LdapAuthenticationHandler (org.apereo.cas.authentication.LdapAuthenticationHandler)1 DefaultLdapPasswordPolicyHandlingStrategy (org.apereo.cas.authentication.support.DefaultLdapPasswordPolicyHandlingStrategy)1 GroovyLdapPasswordPolicyHandlingStrategy (org.apereo.cas.authentication.support.GroovyLdapPasswordPolicyHandlingStrategy)1 LdapPasswordPolicyConfiguration (org.apereo.cas.authentication.support.LdapPasswordPolicyConfiguration)1 LdapPasswordPolicyHandlingStrategy (org.apereo.cas.authentication.support.LdapPasswordPolicyHandlingStrategy)1 RejectResultCodeLdapPasswordPolicyHandlingStrategy (org.apereo.cas.authentication.support.RejectResultCodeLdapPasswordPolicyHandlingStrategy)1 LdapEntry (org.ldaptive.LdapEntry)1 AuthenticationRequest (org.ldaptive.auth.AuthenticationRequest)1 AuthenticationResponse (org.ldaptive.auth.AuthenticationResponse)1 RequireAnyRoleAuthorizer (org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer)1 J2EContext (org.pac4j.core.context.J2EContext)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1