通常,有很多方法可以确保您期望的行为。
我建议将 shiro 与标准 grails 过滤器结合使用:
class SecurityFilters {
def filters = {
all(uri: "/**") {
before = {
// Ignore direct views (e.g. the default main index page).
if (!controllerName) return true
accessControl {
// add your logic here to determine if user has access or not
// return true if user has access, false otherwise
// get current user
def user = yourService.getCurrentUser()
// get projects the user is allowed to access
def projects = yourService.getProjectsOfUser(user)
// get the project the user tries to access
def currentProject = Project.get(params.projectId)
// is current project in list of permitted projects?
return project.contains(currentProject)
}
}
}
}
}
或者,您可以实现自己的Permission
并使用SecurityUtils.subject.isPermitted()
.
最佳实现取决于您的应用程序的架构。如果您需要更多帮助,您必须提供有关您的应用程序的更多详细信息。
希望有帮助!