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

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

Introduction

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

Prototype

public void setUseAuthenticationRequestCredentials(boolean useAuthenticationRequestCredentials) 

Source Link

Document

Determines whether the supplied password will be used as the credentials in the successful authentication token.

Usage

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

private Authentication getADAuthentication(Authentication authentication) {
    try {/*w  w w .  j av  a  2 s .com*/
        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;
    }
}