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

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

Introduction

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

Prototype

public void setConvertSubErrorCodesToExceptions(boolean convertSubErrorCodesToExceptions) 

Source Link

Document

By default, a failed authentication (LDAP error 49) will result in a BadCredentialsException .

Usage

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

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