【问题标题】:Grails security filter doesn't work with 2 controllersGrails 安全过滤器不适用于 2 个控制器
【发布时间】:2014-11-12 04:44:52
【问题描述】:

我正在使用 grails 2.4.3,创建了一个安全过滤器。我的项目名称中有 3 个控制器:管理员、登录和报告。所以我在过滤器中添加了以下内容:

def filters = {
        all(controller: 'Admin', action: '*') {
            before = {
                if (!session.company) {
                    redirect(controller: 'login', action: 'auth')
                    return false
                }
            }
            after = { Map model ->

            }
            afterView = { Exception e ->

            }
        }
    }

我的意思是来自管理控制器的任何操作,如果!session.company,页面将被重定向到登录控制器中的身份验证操作。

现在我想在这个过滤器中添加一个控制器报告,我该怎么做?我试过all(controller: ['Admin', 'Report'], action: '*'),但它不起作用。

任何帮助将不胜感激。谢谢

【问题讨论】:

    标签: security grails groovy


    【解决方案1】:

    使用管道符号添加多个控制器,如

    def filters = {
        all(controller: 'Admin|Report', action: '*') {
            ...
        }
    }
    

    参考号How to define mutliple distinct controllers in Grails 2 filter?

    【讨论】:

    • 谢谢,这真的很有帮助,我之前考虑过,但是我输入了错误的语法。我试过Report,但它支持report。总之谢谢老哥。美好的一天。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 2022-11-09
    • 2011-05-16
    相关资源
    最近更新 更多