spring - SuccessAuthentication 中的 AbstractAuthenticationProcessingFilter 链
问题描述
您好,我有过滤器可以从 JWT 获取自动化
public class JwtAuthorizationFilter extends AbstractAuthenticationProcessingFilter {
public JwtAuthorizationFilter() {
super("/**");
}
@Override
public void setAuthenticationSuccessHandler(AuthenticationSuccessHandler successHandler) {
super.setAuthenticationSuccessHandler(successHandler);
}
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException {
super.successfulAuthentication(request, response, chain, authResult);
chain.doFilter(request, response);
}
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
String token = request.getHeader("Authorization");
//code
return getAuthenticationManager().authenticate(getAuthentication(token));
}
private UsernamePasswordAuthenticationToken getAuthentication(String token) {
// code
}
问题是,当我达到successfulAuthentication并执行chain.doFilter时,我在路径[]的上下文中为servlet [dispatcherServlet]收到异常“servlet.service()”抛出异常[请求处理失败;嵌套异常是java.lang.IllegalStateException:无法调用sendError() after response has been commited] with root cause" 而且我无法获得我的端点。我还注意到,即使我只登录一次,authResult 也会生成许多具有相同数据的(对象?)
@Edit我现在注意到,在成功授权后,弹簧试图到达我的控制器几次。第一个返回值,但其他只是抛出错误,我不知道为什么我有这个循环
解决方案
里面做了什么super.successfulAuthentication
?如果您对HttpServletResponse
对象进行任何修改,例如,通过更改 Http 状态代码,或者ResponseEntity
您将无法通过调用继续执行链中的下一个过滤器,chain.doFilter(request, response)
因为响应已提交并返回给客户端。
推荐阅读
- swift - 有没有办法访问 UIImagePickerController 的 CAMPreviewView 的 frame 属性
- c# - 如何使用函数将元素添加到 IList 集合
- cucumberjs - 将自定义数据添加到黄瓜报告
- powershell - Powershell如何获取json文件的值
- javascript - RegEx - 在句点后包含特定数字
- flutter - 如何在flutter web中修改标签
- javascript - toLocaleString、toLocaleDateString 和 toLocaleTimeString 有什么区别?
- mongodb - 我在我的 mongodb 数据库中看不到我的数据
- javascript - 即使在控制失焦后 AddEventListener() 仍在运行
- c# - 从 ASP.NET MVC 中的类方法重定向到控制器