Search in sources :

Example 1 with MidpointPrincipalContextMapper

use of com.evolveum.midpoint.authentication.impl.ldap.MidpointPrincipalContextMapper in project midpoint by Evolveum.

the class LdapModuleFactory method getProvider.

private AuthenticationProvider getProvider(LdapAuthenticationModuleType moduleType) {
    DefaultSpringSecurityContextSource ctx = new DefaultSpringSecurityContextSource(moduleType.getHost());
    ctx.setUserDn(moduleType.getUserDn());
    try {
        ctx.setPassword(protector.decryptString(moduleType.getUserPassword()));
    } catch (EncryptionException e) {
        LOGGER.error("Couldn't obtain clear string for configuration of LDAP user password from " + moduleType.getUserPassword());
    }
    getObjectObjectPostProcessor().postProcess(ctx);
    BindAuthenticator auth = new BindAuthenticator(ctx);
    if (StringUtils.isNotEmpty(moduleType.getDnPattern())) {
        auth.setUserDnPatterns(new String[] { moduleType.getDnPattern() });
    }
    if (moduleType.getSearch() != null) {
        FilterBasedLdapUserSearch search = new FilterBasedLdapUserSearch("", moduleType.getSearch().getPattern(), ctx);
        if (moduleType.getSearch().isSubtree() != null) {
            search.setSearchSubtree(moduleType.getSearch().isSubtree());
        }
        getObjectObjectPostProcessor().postProcess(search);
        auth.setUserSearch(search);
    }
    getObjectObjectPostProcessor().postProcess(auth);
    MidPointLdapAuthenticationProvider provider = new MidPointLdapAuthenticationProvider(auth);
    provider.setUserDetailsContextMapper(new MidpointPrincipalContextMapper(principalManager));
    getObjectObjectPostProcessor().postProcess(provider.getAuthenticatorProvider());
    getObjectObjectPostProcessor().postProcess(provider);
    return provider;
}
Also used : MidpointPrincipalContextMapper(com.evolveum.midpoint.authentication.impl.ldap.MidpointPrincipalContextMapper) BindAuthenticator(org.springframework.security.ldap.authentication.BindAuthenticator) DefaultSpringSecurityContextSource(org.springframework.security.ldap.DefaultSpringSecurityContextSource) MidPointLdapAuthenticationProvider(com.evolveum.midpoint.authentication.impl.provider.MidPointLdapAuthenticationProvider) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) FilterBasedLdapUserSearch(org.springframework.security.ldap.search.FilterBasedLdapUserSearch)

Aggregations

MidpointPrincipalContextMapper (com.evolveum.midpoint.authentication.impl.ldap.MidpointPrincipalContextMapper)1 MidPointLdapAuthenticationProvider (com.evolveum.midpoint.authentication.impl.provider.MidPointLdapAuthenticationProvider)1 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)1 DefaultSpringSecurityContextSource (org.springframework.security.ldap.DefaultSpringSecurityContextSource)1 BindAuthenticator (org.springframework.security.ldap.authentication.BindAuthenticator)1 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)1