Step-by-Step
[Spring] Spring Security 본문
Spring Security에 대한 개념과 구조를 공부하려고 한다.
Spring Security
- 스프링 기반 애플리케이션의 보안을 담당하는 스프링의 하위 프레임워크
- Spring Security는 인증(Authentication)과 권한(Authorization)에 대한 부분을 Filter의 흐름에 따라 처리
인증과 인가
1) 인증(Authentication)
- 해당 사용자가 본인이 맞는지를 확인하는 절차
- 보호된 리소스에 대해 접근하는 자가 누구인지 확인하는 절차
- 인증관리자 : UsernamePasswordAuthenticationFilter
2) 인가(Authorization)
- 인증된 사용자가 요청한 자원에 접근 가능한지를 결정하는 절차
- 사용자가 어떤 일을 할 수 있는지 권한을 설정하는 절차
- 보호된 리소스에 접근할 수 있는 권한을 판단/확인
- 인가 관리자 : FilterSecurityIntercepter
3) 접근주체(Principal)
- 보호된 리소스에 접근하는 대상
4) 비밀번호(Credentials)
- 리소스에 접근하는 대상의 비밀번호
5) 권한(Authorities)
- GrantAuthority 권한을 포함
GrandAutority
- 사용자에게 부여된 상위 수준의 권한
- 인증받으려는 주체에게 부여된 권한
- 사용자, 관리자 등등 해당 권한을 나타냄
- 이 역할로 특정 URI에 대한 권한이나 접근 권한을 제어할 수 있음
- username, password 기반 인증을 사용할 시 권한은 UserDetailService가 가짐
※ UserDetailService
- AuthenticationProvider에서 username, password로 인증하기 위해 해당 사용자 이름, 비밀번호, 기타 속성 검색하는데 이용
Spring Security 특징
- 보안과 관련하여 체계적으로 많은 옵션을 제공하여 편리하게 사용 가능
- Filter 기반으로 동작하여 MVC와 분리하여 관리 및 동작
- 어노테이션을 통한 간단한 설정
- Spring Security는 기본적을 세션 & 쿠키 방식으로 인증
※ Filter : Dispatcher Servlet 으로 가기 전에 적용되므로 먼저 URL요청을 받지만,
Intercepter는 Dispatcher와 Controller 사이에 위치
Spring Security 구조
1) SecurityContextHolder
- 시큐리티가 최종적으로 제공하는 객체 but 인증에 대한 정보는 Authentication 객체에 존재
- SecurityContextHolder은 SecurityContext 객체를 Thread-local로 제공
※ Thread-local :같은 스레드에서는 매개로 주고받지 않아도 언제든지 인증정보에 접근할 수 있음
2) AuthoenticationManager <<Interface>>
- 인증 처리 관련 인터페이스
3) ProviderManager
- AuthenticationManager의 구현체
- 실제 인증 처리
Filter 구조
[참조]
https://velog.io/@seongwon97/security
https://velog.io/@lsj8367/Authentication
https://velog.io/@lsj8367/Spring-Security-%EA%B0%9C%EC%9A%94
https://velog.io/@sa833591/Spring-Security-5-Spring-Security-Filter-%EC%A0%81%EC%9A%A9
'언어 > Java Spring' 카테고리의 다른 글
[Spring] Gradle vs Maven (0) | 2022.03.28 |
---|---|
[Java Spring] JPA에 대한 이해 (0) | 2022.03.16 |