OAuth 2.0 Resource Server 권한 구현 - 권한 구성 커스터마이징
인가 서버가
scope속성 대신 자체 커스텀 속성을 사용하거나 리소스 서버에서 속성을 내부 권한에 맞게 조정해야 할 경우 사용한다.JwtAuthenticationConverter는 Jwt 객체를Authentication으로 변환하는 클래스이며, 권한을 변환하는JwtGrantedAuthoritiesConverter를 가지고 있다.

JwtAuthenticationConverter

스프링 시큐리티의
JwtAuthenticationConverter는 기본적으로JwtGrantedAuthoritiesConverter를 통해 권한 매핑을 하며,setter를 통해 커스텀한 컨버터를 지정할 수 있다.

스프링 시큐리티는 기본적으로 클레임 정보 중에서
scope정보를 가지고SCOPE_Prefix를 붙여 권한 매핑을 한다. 권한 매핑을 커스터마이징 하기 위해 여기서는 키클록에서 주는 정보인realm_access에roles를 권한 매핑을 해본다.
SecurityConfig
/photos/2로 오는 요청에 대해서는 커스텀 권한 매핑을 하지 않고 스프링 시큐리티에 맡기도록 설정
CustomRoleConverter

Last updated