gpt4 book ai didi

grails - Grails中的用户访问控制

转载 作者:行者123 更新时间:2023-12-02 14:14:00 24 4
gpt4 key购买 nike

我对Grails完全陌生,并且已经阅读了Shiro插件,但是我不确定这是Im之后的事情,因此希望有人可以指出正确的方向。

对于我在计算机科学 Realm 的最后一个项目,我正在创建用Grails编写的在线团队协作工具。该应用程序的结构如下:

应用程序-有许多公司在使用它
公司有很多项目
项目有很多用户等。

确保用户登录时最好的方式是什么,如果他们是管理员,则他们只能看到其公司和项目的内容,如果是普通用户,则只能看到其项目的内容。显然,我不希望某个公司的用户能够访问其他公司的项目信息等。

任何帮助深表感谢。

最佳答案

通常,有很多方法可以确保您期望的行为。

我建议将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()

最佳实现取决于您的应用程序的体系结构。如果您需要更多帮助,则必须提供应用程序的更多详细信息。

希望有帮助!

关于grails - Grails中的用户访问控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13540841/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com