springframework/시작하자SpringSecurity 44

24.SpringSecurity 필터, 아키텍쳐 정리

Spring Security Initalization 2개의 WebSecurityConfigurerAdapter 상속클래스가 있다고 가정한다. 설정클래스에서 정의한 여러 API 들을 정의 API에 맞는 클래스에서 Filter Type Bean을 생성 Filter Type Bean 들을 생성하는 클래스는 HttpSecurity ( 각각의 설정클래스의 Filter Type Bean 명단은 SecurityFilterChain의 Filters 필드에 저장 되는 것 기억 ) HttpSecurity의 Filter Type Bean(Filters) 들은 WebSecurity 객체에 저장 됨 WebSecurity의 FilterChainProxy 객체 생성시 FilterChainProxy의 생성자에 SecurityFil..

23.AccessDesicionManager, AccessDecisionVotor

AccessDecisionManager 인증정보 , 요청정보, 권한정보 를 이용해서 사용자의 자원접근 허가여부를 결정하는 주체 여러개의 Votor 를 가지며 Votor 들에게 허용, 거부 , 보류 값을 각각 리턴받아 판단, 결정한다. 접근 거부시 AccessDeniedException을 발생 AcceessDesicionManager 의 접근 결정 유형에 따른 구현객체들 AffermativeBased : Votor 클래스 중 하나라도 접근 허가를 내면 접근 허가 ConsensusBased : 다수표에 의해 판단, 동수일경우 default 값은 허가이며, allowIfEqualGrantedDeniendDecisions 속성을 false 로 주면 접근 거부 설정 됨 UnanimousBased : 하나의 Vot..

22.Authorization, FilterSecurityInterceptor

Authorization 무엇이 허가되었는지 증명하는 것이다. SpringSecurity 는 Authentication 과 Authorization 으로 영역을 나눈다. Authentication 영역에서는 사용자가 자원에 접근하기위해 Request 를 보낼 때 인증 여부를 확인한다. Authorization 영역에서는 인증이 완료 된 후 사용자가 특졍 자원에 접근할 때에 사용자의 권한이 특정 자원의 접근 권한에 충분하는 지의 심사를 한다. SpringSecurity 가 지원하는 권한 계층 웹 계층 : Presentation Tier 의 URL 요청 단위 레벨 보안 서비스 계층 : Service Tier 의 메서드 단위 레벨 보안 도메인 계층(Access Control List, 접근 제어 목록) : P..

21.AuthenticationProvider

AuthenticationProvider 실질적으로 인증처리를 하는 핵심 클래스로 Interface 이다. AuthenticaionProvider를 구현하여 서비스에 맞는 인증방식을 만드는 것이 주를 이룬다. 재정의 할 메서드 boolean support(authentication) : 조건의 기준 검사. Authentication authenticate(authentication) : 실질적 인증처리를 위한 검증 매개 값으로는 username , password 를 가진 Authentication 객체를 가진다. 흐름 구조를 알면 메서드 재정의 방식을 이해할 수 있을듯 하다. authenticate(authentication) 에서 username 검증을 위해 UserDetailsService 호출 ,..

20.AuthenticationMananger를 구현한 ProviderManager

ProviderManager 는 AuthenticationManager 의 구현객체이다. 동작 구조 인증을 요구하는 Filter( UsernamePasswordAuthenticationFilter, RemeberMeAuthenticationFilter...) 에서 인증 요청을 받게되면 AuthenticationProvider의 구현체인 ProviderManager가 작동 ProviderManager 는 해당 인증방식 (Form Login, Remember Me , Oauth..) 에 따라서 자신이 가지고 있는 AuthenticationProvider 중 알맞은 AuthenticationProvider 를 찾는다. (DaoAuthenticationProvider , RememberMeAuthenticati..

19.Authentication Flow

Authentication Flow : 인증의 흐름 Client Login Request UsernamePasswordAuthenticationFilter 가 수렴하여 username , password 를 담은 Authentication 토큰생성 AuthenticationManager 에게 Authentication 객체를 넘겨 처리 위임 AuthenticationManager는 인증 관리자로 적절한 AuthenticationProvider에게 넘기는 역할 만을 함 AuthenticationProvider 는 Authentication 객체를 받아 실제 인증 처리를 시작 AuthenticationProvider는 UserDetailsService에게 username 을 주어 User객체 요청 : loa..

18.인증 저장소 필터 , SecurityContextPersistenceFilter

SecurityContextPersistenceFilter SecurityContext 객체의 생성, 저장, 조회 를 담당 FilterChainProxy의 Filter 중 2번 째에 위치 접근에 따른 동작 익명사용자의 접근 SecrutityContext 객체를 생성하여 SecurityContextHolder에 저장함 AnonymousAuthenticationFilter 에서 만든 AnonymousAuthenticationToken 객체를 SecurityContext에 저장시킴 인증 시도 시 SecurityContext 객체를 생성하여 SecurityContextHolder에 저장 UsernamePasswordAuthenticationFilter 에서 인증 성공 후 만든 UsernamePasswordAut..

17.SecurityContextHolder, SecurityContext

SecurityContext Authentication 의 보관소, 언제든 Authentication을 꺼내 사용할 수 있도록 제공되는 클래스이다. ThreadLocal 에 저장되어 아무 곳에서 참조가 가능하도록 설계됨 ThreadLocal 은 Thread 하나에 할당 된 저장소이다. 즉 Thread-Safe 하다. ThreadLocal은 인증 완료시 HttpSession 저장되어 Application 전반에서 참조가 가능하다. SecurityContextHolder SecurityContext를 감싸 저장하는 객체, 저장방법은 3가지이다. MODE_THREADLOCAL : 하나의 스레드 당 SecurityContext 를 할당 , default 값 MODE_INHERITABLETHREADLOCAL : ..

16.Authentication

인증, Authentication 스스로 누구인지 증명하는 것이다. Authentication 객체는 사용자의 인증 정보를 담는 Token 개념이다. (UsernameAuthenticationToken , AnonymousAuthenticationToken , RememberMeAuthenticationToken...) 인증 시의 id , password를 담아 인증 검증을 위해 전달되어 사용된다. 인증 후 최종 Authentication 객체에는 사용자 정보를 담은 User 객체와 권한정보인 Authority가 들어있다. Authentication 객체는 SecurityContext에 저장되어 전역적으로 참조가 가능 Authentication authentication = SecurityContextH..

15.필터 초기화와 다중 보안 설정

다중 보안 설정, 필터 초기화 방식 다중 보안 설정은 즉, WebSecurityConfigurerAdapter 상속클래스가 다중임을 뜻함. 각각의 WebSecurityConfugurerAdapter 객체들은 각각의 HttpSecurity를 통해 보안 API 에 맞는 Filter들을 가지고 있음 각각의 SpringSecurity 설정 클래스마다 SecurityFilterChain 객체를 각각 생성. WebSecurityConfigurerAdapter 마다 지정된 API 에 맞는 Filter들의 명단을 SecurityFilterChain 객체의 Filters 필드에 저장 또한 각각의 RequestMapping 들을 SecurityFilterChain 객체의 RequestMatcher 필드(AntRequest..