java - 管理错误凭据的 SpringSecurity failureHandler 或 failureUrl 被忽略
问题描述
我正在将 SpringBoot 与 SpringSecurity 一起使用。我集成了 LDAP 身份验证过程。我没有使用 REST 方法,我只是使用 Thymeleaf 库显示页面。一切正常。
现在,我尝试在凭据错误的情况下显示相同的登录页面和身份验证错误消息。
我以这种方式配置了安全配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors();
http
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.csrf().disable()
.formLogin()
.loginPage("/")
//.failureUrl("/authError")
//.failureHandler(getAuthenticationFailureHandler())
.permitAll()
.and()
.httpBasic().disable()
.authorizeRequests()
.antMatchers("/",
"/error",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/webjar/**",
"/**/*.js").permitAll()
.antMatchers("/login**").permitAll()
.anyRequest().authenticated();
http.addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
}
@Bean
public AuthenticationFailureHandler getAuthenticationFailureHandler() {
return new LdapAuthenticationFailureHandler();
}
public class LdapAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(HttpServletRequest request,
HttpServletResponse response, AuthenticationException exception)
throws IOException, ServletException {
//mylogic
}
我想使用自定义处理程序来管理这个场景,但是如果我尝试在AuthenticationFailure 方法上放置一个断点,它就永远不会被调用。
如果我尝试使用自定义控制器配置 .failureUrl("/login-error") 也会出现同样的问题。
我该如何解决这个问题?
解决方案
推荐阅读
- function - 如何在 Julia 中创建一个函数不返回任何内容?
- python - 如何将 jax vmap 用于嵌套循环?
- regex - AWS Athena regexp_extract() 损坏
- python - pywinauto paython我的鼠标光标在使用空间动作时移动为什么
- python - 过滤除数字中的“+”和“-”之外的特殊符号,例如 (!@#$%..etc)
- javascript - 使用 JQuery 将 Javascript 本地存储变量发送到 MySql 数据库
- keras - 100 维向量的监督分类
- python - 方法 POST 不允许 [DRF]
- python - Pandas Group by dict 值
- android - 更新到新的库版本后,导航撰写状态保存中断