스터디-Spring

[스프링 시큐리티] @Async & WebAsyncManagerIntegrationFilter

일태우 2022. 1. 21. 21:52
반응형

Async 웹 MVC를 지원하는 필터

 

스프링 MVC의 Async 기능(핸들러에서 Callable을 리턴할 수 있는 기능)을 사용할 때에도 SecurityContext를 공유하도록 도와주는 필터

 

해당 필터는 AsyncManager에 Interceptor를 등록하고

핵심 기능은 SecurityContextCallableProcessingInterceptor 에서 구현

  • PreProcess: SecurityContext를 설정
  • Callable: 다른 쓰레드이지만 그 안에서는 동일한 SecurityContext를 참조할 수 있음
  • PostProcess: SecurityContext를 clear

@Async를 사용하는 서비스를 호출하는 경우, Thread가 다르기 때문에 SecurityContext를 공유받지 못한다.

기본전략은 MODE_TREADLOCAL이다.

SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
  • SecurityContext를 자식 쓰레드에도 공유하는 전략.
  • @Async를 처리하는 쓰레드에서도 SecurityContext를 공유받을 수 있다.

참고

반응형