Я пытаюсь добавить дополнительную информацию в ответ на ошибку входа в систему от Spring Security.
Вот моя конфигурация:
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final CustomAuthenticationProvider authProvider;
private final CustomAuthEntryPoint customAuthEntryPoint;
public SecurityConfig(CustomAuthenticationProvider authProvider, CustomAuthEntryPoint customAuthEntryPoint) {
this.authProvider = authProvider;
this.customAuthEntryPoint = customAuthEntryPoint;
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.cors().and()
.logout().deleteCookies("SESSION").and()
.authorizeRequests()
.antMatchers("/actuator/**").permitAll()
.anyRequest().authenticated().and()
.httpBasic().authenticationEntryPoint(customAuthEntryPoint).and()
.csrf().disable();
}
}
@Component
public class CustomAuthEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
System.out.println("entrypoint " + exception.getClass().getName());
response.getOutputStream().print(exception.getClass().getName());
response.sendError(401, exception.getClass().getName());
}
}
Когда я пытаюсь войти, он идетпервый раз в пользовательской точке входа с хорошим исключением (BadCredentialsException
), но затем я думаю, что Spring пытается запросить к /error
, а затем он возвращается в точку входа с InsufficientAuthenticationException
(из ExceptionTranslationFilter.sendStartAuthentication
).
И в ответе у меня есть 401 без какого-либо тела, даже имя класса исключения, как определено в точке входа.
Есть идеи, что не так с конфигурацией?