feat: RoleHierarchyを使用するスコープ指定のユーティリティーを追加

This commit is contained in:
usbharu 2024-02-16 14:32:34 +09:00
parent 31075240a0
commit 00cf918720
1 changed files with 16 additions and 0 deletions

View File

@ -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<RequestAuthorizationContext> {
val hasAuthority = AuthorityAuthorizationManager.hasAuthority<RequestAuthorizationContext>("SCOPE_$role")
hasAuthority.setRoleHierarchy(roleHierarchy)
return hasAuthority
}
}