47933

Grails filters: can't make it work !

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

Answer1:

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.

Recommend

  • Using FastMM4, how to register leaked string?
  • Accessing Google Docs Metadata feed with gdata-objectivec-client
  • CSS stylesheets at top or bottom? or How to solve blank page issue?
  • How can I commit a file to SVN that I forgot to commit a while ago, (tweaking it's revision num
  • How to Pass Object from ContainerRequestFilter to Resource
  • MS Access 2007 Append query trouble
  • Avoid back page rendering after sign out in
  • proper way to swap unions?
  • Displaying a server side rendered reactJS component within a PHP application
  • Constructor Taking Parcelable Constructor in kotlin Derived Class
  • Is it possible to access printer installed in network in Google Chrome Packaged App?
  • jquery .removeClass() if NOT .next()
  • Counterpart of .NETs NetworkStream / SslStream in Delphi 7 [closed]
  • Grails filters: can't make it work !
  • How to get poltergeist/PhantomJS to delay returning the page to Capybara until AJAX is loaded?
  • Tkinter Grid Columnspan ignored
  • Set Visual Studio (conditional) breakpoint on local variable value
  • Is there a greater chance to collide when comparing GUIDs based on a hash vs \"Guid.NewGuid()?
  • lldb error: use of undeclared identifier
  • How to remove fragment from fragment manager when activity is restored after being destroyed
  • Is it possible to collect a stream to two different collections using one line?
  • .NET video play library which allows to change the playback rate?
  • How to 'create temp table as select' in Slick?
  • How can I tell a form not to dispose a particular control when it closes?
  • SonarQube: Cannot deactivate rule with missing quality profile
  • Sending HTML Form Data to Spring REST Web Service
  • MySQL Order by column = x, column asc?
  • Sencha Touch 2.0 Controller refs attribute not working?
  • Debugging ASP.NET on a built-in web server suddenly stops
  • Trying to switch camera back to front but getting exception
  • what is the difference between the asp.net mvc application and asp.net web application
  • Weird JavaScript statement, what does it mean?
  • bootstrap to use multiple ng-app
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory
  • Binding checkboxes to object values in AngularJs
  • How to load view controller without button in storyboard?