我正在使用弹簧安全
我有表格登录
在这里我可以设置一个authentication-success-handler-ref
,如何在我的基本身份验证中添加一个:
我认为abour会覆盖BasicAuthenticationFilter,但我怎么能注入我的cutom类
您无法为BASIC身份验证设置身份验证成功处理程序.但是,您可以扩展BasicAuthenticationFilter并覆盖onSuccessfulAuthentication方法:
@Component("customBasicAuthFilter")
public class CustomBasicAuthFilter extends BasicAuthenticationFilter {
@Autowired
public CustomBasicAuthFilter(AuthenticationManager authenticationManager) {
super(authenticationManager);
}
protected void onSuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Authentication authResult) {
// Do what you want here
}
}
在安全配置中注入它,例如:
...
更新:或使用Java配置而不是XML:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.addFilterAt(customBasicAuthFilter, BasicAuthenticationFilter.class)
.exceptionHandling().authenticationEntryPoint(basicEntryPoint);
}