Knowledge of Dev

SpringSecurity 용어 정리 및 흐름

jwkane 2024. 6. 6. 22:05

1. Spring Security 구성 요소

 

1-1 SecurityContext 및 SecurityContextHolder

SecurityContext

- 사용자 세션에 대한 인증 및 보안 관련 정보를 보유


SecurityContextHolder 

- SecurityContext에 액세스하기 위한 클래스

기본적으로 ThreadLocal 보안 컨텍스트 정보를 저장하는 데 사용

 


1-2. 인증

- 인증 요청에 대한 토큰 또는 요청이 처리된 후 인증된 주체
Principal : 현재 인증된 사용자, 일반적으로 사용자 개체 또는 사용자 이름을 나타냄

 


1-3. 인가

- 인증된 사용자에게 부여된 권한

( 일반적으로 USER 또는 ADMIN 과 같은 역할 )

 


1-4. UserDetails 및 UserDetailsService

UserDetails

- 핵심 사용자 정보를 제공


UserDetailsService

- 사용자별 데이터를 로드하기 위한 핵심 인터페이스

 

 


1-5. AuthenticationManager

- 인증을 위한 주요 전략 인터페이스

( 여러 AuthenticationProviders를 가질 수 있음 )

 


1-6. AuthenticationProvider 

- AuthenticationManager의 구현체

ex) 사용자 데이터를 로드(UserDetailsService)하는 데 사용

 


1-7. Interceptor

- 보안 개체 호출(예: HTTP 요청 또는 메서드 호출)을 가로채서 승인되었는지 확인

 

 

 


2. 인증 프로세스 흐름

 

2-1 사용자 로그인

- 사용자는 로그인 양식을 통해 자격 증명(사용자 이름 및 비밀번호)을 제출

 


2-2 AuthenticationFilter

- 자격 증명은 (like UsernamePasswordAuthenticationFilter) 에 의해 가로채어집니다 .

 

 

2-3 AuthenticationManager

- 필터는 자격 증명을 AuthenticationManager

 

 

2-4 AuthenticationProvider

- AuthenticationManager인증 요청을 적절한 AuthenticationProvider

 


2-5 UserDetailsService

- 사용자별 데이터를 로드하는 데 AuthenticationProvider사용됩니다 .UserDetailsService

 

 

2-6 인증 성공 또는 실패 

- 사용자 데이터를 기반으로 AuthenticationProvider사용자를 인증하거나 예외를 발생시킵니다

 

2-7 SecurityContext

- 인증이 성공하면 사용자의 세부 정보가 SecurityContext

 

3. 인가 프로세스 흐름

3-1 보안 인터셉터(Security Interceptor) 

- 요청은 보안 인터셉터(예 FilterSecurityInterceptor: 웹 요청)에 의해 차단


3-2 AccessDecisionManager

- 인터셉터는 요청을 AccessDecisionManager


3-3 AccessDecisionVoter

- AccessDecisionManager 사용하여

- AccessDecisionVoter 사용자의 역할과 권한에 따라 리소스에 대한 액세스를 허용할지 거부할지 결정


3-4 결정 

- 유권자의 결정에 따라 접근이 허용되거나 거부

 

 

4. 필터 및 필터 체인


4-1 UsernamePasswordAuthenticationFilter

- 양식 기반 로그인을 처리


4-2 BasicAuthenticationFilter

- HTTP 기본 인증을 처리


4-3 SecurityContextPersistenceFilter

- SecurityContext세션에 대해 복원


4-4 ExceptionTranslationFilter

- 모든 액세스 거부 예외 및 인증 예외를 처리


4-5 FilterSecurityInterceptor

- 권한 부여 결정 요청을 차단

 


5. 커스터마이징


5-1 CustomAuthenticationProvider

- 인증  논리 커스터마이징


5-2 CustomUserDetailsService

- 사용자 정의 데이터 소스에서 사용자 세부 정보 가져옴

 

5-3 CustomSecurityFilter

- 보안 필터 체인에 사용자 정의 필터 추가

 

5-4 Method Security

- 특정 메소드를 보호하려면 @PreAuthorize, @Secured 와 같은 주석 사용

 

오늘의 배운점

Spring Security 큰틀의 흐름에 대해 배웠고

각 용어들의 역할과 개념을 알아가는데에 도움이 되었다.