我正在创建一个覆盖UsernamePasswordAuthenticationFilter
的自定义身份验证过滤器。这是我的配置的相关部分
protected void configure(HttpSecurity http) throws Exception {
http.addFilterAt(customAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)....
}
@Bean
public AuthenticationSuccessHandler authenticationSuccessHandler() {
return new SimpleUrlAuthenticationSuccessHandler("/login");
}
@Bean
public AuthenticationFailureHandler authenticationFailureHandler() {
return new SimpleUrlAuthenticationFailureHandler("/login");
}
@Bean
public SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new CompositeSessionAuthenticationStrategy(Arrays.asList(
new ChangeSessionIdAuthenticationStrategy(),
new CsrfAuthenticationStrategy(csrfTokenRepository())
));
}
@Bean
public CustomAuthenticationFilter customAuthenticationFilter() throws Exception {
CustomAuthenticationFilter authenticationFilter = new CustomAuthenticationFilter(actService.actuatorService());
authenticationFilter.setRequiresAuthenticationRequestMatcher(
new AntPathRequestMatcher("/login", "POST"));
authenticationFilter.setUsernameParameter("username");
authenticationFilter.setPasswordParameter("password");
authenticationFilter.setAuthenticationManager(authenticationManagerBean());
authenticationFilter.setAuthenticationSuccessHandler(authenticationSuccessHandler());
authenticationFilter.setAuthenticationFailureHandler(authenticationFailureHandler());
authenticationFilter.setSessionAuthenticationStrategy(sessionAuthenticationStrategy());
return authenticationFilter;
}
这是CustomAuthenticationFilter
的相关部分。
public class CustomAuthenticationFilter extends
UsernamePasswordAuthenticationFilter {
....
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException {
Authentication res = super.attemptAuthentication(request, response);
if (actuator.processRequest(request)) {
request.getSession().setAttribute("Actuator", true);
}
return res;
}
没有下面的代码段,我会看到一个错误弹出窗口:-TypeError: failed to fetch
将该代码段与父代码(AbstractAuthenticationProcessingFilter.successfulAuthentication
)中的代码进行比较,看起来唯一的区别是{{ 1}}
successHandler.onAuthenticationSuccess(request, response, authResult);
我是否成功配置了成功处理程序?