Search in sources :

Example 31 with LdapAuthenticationProvider

use of org.springframework.security.ldap.authentication.LdapAuthenticationProvider in project spring-security by spring-projects.

the class LdapAuthenticationProviderBuilderSecurityBuilderTests method groupSearchCustom.

@Test
public void groupSearchCustom() {
    this.spring.register(GroupSearchConfig.class).autowire();
    LdapAuthenticationProvider provider = ldapProvider();
    assertThat(ReflectionTestUtils.getField(getAuthoritiesPopulator(provider), "groupSearchFilter")).isEqualTo("ou=groupName");
}
Also used : LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider) Test(org.junit.jupiter.api.Test)

Example 32 with LdapAuthenticationProvider

use of org.springframework.security.ldap.authentication.LdapAuthenticationProvider in project spring-security by spring-projects.

the class LdapAuthenticationProviderBuilderSecurityBuilderTests method groupSubtreeSearchCustom.

@Test
public void groupSubtreeSearchCustom() {
    this.spring.register(GroupSubtreeSearchConfig.class).autowire();
    LdapAuthenticationProvider provider = ldapProvider();
    assertThat(ReflectionTestUtils.getField(getAuthoritiesPopulator(provider), "searchControls")).extracting("searchScope").isEqualTo(SearchControls.SUBTREE_SCOPE);
}
Also used : LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider) Test(org.junit.jupiter.api.Test)

Example 33 with LdapAuthenticationProvider

use of org.springframework.security.ldap.authentication.LdapAuthenticationProvider in project spring-security by spring-projects.

the class LdapAuthenticationProviderBuilderSecurityBuilderTests method defaultConfiguration.

@Test
public void defaultConfiguration() {
    this.spring.register(DefaultLdapConfig.class).autowire();
    LdapAuthenticationProvider provider = ldapProvider();
    LdapAuthoritiesPopulator authoritiesPopulator = getAuthoritiesPopulator(provider);
    assertThat(authoritiesPopulator).hasFieldOrPropertyWithValue("groupRoleAttribute", "cn");
    assertThat(authoritiesPopulator).hasFieldOrPropertyWithValue("groupSearchBase", "");
    assertThat(authoritiesPopulator).hasFieldOrPropertyWithValue("groupSearchFilter", "(uniqueMember={0})");
    assertThat(authoritiesPopulator).extracting("searchControls").hasFieldOrPropertyWithValue("searchScope", SearchControls.ONELEVEL_SCOPE);
    assertThat(ReflectionTestUtils.getField(getAuthoritiesMapper(provider), "prefix")).isEqualTo("ROLE_");
}
Also used : LdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider) Test(org.junit.jupiter.api.Test)

Example 34 with LdapAuthenticationProvider

use of org.springframework.security.ldap.authentication.LdapAuthenticationProvider in project midpoint by Evolveum.

the class MidPointLdapAuthenticationProvider method createAuthenticatorProvider.

private LdapAuthenticationProvider createAuthenticatorProvider(LdapAuthenticator authenticator) {
    return new LdapAuthenticationProvider(authenticator) {

        @Override
        protected DirContextOperations doAuthentication(UsernamePasswordAuthenticationToken authentication) {
            DirContextOperations originalDirContextOperations = super.doAuthentication(authentication);
            return MidPointLdapAuthenticationProvider.this.doAuthentication(originalDirContextOperations);
        }

        @Override
        protected Authentication createSuccessfulAuthentication(UsernamePasswordAuthenticationToken authentication, UserDetails user) {
            Authentication authNCtx = super.createSuccessfulAuthentication(authentication, user);
            MidPointLdapAuthenticationProvider.this.createSuccessfulAuthentication(authentication, authNCtx);
            return authNCtx;
        }
    };
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) DirContextOperations(org.springframework.ldap.core.DirContextOperations) LdapModuleAuthentication(com.evolveum.midpoint.authentication.impl.module.authentication.LdapModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider)

Example 35 with LdapAuthenticationProvider

