spring-projects / spring-security

Spring Security
http://spring.io/projects/spring-security
Apache License 2.0
8.72k stars 5.87k forks source link

Allow hideUserNotFoundExceptions property to be set in AuthenticationManagerBuilder #4813

Open M3lkior opened 6 years ago

M3lkior commented 6 years ago

Summary

I'm using the LdapAuthenticationProviderConfigurer for my spring security LDAP configuration.

Actual Behavior

Actually, i don't find a way to set the hideUserNotFoundExceptions property in the built LdapAuthenticationProvider (by LdapAuthenticationProviderConfigurer)

Expected Behavior

Allow hideUserNotFoundExceptions property to be set in auth .ldapAuthentication() without redefining a complet LdapAuthentificationProvider

@Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .ldapAuthentication()
}

Configuration

@Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .ldapAuthentication()

            .userDnPatterns(securityProperties.getLdap().getUserDn())
            .groupSearchFilter("(uniqueMember={0})")
            .groupSearchBase(securityProperties.getLdap().getGroupDn())
            .userDetailsContextMapper((customUserDetailsContextMapper())

            .contextSource(contextSource())
            .rolePrefix(ROLE_PREFIX)
            .passwordCompare()
            .passwordAttribute("userPassword");

    }

Version

1.5.1.RELEASE

Sample

dmitryogorodnikov63 commented 2 years ago

Temporary solution:

@Component
public class LdapAuthenticationProviderBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof LdapAuthenticationProvider) {
            ((LdapAuthenticationProvider) bean).setHideUserNotFoundExceptions(false);
        }
        return bean;
    }
}