Example usage for org.springframework.security.ldap.authentication BindAuthenticator setUserDnPatterns

List of usage examples for org.springframework.security.ldap.authentication BindAuthenticator setUserDnPatterns

Introduction

In this page you can find the example usage for org.springframework.security.ldap.authentication BindAuthenticator setUserDnPatterns.

Prototype

public void setUserDnPatterns(String[] dnPattern) 

Source Link

Document

Sets the pattern which will be used to supply a DN for the user.

Usage

From source file:org.osiam.configuration.LdapAuthentication.java

@Bean
public LdapAuthenticator bindAuthenticator() {
    BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource());
    bindAuthenticator.setUserDnPatterns(dnPatterns);
    bindAuthenticator/*from   ww w  .j av a  2 s  . c o  m*/
            .setUserAttributes(Iterables.toArray(ldapToScimAttributeMapping().ldapAttributes(), String.class));
    return bindAuthenticator;
}

From source file:com.evolveum.midpoint.web.boot.LdapSecurityConfig.java

@Bean
public BindAuthenticator bindAuthenticator() {
    BindAuthenticator auth = new BindAuthenticator(contextSource());
    if (StringUtils.isNotEmpty(ldapDnPattern)) {
        auth.setUserDnPatterns(new String[] { ldapDnPattern });
    }/*from ww w  . j a  v a2 s .c  o  m*/
    if (StringUtils.isNotEmpty(ldapSearchPattern)) {
        auth.setUserSearch(userSearch());
    }

    return auth;
}

From source file:org.osiam.auth.configuration.LdapConfiguration.java

@Bean
public OsiamLdapAuthenticationProvider createLdapAuthProvider() {
    if (isLdapConfigured) {

        createLdapToScimAttributeMapping();

        DefaultSpringSecurityContextSource contextSource = createLdapContextSource();

        BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource);
        bindAuthenticator.setUserDnPatterns(dnPatterns);
        bindAuthenticator.setUserAttributes(attributes);

        OsiamLdapUserContextMapper mapper = new OsiamLdapUserContextMapper(scimLdapAttributes);
        DefaultLdapAuthoritiesPopulator authoritiesPopulator = new DefaultLdapAuthoritiesPopulator(
                contextSource, groupSearchBase);

        OsiamLdapAuthenticationProvider provider = new OsiamLdapAuthenticationProvider(bindAuthenticator,
                authoritiesPopulator, mapper);

        authenticationManager.getProviders().add(provider);

        return provider;
    }/*  w  w  w.j  a va2s . com*/
    return null;
}

From source file:de.thm.arsnova.config.SecurityConfig.java

@Bean
public LdapAuthenticator ldapAuthenticator() throws Exception {
    BindAuthenticator authenticator = new BindAuthenticator(ldapContextSource());
    authenticator.setUserDnPatterns(new String[] { ldapUserDn });

    return authenticator;
}

From source file:org.apache.atlas.web.security.AtlasLdapAuthenticationProvider.java

private Authentication getLdapAuthentication(Authentication authentication) {

    if (isDebugEnabled) {
        LOG.debug("==> AtlasLdapAuthenticationProvider getLdapAuthentication");
    }//from  w w w.  j  a  v a  2 s  .c  o  m

    try {
        // taking the user-name and password from the authentication
        // object.
        String userName = authentication.getName();
        String userPassword = "";
        if (authentication.getCredentials() != null) {
            userPassword = authentication.getCredentials().toString();
        }

        // populating LDAP context source with LDAP URL and user-DN-pattern
        LdapContextSource ldapContextSource = new DefaultSpringSecurityContextSource(ldapURL);

        ldapContextSource.setCacheEnvironmentProperties(false);
        ldapContextSource.setAnonymousReadOnly(true);

        // Creating BindAuthenticator using Ldap Context Source.
        BindAuthenticator bindAuthenticator = new BindAuthenticator(ldapContextSource);
        //String[] userDnPatterns = new String[] { rangerLdapUserDNPattern };
        String[] userDnPatterns = ldapUserDNPattern.split(";");
        bindAuthenticator.setUserDnPatterns(userDnPatterns);

        LdapAuthenticationProvider ldapAuthenticationProvider = null;

        if (!StringUtils.isEmpty(ldapGroupSearchBase) && !StringUtils.isEmpty(ldapGroupSearchFilter)) {
            // Creating LDAP authorities populator using Ldap context source and
            // Ldap group search base.
            // populating LDAP authorities populator with group search
            // base,group role attribute, group search filter.
            DefaultLdapAuthoritiesPopulator defaultLdapAuthoritiesPopulator = new DefaultLdapAuthoritiesPopulator(
                    ldapContextSource, ldapGroupSearchBase);
            defaultLdapAuthoritiesPopulator.setGroupRoleAttribute(ldapGroupRoleAttribute);
            defaultLdapAuthoritiesPopulator.setGroupSearchFilter(ldapGroupSearchFilter);
            defaultLdapAuthoritiesPopulator.setIgnorePartialResultException(true);

            // Creating Ldap authentication provider using BindAuthenticator and Ldap authentication populator
            ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator,
                    defaultLdapAuthoritiesPopulator);
        } else {
            ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator);
        }

        // getting user authenticated
        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 {
            return authentication;
        }
    } catch (Exception e) {
        LOG.error("getLdapAuthentication LDAP Authentication Failed:", e);
    }
    if (isDebugEnabled) {
        LOG.debug("<== AtlasLdapAuthenticationProvider getLdapAuthentication");
    }
    return authentication;
}

From source file:org.apache.atlas.web.security.AtlasLdapAuthenticationProvider.java

private BindAuthenticator getBindAuthenticator(FilterBasedLdapUserSearch userSearch,
        LdapContextSource ldapContextSource) throws Exception {
    BindAuthenticator bindAuthenticator = new BindAuthenticator(ldapContextSource);
    bindAuthenticator.setUserSearch(userSearch);
    String[] userDnPatterns = new String[] { ldapUserDNPattern };
    bindAuthenticator.setUserDnPatterns(userDnPatterns);
    bindAuthenticator.afterPropertiesSet();
    return bindAuthenticator;
}