gpt4 book ai didi

grails - Grails Shiro LDAP用户/角色身份验证:如何/如何捕获和存储以供重用

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

因此,我需要一些有关项目布局/结构的帮助。我正在制作一个网站,到目前为止,我有一个有效的登录页面,该登录页面针对LDAP服务器使用Apache Shiro对用户进行身份验证,并将用户重定向至初始页面。根据用户所拥有的权限,他们应该/不应该能够在初始页面上查看某些内容。

我想做的是根据 session 信息(即刚刚登录的用户)创建一个新的ShiroUser并为其分配一些角色。例如

def shiroUser = new ShiroUser()
shiroUser.username = session.username
shiroUser.addToRoles(ShiroRole.findByName('ROLE_USER'))
shiroUser.save()

ROLE_USER将由
def shiroRole = new ShiroRole()
shiroRole.name='ROLE_USER'
shiroRole.save()

现在,我只想对它进行硬编码,然后对其进行修改以在表中查找并根据该表中的值分配角色。

我想知道的是
  • 我将这些东西放在哪里?
  • 是否为此创建新的 Controller ?
  • 在哪里定义shiroRoles?
  • 这甚至很聪明吗? (每次有人登录时创建一个新的ShiroUser)

  • 我以前从未建立过网站,所以不确定如何组织代码或将内容放置在何处。 (顺便说一句,我正在使用GGTS。)有些指导/建议将不胜感激!我使用了很多书籍,例如《 Grails in Action》,《 Make Java Groovy》和《 Grails 2权威指南》,但是它们的大多数示例与我想做的都不匹配。如果有我没有找到的任何教程,我很感兴趣看到它们。 (我已经浏览了很多,但是它们只是像我列出的代码片段,但没有指定它们的实际位置!)

    最佳答案

    我做了类似的事情:

    https://github.com/vahidhedayati/kchat/blob/master/grails-app/domain/kchat/UserDetails.groovy

    但就我而言,我是在应用中创建一个用户并存储各种LDAP信息,后来我在securityFilters中使用了自己的过滤检查,以确保其LDAP组或userID与我的内部通过/失败规则匹配,该规则通过securityFilters为给定的 Action / Controller 调用。

    同样,此https://github.com/vahidhedayati/customshiro可能是上述实现的更好解释。

    这些可能会帮助您为您的需求提供更好的设计:

    how to implement Shiro Security of Grails in my Project

    Secure some, but not all pages in a Grails application with the Shiro plugin

    http://coderberry.me/blog/2012/04/26/grails-authentication-with-shiro/

    您应该使用SecurityFilters(如上面的某些链接所示),即:

    browseStore(controller:"store", action:"(show|list)") {
    before = {
    // Ignore direct views (e.g. the default main index page).
    if (!controllerName) return true

    // Access control by convention.
    accessControl()
    }
    }

    或在 Controller 中比较繁琐,以匹配后端凭据
    SecurityUtils.subject.isPermitted("someController:someAction")
    or
    if (SecurityUtils.subject.isPermitted("printer:query:lp7200")) {
    // Return the current jobs on printer lp7200
    }

    有关gsp的进一步前端检查: how to detect whether a uri is allow by shiro or extract controller name from uri
    <shiro:hasPermission permission="someController:someAction">
    <g:link...>
    </shiro:hasPermission>
    <shiro:lacksPermission permission="someController:someAction">
    No link
    </shiro:lacksPermission>

    E2A
    在我的初始方法中,给定 Controller Action 调用的用户/用户部门的控制+甚至在内部对此应用程序环境进行了进一步检查,并且appId(这是传递的内部值)都是动态的,即使已配置了SecurityFilters,实际控制也是传递给我的自定义检查,该检查依赖于数据库条目进行验证。现在,这就是数据库,这意味着您可以更新或向给定的用户/部门用户组添加权限,而不必更新后端Controller / SecurityFilters。我必须把这个放在要点上,否则它是一个值得回答的章节

    https://gist.github.com/vahidhedayati/71d92f8153ade5d732b3

    其他一些可能有帮助的东西:
    看看被逮捕的插件。此处的演示站点具有github.com/vahidhedayati/testingarrested中插件的编译输出

    关于grails - Grails Shiro LDAP用户/角色身份验证:如何/如何捕获和存储以供重用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31479753/

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