代码之家  ›  专栏  ›  技术社区  ›  Tom

微粒过滤器:不能让它工作!

  •  2
  • Tom  · 技术社区  · 14 年前

    我正在尝试为我的Web应用编写一个筛选器。我阅读了[文档][1],并在我的 grails-app/conf 目录

    class SecurityFilters {
       def filters = {
           someFilter(controller:'*',action:'*') {
    
                  write('Filtering')
    
           }
       }
    }
    

    接下来我要做的是在 write 声明,但它并没有就此止步。

    我需要“注册”这个过滤器还是什么?春天可能是预兆?

    this question 看起来不像。

    也许我做错了什么,或者忽略了什么?

    更新

    class SecurityFilters {
       def filters = {
    
           all(controller:'*',action:'*') {
            before={
                  println 'Filtering'
                  return false
            }
           }
       }
    }
    

    事先谢谢。

    〔1〕: http://www.grails.org/doc/1.3.x/guide/single.html#6.6 过滤器

    1 回复  |  直到 14 年前
        1
  •  2
  •   Burt Beckwith    14 年前

    两个问题。一个是没有“写入”方法-将其更改为“println”,它应该可以工作。但是过滤器是由一些前、后和后视图子闭包的组合组成的,所以您真正想要的是

    class SecurityFilters {
       def filters = {
          someFilter(controller:'*',action:'*') {
             before = {
                println 'Filtering'
             }
          }
       }
    }
    

    但是,如果您真的要创建一个安全过滤器,请不要这样做。这样做太容易出错。这个 Spring Security Core Shiro 插件有很多特性,易于配置和使用。