Spring Security의 권한 부여 컴포넌트
1. AuthorizationFilter(인가필터)
권한에 따른 URL 액세스를 제한
SecurityContextHolder로 부터 Authentication 획득
2. RequestMatcherDelegatingAuthorizationManager(요청매처 위임 인가매니저)
AuthorizationFilter로 부터 Authentication(인증)와 HttpServletRequest 획득
메서드 체인 정보(.antMatchers("/orders/**").hasRole("ADMIN"))를 기반으로 생성된 RequestMatcher를 통해 AuthorizationManager를 매치(위임)
3. AuthorizationManager(인가매니저)
적절한 권한인지 확인
check(), prosessing
or AccessDeniedException -> ExceptionTranslationFilter
Spring Security에서 지원하는 보안을 위한 표현식(Spring EL)
Spring EL
런타임에서 객체에 대한 쿼리와 조작을 지원하는 강력한 표현 언어
#{ SpEL표현식 }형태로 표현
${ }는 프로퍼티 참조
어노테이션 값 표현으로 많이 쓰인다아래의 접근 제어 표현식 사용 예시
@PreAuthorize("hasRole('ROLE_USER')")
권한설정이 필요한 URI 매핑에 사용
| 표현식 | 설명 |
|---|---|
| hasRole(Stirng role) | 해당 역할을 가졌는지 |
| hasAnyRole(String… roles) | 해당 역할 중 하나라도 가졌는지(콤마 구분) |
| hasAuthority(String authority) | 해당 권한을 갖고 있는지 |
| hasAnyAuthority(String… authorities) | 해당 권한 중 하나라도 가졌는지(콤마 구분) |
| principal | 현재 사용자를 나타내는 principal에 직접 접근 |
| authentication | Authentication 객체에 직접 접근 |
| permitAll | 항상 true로 평가 |
| denyAll | 항상 false로 평가 |
| isAnonymous() | 익명 사용자인지 |
| isAuthenticated() | 익명 사용자가 아닌지 |
| isRememberMe() | remember-me 사용자인지 |
| isFullyAuthenticated() | 익명 사용자나 remember-me 사용자가 아닌지 |
| hasPermission(Object target, Object permission) | target에 해당 permission 권한이 있는지 |
| hasPermission(Object targetId, String targetType, Object permission) | target에 해당 permission 권한이 있는지 |