All Downloads are FREE. Search and download functionalities are using the official Maven repository.

yakworks.security.shiro.GormShiroRolePermissionResolver.groovy Maven / Gradle / Ivy

There is a newer version: 7.3.27
Show newest version
/*
* Copyright 2022 Yak.Works - Licensed under the Apache License, Version 2.0 (the "License")
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
package yakworks.security.shiro

import groovy.transform.CompileStatic

import org.apache.shiro.authz.Permission
import org.apache.shiro.authz.permission.RolePermissionResolver
import org.apache.shiro.authz.permission.WildcardPermission

import yakworks.security.gorm.model.SecRolePermission

@CompileStatic
class GormShiroRolePermissionResolver implements RolePermissionResolver {

    @Override
    Collection resolvePermissionsInRole(String roleString) {
        List stringPermissions = SecRolePermission.executeQuery("""
            Select sr.permission FROM SecRolePermission sr WHERE upper(sr.role.code) = :roleString
        """, [roleString: roleString.toUpperCase()]) as List

        List permissions = []

        stringPermissions.each { String perm ->
            permissions << new WildcardPermission(perm)
        }

        return permissions
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy