Having the last word when adding ServletFilters to the web.xml

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Having the last word when adding ServletFilters to the web.xml

Benjamin Wolff
Hi,

In my Grails application I need to make sure that a ServletFilter is configured as the first in the row of filters, which means it's the first <filter-mapping> declaration in the web.xml. Is there a way to achieve this from within my application without creating a plugin just for this purpose?

The plugins can add filter via the doWithWebDescriptor() closure, but I didn't find any way to make sure my application adds the filters after the additions done by all plugins. If I add the filter directly to the web.xml template it will get overridden by the plugins.

I played around with some scripts/_Events.groovy events and adding a filter by hacking the XML in the eventWebXmlEnd event, but it seems that the plugin add their stuff after that event. Putting it in eventCreateWarStart doesn't help me when I run the "run-app" command.

So I'd need a hook to add the filter in my app that is ensured to be called after all the plugins finished their work. I'd be grateful for any ideas.

Cheers,
Ben
Cheers,
Ben
Reply | Threaded
Open this post in threaded view
|

RE: Having the last word when adding ServletFilters to the web.xml

Bob Brown
Take a look at 'dependsOn' for filters.

http://grails.org/doc/latest/guide/single.html#filterDependencies

and the general doco for filters.

http://grails.org/doc/latest/guide/single.html#filters

HTH

BOB

> -----Original Message-----
> From: Benjamin Wolff [mailto:[hidden email]]
> Sent: Wednesday, 16 October 2013 5:46 PM
> To: [hidden email]
> Subject: [grails-user] Having the last word when adding ServletFilters to
the
> web.xml
>
> Hi,
>
> In my Grails application I need to make sure that a ServletFilter is
configured
> as the first in the row of filters, which means it's the first
<filter-mapping>
> declaration in the web.xml. Is there a way to achieve this from within my
> application without creating a plugin just for this purpose?
>
> The plugins can add filter via the doWithWebDescriptor() closure, but I
didn't
> find any way to make sure my application adds the filters after the
additions
> done by all plugins. If I add the filter directly to the web.xml template
it will
> get overridden by the plugins.
>
> I played around with some scripts/_Events.groovy events and adding a
filter
> by hacking the XML in the eventWebXmlEnd event, but it seems that the
> plugin add their stuff after that event. Putting it in eventCreateWarStart
> doesn't help me when I run the "run-app" command.
>
> So I'd need a hook to add the filter in my app that is ensured to be
called

> after all the plugins finished their work. I'd be grateful for any ideas.
>
> Cheers,
> Ben
>
>
>
>
> -----
> Cheers,
> Ben
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Having-
> the-last-word-when-adding-ServletFilters-to-the-web-xml-tp4650367.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: Having the last word when adding ServletFilters to the web.xml

Benjamin Wolff
Hi Bob,

thanks a lot for your response!

Unfortunately this approach doesn't work for me. I'm using a class that extends from javax.servlet.Filter and it has to put as the first filter mapping in the web.xml, it deals with some security related redirects and has to be invoked before any other of the default Grails filters or other filter added by other plugins (like spring-security-core etc.).

The only way I can currently imagine to make it work is to create another Grails plugin for the sole purpose of using the "doWithWebDescriptor" closure in the plugin descriptor and declare a plugin-dependency to all other plugins that contribute filters to the web.xml. Of course this approach seems pretty "through-the-knee-in-the-chest" to me and also quite fragile ;). Therefore I'm looking for a more straight-forward approach.

Cheers,
Ben
Cheers,
Ben