开发者

Grails filters: can't make it work !

开发者 https://www.devze.com 2023-01-13 17:48 出处:网络
Im trying to write a Filter for my web-app. I read [the documentation][1], and wrote this dummy filter in my grails-app/conf directory

Im trying to write a Filter for my web-app. I read [the documentation][1], and wrote this dummy filter in my grails-app/conf directory

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

              write('Filtering')
           
       }
   }
}

Next thing I do is set a breakpoint on the write statement, but it just doesn't stop there.

Do I need to "register" this filter or anything? Spring may be bodering?

From this question, it doesn't look like it.

开发者_运维知识库

Maybe i'm doing something wrong, or overlooked anything?

update

class SecurityFilters {
   def filters = {

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

Thanks in advance.

[1]: http://www.grails.org/doc/1.3.x/guide/single.html#6.6 Filters


Two problems. One is there's no 'write' method - change it to 'println' and it should work. But a filter is comprised of some combination of before, after, and afterView sub-closures, so what you really want is

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

But if you're really creating a security filter, please don't. It's too easy to do this incorrectly. The Spring Security Core and Shiro plugins have plenty of features and are easy to configure and use.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号