OAuth 2.0 Resource Server 권한 구현 - 권한 구성 커스터마이징

  • 인가 서버가 scope 속성 대신 자체 커스텀 속성을 사용하거나 리소스 서버에서 속성을 내부 권한에 맞게 조정해야 할 경우 사용한다.

  • JwtAuthenticationConverterJwt 객체를 Authentication 으로 변환하는 클래스이며, 권한을 변환하는 JwtGrantedAuthoritiesConverter를 가지고 있다.

img_11.png

JwtAuthenticationConverter

img_12.png

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

img_13.png

스프링 시큐리티는 기본적으로 클레임 정보 중에서 scope 정보를 가지고 SCOPE_ Prefix를 붙여 권한 매핑을 한다. 권한 매핑을 커스터마이징 하기 위해 여기서는 키클록에서 주는 정보인 realm_accessroles를 권한 매핑을 해본다.

SecurityConfig

/photos/2 로 오는 요청에 대해서는 커스텀 권한 매핑을 하지 않고 스프링 시큐리티에 맡기도록 설정

CustomRoleConverter

img_14.png

이전 ↩️ - OAuth 2.0 Resource Server 권한 구현 - Scope 기반 권한 매핑arrow-up-right

메인 ⏫arrow-up-right

Last updated