概述
我们可以通过集成AbstractAuthenticationProcessingFilter
或者现有的过滤器来完成自定义的身份认证过滤器
身份验证过滤器的主要责任是何时进行身份认证以及如何进行身份认证等
实现案例
以下是实现案例,可根据需求进行拓展和剔除
1. 继承AbstractAuthenticationProcessingFilter
public class GetRequestAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
}
2. 重写attemptAuthentication()
方法
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
if (request.getMethod().toUpperCase().equals("GET")) {
// 创建身份认证对象
UsernamePasswordAuthenticationToken token = new