我正在尝试制作一个概念验证应用程序,该应用程序允许具有管理权限的用户授予和撤消其他用户的权限。虽然仅使用用户名(唯一标识符)进行授予和吊销,但获得在UI中显示的权限被证明是我无法实现的。是否可以从服务方法中获取其他用户的权限列表?
我曾尝试在网上搜索,但找不到适用于我的问题的任何解决方案。我尝试使用SwitchUserAuthorityChanger,RunAsManager和aclService.readAclsById。这些都不起作用。
我将Grails 3.3.2与Spring-Security 3.2.0和ACL 3.2.0一起使用。
欢呼大家!
最佳答案
我最终自己解决了这个问题。我将在这里发布答案,以防某些可怜的灵魂遇到类似的问题。
在ACL数据库表中进行了一些挖掘之后,我创建了一个单独的服务,其中通过ID获得AclObjectIdentity
,获得用户sid。使用这些变量,我可以从AclEntry
中找到所有相关变量。之后,仅需通过其掩码获取权限即可。
如果有可能帮助任何人,请使用以下方法:
def getPermissions(Object domainObject, String sid) {
Map<String, String> returnValue = [
"status": "success"
]
def aclObject = AclObjectIdentity.findByObjectId(domainObject.id)
def userAclSid = AclSid.findBySid(sid)
if (null == userAclSid || null == aclObject) {
returnValue["status"] = "failed"
return returnValue
}
def aclEntries = AclEntry.findAllBySidAndAclObjectIdentity(userAclSid, aclObject)
returnValue["permissions"] = []
def tempMap = [:]
if (null == aclEntries) {
returnValue["permissions"] = "null"
return returnValue
}
def counter = 0
for (entry in aclEntries) {
int mask = entry.mask
BasePermission permission
for (BasePermission perm in PermissionEnum.toList()) {
int test = 1 << mask
if (perm.getMask() == test) {
permission = perm
break;
}
}
def permString = PermissionEnum.getPermission(permission)
tempMap["$counter"] = permString
counter++
}
returnValue["permissions"] = tempMap
return returnValue
}
关于grails - 管理员角色能否在Spring-security ACL Grails中获得其他用户的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48466383/