-
Spring security authorization (servlet)spring 2022. 12. 14. 14:33
(세번째로 spring security 를 쓰고 있다. 첫번째는 소셜로그인, 두번째는 oauth api 풀링, 세번째는 mfa)
Spring security 아키텍처는 앞의 필터들을 통해 Authentication 을 결정하고, 그 다음에 interceptor 에서 Authorization 을 결정한다. (Authentication 과 Authorization 이 무엇인지는 cs 를 공부해 보자.)
https://docs.spring.io/spring-security/reference/servlet/authorization/architecture.html
Authorization Architecture :: Spring Security
It is a common requirement that a particular role in an application should automatically "include" other roles. For example, in an application which has the concept of an "admin" and a "user" role, you may want an admin to be able to do everything a normal
docs.spring.io
아키텍처에 대한 내용이 위에 나와 있다.
SecurityFilterChain 중에서 (일단 하나의 chain 만 있다고 하자.)
https://docs.spring.io/spring-security/reference/servlet/architecture.html#servlet-security-filters
Architecture :: Spring Security
Spring Security’s Servlet support is based on Servlet Filters, so it is helpful to look at the role of Filters generally first. The following image shows the typical layering of the handlers for a single HTTP request. The client sends a request to the ap
docs.spring.io
뒤에서 두번째에 FilterSecurityInterceptor 가 있는데, 여기서 Authentication 객체를 읽고 Authorization 을 결정한다. 결정하는 객체는 AuthorizationManager 이고, 레거시에는 AccessDecisionManager 이다. (이 레거시 api 는 쓰기가 힘들다 ㅠㅠ 그래서 객체지향적으로 개선됬던게 아닐까?) 5버전 이상에서는 AuthorizationManager 를 오버라이드 해서 편하게 커스터마이징 할 수 있다.
AuthorizationManager 는 (함수형) 인터페이스고 구현체를 샘플로 보면 된다.
AccessDecisionManager 도 인터페이스고, 샘플로 UnanimousBased, RoleVoter 등의 클래스를 보면 된다.
'spring' 카테고리의 다른 글
Spring 어플리케이션을 설정하는 방법 (0) 2023.01.28 Spring boot vs spring + tomcat (0) 2023.01.01 Spring @Async vs WebFlux / @Async 쓰는 이유? vs CompletableFuture (0) 2022.11.27 Spring security 5 복습 (0) 2022.06.19 @Transactional 에 대해 + 실험하기 (0) 2022.05.02