如何定义Grails过滤器的调用序列 [英] How is the invocation sequence of Grails filters defined

查看:134
本文介绍了如何定义Grails过滤器的调用序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用过滤器来处理Grails应用程序的身份验证和其他一些前置条件检查。我遇到了这样的情况,确保过滤器A总是在过滤器B之前被调用。



根据文档, filters按定义的顺序执行,但不清楚该定义是指什么。我熟悉Java EE ServletFilters是如何工作的,其中序列是通过web.xml中相应标记的顺序来声明的,但是由于部署是在Grails中自动处理的,所以我不太确定在哪里可以影响订单其中过滤器设置。

这是可能的在所有Grails,如果是这样,如何?

<如果在一个类中声明了几个过滤器,那么显然它们将按照声明的顺序执行。我更关心的是在不同的类中定义的过滤器以及这些类将被考虑的顺序。

解决方案

Molske是正确的他们按照类中定义的顺序执行。还有一个新的配置选项dependsOn,您可以使用它来排序不同的过滤器类,即MyFilters2在MyFilters1之后运行。请参阅6.6.4过滤器相关性,网址为 http://grails.org/doc/latest/


I am using filters to handle authentication and some other pre-condition checks for a Grails application. I've run into a situation where it'd be nice to ensure that filter A is always invoked before filter B.

According to the documentation the "filters are executed in the order they are defined" but it is unclear what that definition refers to. I am familiar with how that works for Java EE ServletFilters, where the sequence is declared by the order of corresponding tags in the web.xml, but as the deployment is handled automatically in Grails, I am not really sure where I could influence the order in which the filters are set up.

Is that possible at all in Grails, and if so, how?

Update

If several filters are declared within one class, it's obvious that they'll be executed in the order that they were declared. I am more concerned with filters defined in different classes and the sequence that those classes will be considered in.

解决方案

Molske is correct that they're executed in the order defined in the class. One exception is that the first 'before' filter that returns false stops processing.

There's also a new configuration option 'dependsOn' that you can use to order different filter classes, i.e. that MyFilters2 runs after MyFilters1. See "6.6.4 Filter Dependencies" at http://grails.org/doc/latest/

这篇关于如何定义Grails过滤器的调用序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