Я уже исследовал это и подумал, что это комментарий (ниже ответа на самом деле в этой теме: >ProviderManager.authenticate вызывается дважды для BadCredentialsException) было бы моим решением ... но я все еще получаю двойную отправку/вызовы для аутентификации. У второго каждый раз пустой пароль. Первый вызов имеет учетные данные.
Ниже представлен класс Java Config и класс CustomAuthProvider.
@Configuration
@EnableWebSecurity
public class UserWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
//@formatter:off
http.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/home**", "/login**","/create_user")
.permitAll().anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/login")
.failureUrl("/login?error")
.and()
.logout()
.logoutSuccessUrl("/login?logout")
.permitAll()
.and()
.exceptionHandling().accessDeniedPage("/login?denied") //in this simple case usually due to a InvalidCsrfTokenException after session timeout
.and()
.csrf()
.ignoringAntMatchers("/rest/**")
.and()
.sessionManagement().enableSessionUrlRewriting(false)
.and()
.headers().frameOptions().deny();
}
... затем customAuthProvider...
@Component
public class CustomAuthProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
if (authentication.getName() == null) {
logger.warn("empty userName");
return null;
}
if (authentication.getCredentials() == null) {
logger.warn("empty password");
return null;
}
// code to check credentials etc ...
if (!(user != null && userHash.equals(storedHash))) {
System.out.println("fail");
return null;
}
return new UsernamePasswordAuthenticationToken(user,password);
}