필터란?
WAS에서 실행된 요청이 오면 이 요청이 서블릿으로 들어오는데, 서블릿으로 들어오기 전 처리하는 것이 필터
필터 흐름 :
HTTP 요청 -> WAS -> 필터 -> 서블릿 -> 컨트롤러
필터 체인 :
HTTP 요청 -> WAS -> 필터1 -> 필터2 -> 필터3 -> 서블릿 -> 컨트롤러
1) spring 이 시작되면, ServletContext 와 RootApplicationContext 가 load 되고, bean들을 관리한다
( * HTTP요청이 들어오면 Servlet 컨테이너에서 요청을 받는다.)
2) spring security 에 의해 설정된 SecurityFilterChain 이 DelegateFilterProxy와 FilterChainProxy 에 의해 관리된다.
(*Servlet 컨테이너 내의 필터들이 동작하는 중간에 DelegatingFilterProxy Filter가 요청을 받으면 springSecurityFilterChain 이름으로 생성된 빈을 AnnotationConfigServletWebServerApplicationContext 객체에서 찾는다. 찾은 Filter Bean이 FilterChainProxy. FilterChainProxy에 요청을 전달한다.)
3) request 가 들어오면 각 필터의 doFilter 메서드 호출에 따라 지정된 작업을 수행한다.
각 필터들은 request를 변경할 수 있다. 반대로 response 가 나갈때도 마찬가지.
4) 이 때 인증에 필요한 부분은 SecurityFilterChain 을 거치면서 수행된다.
- 핵심 필터는 SecurityContextPersistenceFilter, AbstractAuthenticationProcessingFilter 두 개.
- 첫번째로 SecurityContextPersistenceFilter는 인증된 결과를 저장할 SecurityContext 를 만든다.
- 두번째로 AbstractAuthenticationProcessingFilter는 인증된 결과인 Authenticate 인스턴스를 SecurityContext 에 저장한다. (소셜로그인 정보가 담겨있다.)
5) FilterChainProxy에서 필터들을 이용하여 보안처리를 진행한 후 최종적으로 SpringMVC의 DeispatcherServlet에 전달하여 요청에 대한 Servlet 처리
'spring' 카테고리의 다른 글
@RequestParam과 @PathVariable (0) | 2023.08.24 |
---|---|
[SpringSecurity] FailureHandler 구현 (0) | 2023.08.02 |
[Spring Security] Exception (0) | 2023.07.26 |
서버 재기동시 세션 (0) | 2023.02.14 |
Mybatis쿼리문 다중 파라미터 사용 (0) | 2023.02.11 |