From 4bd2234a691aeae5c2507c9be3c1f4b3c9363880 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:32:34 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20RoleHierarchy=E3=82=92=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E3=81=99=E3=82=8B=E3=82=B9=E3=82=B3=E3=83=BC=E3=83=97?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E3=81=AE=E3=83=A6=E3=83=BC=E3=83=86=E3=82=A3?= =?UTF-8?q?=E3=83=AA=E3=83=86=E3=82=A3=E3=83=BC=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RoleHierarchyAuthorizationManagerFactory.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/kotlin/dev/usbharu/hideout/application/infrastructure/springframework/RoleHierarchyAuthorizationManagerFactory.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/springframework/RoleHierarchyAuthorizationManagerFactory.kt b/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/springframework/RoleHierarchyAuthorizationManagerFactory.kt new file mode 100644 index 00000000..42a249ea --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/springframework/RoleHierarchyAuthorizationManagerFactory.kt @@ -0,0 +1,16 @@ +package dev.usbharu.hideout.application.infrastructure.springframework + +import org.springframework.security.access.hierarchicalroles.RoleHierarchy +import org.springframework.security.authorization.AuthorityAuthorizationManager +import org.springframework.security.authorization.AuthorizationManager +import org.springframework.security.web.access.intercept.RequestAuthorizationContext +import org.springframework.stereotype.Component + +@Component +class RoleHierarchyAuthorizationManagerFactory(private val roleHierarchy: RoleHierarchy) { + fun hasScope(role: String): AuthorizationManager { + val hasAuthority = AuthorityAuthorizationManager.hasAuthority("SCOPE_$role") + hasAuthority.setRoleHierarchy(roleHierarchy) + return hasAuthority + } +} \ No newline at end of file