Example usage for org.springframework.security.ldap.authentication.ad ActiveDirectoryLdapAuthenticationProvider ActiveDirectoryLdapAuthenticationProvider

List of usage examples for org.springframework.security.ldap.authentication.ad ActiveDirectoryLdapAuthenticationProvider ActiveDirectoryLdapAuthenticationProvider

Introduction

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

Prototype

public ActiveDirectoryLdapAuthenticationProvider(String domain, String url) 

Source Link

Usage

From source file:com.expedia.seiso.SeisoWebSecurityConfig.java

private void configureActiveDirectory(AuthenticationManagerBuilder auth) throws Exception {
    String domain = seisoProperties.getAdDomain();
    String url = seisoProperties.getAdUrl();
    if (domain != null) {
        ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(
                domain, url);/*from ww w  .  j  ava2s .  c  o  m*/
        provider.setUserDetailsContextMapper(userDetailsContextMapper());

        // Hm, this doesn't seem to have any effect, so handle the mapping in the SeisoUserDetailsContextMapper.
        //         provider.setAuthoritiesMapper(grantedAuthoritiesMapper());

        auth.authenticationProvider(provider);
    }
}

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

private Authentication getADAuthentication(Authentication authentication) {
    try {/*from  w ww  . j a va2s.c o  m*/
        String userName = authentication.getName();
        String userPassword = "";
        if (authentication.getCredentials() != null) {
            userPassword = authentication.getCredentials().toString();
        }

        ActiveDirectoryLdapAuthenticationProvider adAuthenticationProvider = new ActiveDirectoryLdapAuthenticationProvider(
                adDomain, adURL);
        adAuthenticationProvider.setConvertSubErrorCodesToExceptions(true);
        adAuthenticationProvider.setUseAuthenticationRequestCredentials(true);

        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 = adAuthenticationProvider.authenticate(finalAuthentication);
            if (groupsFromUGI) {
                authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
            }
            return authentication;
        } else {
            LOG.error("AD Authentication Failed userName or userPassword is null or empty");
            return null;
        }
    } catch (Exception e) {
        LOG.error("AD Authentication Failed:", e);
        return null;
    }
}