mirror of https://github.com/usbharu/Hideout.git
feat: RoleHierarchyを使用するスコープ指定のユーティリティーを追加
This commit is contained in:
parent
31075240a0
commit
00cf918720
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue