Skip to content

Commit ab022e8

Browse files
authored
Merge pull request #13809 from codeconsole/7.0.x-filter-order
Filter order values should not be fixed and should be relative to requirements of Spring Boot.
2 parents fff053d + 44860dc commit ab022e8

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Copyright 2024 the original author or authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package org.grails.config.http;
17+
18+
import org.springframework.boot.autoconfigure.security.SecurityProperties;
19+
20+
/**
21+
* Stores the default order numbers of all Grails filters for use in configuration.
22+
* These filters are run prior to the Spring Security Filter Chain which is at DEFAULT_FILTER_ORDER
23+
* @since 7.0
24+
*/
25+
public enum GrailsFilters {
26+
27+
FIRST,
28+
ASSET_PIPELINE_FILTER,
29+
CHARACTER_ENCODING_FILTER,
30+
HIDDEN_HTTP_METHOD_FILTER,
31+
SITEMESH_FILTER,
32+
GRAILS_WEB_REQUEST_FILTER,
33+
LAST(SecurityProperties.DEFAULT_FILTER_ORDER - 10);
34+
35+
private static final int INTERVAL = 10;
36+
private final int order;
37+
38+
GrailsFilters() {
39+
this.order = SecurityProperties.DEFAULT_FILTER_ORDER - 100 + ordinal() * INTERVAL;
40+
}
41+
GrailsFilters(int order) {
42+
this.order = order;
43+
}
44+
45+
public int getOrder() {
46+
return this.order;
47+
}
48+
49+
}

grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import groovy.transform.CompileStatic
2323
import groovy.util.logging.Slf4j
2424
import org.grails.core.artefact.ControllerArtefactHandler
2525
import org.grails.plugins.web.servlet.context.BootStrapClassRunner
26+
import org.grails.config.http.GrailsFilters
2627
import org.grails.web.errors.GrailsExceptionResolver
2728
import org.grails.web.filters.HiddenHttpMethodFilter
2829
import org.grails.web.servlet.mvc.GrailsDispatcherServlet
@@ -32,7 +33,6 @@ import org.grails.web.servlet.view.CompositeViewResolver
3233
import org.springframework.beans.factory.support.AbstractBeanDefinition
3334
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletRegistrationBean
3435
import org.springframework.boot.web.servlet.FilterRegistrationBean
35-
import org.springframework.boot.web.servlet.filter.OrderedFilter
3636
import org.springframework.context.ApplicationContext
3737
import org.springframework.util.ClassUtils
3838
import org.springframework.web.filter.CharacterEncodingFilter
@@ -93,19 +93,19 @@ class ControllersGrailsPlugin extends Plugin {
9393
forceEncoding = filtersForceEncoding
9494
}
9595
urlPatterns = catchAllMapping
96-
order = OrderedFilter.REQUEST_WRAPPER_FILTER_MAX_ORDER + 10
96+
order = GrailsFilters.CHARACTER_ENCODING_FILTER.order
9797
}
9898

9999
hiddenHttpMethodFilter(FilterRegistrationBean) {
100100
filter = bean(HiddenHttpMethodFilter)
101101
urlPatterns = catchAllMapping
102-
order = OrderedFilter.REQUEST_WRAPPER_FILTER_MAX_ORDER + 20
102+
order = GrailsFilters.HIDDEN_HTTP_METHOD_FILTER.order
103103
}
104104

105105
grailsWebRequestFilter(FilterRegistrationBean) {
106106
filter = bean(GrailsWebRequestFilter)
107107
urlPatterns = catchAllMapping
108-
order = OrderedFilter.REQUEST_WRAPPER_FILTER_MAX_ORDER + 30
108+
order = GrailsFilters.GRAILS_WEB_REQUEST_FILTER.order
109109
dispatcherTypes = EnumSet.of(
110110
DispatcherType.FORWARD,
111111
DispatcherType.INCLUDE,

0 commit comments

Comments
 (0)