use of org.springframework.security.ldap.authentication.LdapAuthenticationProvider in project incubator-atlas by apache.

the class AtlasLdapAuthenticationProvider method getLdapBindAuthentication.

private Authentication getLdapBindAuthentication(Authentication authentication) {
    try {
        if (isDebugEnabled) {
            LOG.debug("==> AtlasLdapAuthenticationProvider getLdapBindAuthentication");
        }
        String userName = authentication.getName();
        String userPassword = "";
        if (authentication.getCredentials() != null) {
            userPassword = authentication.getCredentials().toString();
        }
        LdapContextSource ldapContextSource = getLdapContextSource();
        DefaultLdapAuthoritiesPopulator defaultLdapAuthoritiesPopulator = getDefaultLdapAuthoritiesPopulator(ldapContextSource);
        if (ldapUserSearchFilter == null || ldapUserSearchFilter.trim().isEmpty()) {
            ldapUserSearchFilter = "(uid={0})";
        }
        FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(ldapBase, ldapUserSearchFilter, ldapContextSource);
        userSearch.setSearchSubtree(true);
        BindAuthenticator bindAuthenticator = getBindAuthenticator(userSearch, ldapContextSource);
        LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator, defaultLdapAuthoritiesPopulator);
        if (userName != null && userPassword != null && !userName.trim().isEmpty() && !userPassword.trim().isEmpty()) {
            final List<GrantedAuthority> grantedAuths = getAuthorities(userName);
            final UserDetails principal = new User(userName, userPassword, grantedAuths);
            final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal, userPassword, grantedAuths);
            authentication = ldapAuthenticationProvider.authenticate(finalAuthentication);
            if (groupsFromUGI) {
                authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
            }
            return authentication;
        } else {
            LOG.error("LDAP Authentication::userName or userPassword is null or empty for userName " + userName);
        }
    } catch (Exception e) {
        LOG.error(" getLdapBindAuthentication LDAP Authentication Failed:", e);
    }
    if (isDebugEnabled) {
        LOG.debug("<== AtlasLdapAuthenticationProvider getLdapBindAuthentication");
    }
    return authentication;
}
Also used : BindAuthenticator(org.springframework.security.ldap.authentication.BindAuthenticator) User(org.apache.atlas.web.model.User) LdapContextSource(org.springframework.ldap.core.support.LdapContextSource) DefaultLdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator) GrantedAuthority(org.springframework.security.core.GrantedAuthority) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AuthenticationException(org.springframework.security.core.AuthenticationException) UserDetails(org.springframework.security.core.userdetails.UserDetails) Authentication(org.springframework.security.core.Authentication) FilterBasedLdapUserSearch(org.springframework.security.ldap.search.FilterBasedLdapUserSearch) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider)

Aggregations

LdapAuthenticationProvider (org.springframework.security.ldap.authentication.LdapAuthenticationProvider)35 Authentication (org.springframework.security.core.Authentication)17 LdapContextSource (org.springframework.ldap.core.support.LdapContextSource)14 BindAuthenticator (org.springframework.security.ldap.authentication.BindAuthenticator)14 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)13 UserDetails (org.springframework.security.core.userdetails.UserDetails)12 GrantedAuthority (org.springframework.security.core.GrantedAuthority)11 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)11 DefaultSpringSecurityContextSource (org.springframework.security.ldap.DefaultSpringSecurityContextSource)10 AuthenticationException (org.springframework.security.core.AuthenticationException)8 DefaultLdapAuthoritiesPopulator (org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator)8 Test (org.junit.jupiter.api.Test)7 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)7 ArrayList (java.util.ArrayList)6 User (org.apache.atlas.web.model.User)6 DefaultTlsDirContextAuthenticationStrategy (org.springframework.ldap.core.support.DefaultTlsDirContextAuthenticationStrategy)5 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)5 User (org.springframework.security.core.userdetails.User)5 ActiveDirectoryLdapAuthenticationProvider (org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider)5 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)3