天天看点

6、spring security拦截器之WebAsyncManagerIntegrationFilter

WebAsyncManagerIntegrationFilter:主要是设置了SecurityContextCallableProcessingInterceptor拦截器。该拦截器是在处理前后设置或清除SecurityContext

@Override
protected void doFilterInternal(HttpServletRequest request,
      HttpServletResponse response, FilterChain filterChain)
      throws ServletException, IOException {
   WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);

   SecurityContextCallableProcessingInterceptor securityProcessingInterceptor = (SecurityContextCallableProcessingInterceptor) asyncManager
         .getCallableInterceptor(CALLABLE_INTERCEPTOR_KEY);
   if (securityProcessingInterceptor == null) {
      asyncManager.registerCallableInterceptor(CALLABLE_INTERCEPTOR_KEY,
            new SecurityContextCallableProcessingInterceptor());
   }

   filterChain.doFilter(request, response);
}