Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinte loop when bad credentials are entered in spring security/form login

As much as I have been able to determine it gets into infinite loop only when following bean is enabled on my . If this bean is enabled WebSecurityConfigurerAdapter extended class.

@Override
@Bean(name = "MyAuthManager")
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

With this bean enabled, if I enter bad credentials, it gets into infinite loop. I have custom authentication provider extending from AbstractUserDetailsAuthenticationProvider. This class, as per contract throws UsernameNotFoundException if user is not found. I can see calls coming to my retrieveUser continuously.

Removing @Bean annotation, makes it work properly. But I need to access authentication manager at some other place.

like image 485
user871199 Avatar asked Jan 15 '15 03:01

user871199


1 Answers

I don't understand all the mechanics of things get glued together, but authenticationManagerBean was big clue. Somehow when spring security created authentication manager chain, parent manager was set to self manager if I use authenticationManagerBean. My solution was to set parent authentication manager to null in during configuration. It must be my mistake or lack of my understanding somewhere

@Override
    protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
        auth.parentAuthenticationManager(null);
    }
like image 181
user871199 Avatar answered Sep 26 '22 00:09

user871199