Skip to content

Commit

Permalink
Fix characterEncodingFilter order
Browse files Browse the repository at this point in the history
  • Loading branch information
codeconsole committed Nov 17, 2024
1 parent 4b23183 commit 0667c53
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.web.filter.CharacterEncodingFilter;

import java.util.EnumSet;

@AutoConfiguration(before = { WebMvcAutoConfiguration.class })
@AutoConfiguration(before = { HttpEncodingAutoConfiguration.class, WebMvcAutoConfiguration.class })
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class ControllersAutoConfiguration {

Expand All @@ -28,16 +31,14 @@ public class ControllersAutoConfiguration {
private boolean filtersForceEncoding;

@Bean
@ConditionalOnMissingBean(HiddenHttpMethodFilter.class)
public FilterRegistrationBean<Filter> characterEncodingFilter() {
@ConditionalOnMissingBean(CharacterEncodingFilter.class)
public CharacterEncodingFilter characterEncodingFilter() {
FilterRegistrationBean<Filter> registrationBean = new FilterRegistrationBean<>();
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
OrderedCharacterEncodingFilter characterEncodingFilter = new OrderedCharacterEncodingFilter();
characterEncodingFilter.setEncoding(filtersEncoding);
characterEncodingFilter.setForceEncoding(filtersForceEncoding);
registrationBean.setFilter(characterEncodingFilter);
registrationBean.addUrlPatterns(Settings.DEFAULT_WEB_SERVLET_PATH);
registrationBean.setOrder(GrailsFilters.CHARACTER_ENCODING_FILTER.getOrder());
return registrationBean;
characterEncodingFilter.setOrder(GrailsFilters.CHARACTER_ENCODING_FILTER.getOrder());
return characterEncodingFilter;
}

@Bean
Expand Down

0 comments on commit 0667c53

Please sign in to comment.