| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 |
- Routing Key
- securitycontextholderfilter
- 스프링 부트
- DLQ
- @ComponentScan
- JdbcTemplate
- Spring Data JPA
- docker
- 서블릿 컨테이너
- kafka
- @Transactional
- docker compose
- redis
- Web
- Dead Letter Queue
- JWT
- Spring
- 쿠버네티스
- 페이징
- mybatis
- JPQL
- 지연 로딩
- MSA
- Spring Container
- CORS
- DI
- JPA
- 컨테이너
- dockerhub
- AWS
- Today
- Total
look-forest
내부 구조 - Authorization (인가) 본문
인가 전체 구조

AuthorizationFilter
AuthorizationManager 를 사용하여 Access Control 또는 예외 처리 하는 필터.
대부분의 경우 FilterChainProxy에 마지막 필터로 들어있다. (인증을 거친 후 최종 인가)
아래와 같이 SecurityFilterChain의 authorizeHttpRequests()로 설정한 값에 따라 인가를 수행한다.
http
.authorizeHttpRequests((auth) -> auth
.requestMatchers("/").permitAll()
.anyRequest().permitAll());
주요 로직 : doFilter()
public class AuthorizationFilter extends GenericFilterBean {
public void doFilter() {
// 인가 작업 수행
try {
// 인가 매니저를 통해 인가 확인
AuthorizationDecision decision = this.authorizationManager.check(this::getAuthentication, request);
this.eventPublisher.publishAuthorizationEvent(this::getAuthentication, request, decision);
if (decision != null && !decision.isGranted()) {
// 인가 권한이 안맞다면 예외 발생
throw new AccessDeniedException("Access Denied");
}
chain.doFilter(request, response);
}
finally {
// 최종적으로 모든 작업 처리 후 사용 기록 삭제
request.removeAttribute(alreadyFilteredAttributeName);
}
}
}

AuthorizationManager
모든 Authentication 구현은 List<GrantedAuthority>를 저장할 수 있고, 이들은 principal에 부여된 권한을 나타낸다.
GrantedAuthority들은 AuthenticationManager에 의해 Authentication에 삽입되며,
나중에 인가 결정을 내릴 때 AuthorizationManager에 의해 읽힌다.
해당 Authentication이 특정한 Object에 접근할 때 필요한 ConfigAttributes(permitAll, hasRole)를 만족하는지 확인한다.
( AuthorizationManager 는 구 버전의 AccessDecisionManager와 AccessDecisionVoter를 대체한다 )
AuthorizationManager 인터페이스의 구현 메서드
// 엑세스 허용 : 양수의 AuthorizationDecision 반환
// 엑세스 거부 : 음수의 AuthorizationDecision 반환
// 결정 x : null AuthorizationDecision 반환
AuthorizationDecision check(Supplier<Authentication> authentication, T object);
Spring Security는 개별 AuthorizationManager 와 협력할 수 있는 위임 형식의 AuthorizationManager 를 제공한다.
- request에 대한 인가를 위해서는 RequestMatcherDelegatingAuthorizationManager
- 메서드 보안의 경우 AuthorizationManagerBeforeMethodInterceptor, AuthorizationManagerAfterMethodInterceptor

# Hierarchical Roles
어떤 역할 혹은 권한이 다른 역할을 포함하는지를 구성할 수 있다.

참고 자료 & 이미지 출처
스프링부트 시큐리티 (백기선 님)
https://www.devyummi.com/page?id=6695e062d31df967ae77c97b
개발자 유미 | 커뮤니티
www.devyummi.com
https://spring.io/projects/spring-security
Spring Security
Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications. Spring Security is a framework that focuses on providing both authentication and authoriz
spring.io
'Spring > Spring Security (feat. JWT, OAuth2)' 카테고리의 다른 글
| 기타 : 메소드 시큐리티, 연동(웹 MVC, 타임리프, 스프링 데이터 JPA) (1) | 2024.11.10 |
|---|---|
| 내부 구조 - Security Filters (0) | 2024.11.02 |
| 내부 구조 - Authentication (인증) (1) | 2024.11.02 |
| 내부 구조 - 필터와 사용자/인증 정보 (0) | 2024.10.30 |
| 사용, 테스트 방법 (0) | 2024.10.30 |