Add property to disable HiddenHttpMethodFilter

Closes gh-14030
This commit is contained in:
artsiom
2018-08-17 10:24:26 +02:00
committed by Brian Clozel
parent 4bc5535c37
commit d22c3e2787
4 changed files with 25 additions and 0 deletions

View File

@@ -135,6 +135,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Kristine Jetzke * @author Kristine Jetzke
* @author Bruce Brouwer * @author Bruce Brouwer
* @author Artsiom Yudovin
*/ */
@Configuration @Configuration
@ConditionalOnWebApplication(type = Type.SERVLET) @ConditionalOnWebApplication(type = Type.SERVLET)
@@ -153,6 +154,7 @@ public class WebMvcAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(HiddenHttpMethodFilter.class) @ConditionalOnMissingBean(HiddenHttpMethodFilter.class)
@ConditionalOnProperty(prefix = "spring.mvc.hiddenmethod.filter", name = "enabled", matchIfMissing = true)
public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() { public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new OrderedHiddenHttpMethodFilter(); return new OrderedHiddenHttpMethodFilter();
} }

View File

@@ -466,6 +466,12 @@
"description": "Whether to enable Spring's HttpPutFormContentFilter.", "description": "Whether to enable Spring's HttpPutFormContentFilter.",
"defaultValue": true "defaultValue": true
}, },
{
"name": "spring.mvc.hiddenmethod.filter.enabled",
"type": "java.lang.Boolean",
"description": "Whether to enable Spring's HiddenHttpMethodFilter.",
"defaultValue": true
},
{ {
"name" : "spring.mvc.media-types", "name" : "spring.mvc.media-types",
"type" : "java.util.Map<java.lang.String,org.springframework.http.MediaType>", "type" : "java.util.Map<java.lang.String,org.springframework.http.MediaType>",

View File

@@ -71,6 +71,7 @@ import org.springframework.web.accept.ParameterContentNegotiationStrategy;
import org.springframework.web.accept.PathExtensionContentNegotiationStrategy; import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.filter.HttpPutFormContentFilter; import org.springframework.web.filter.HttpPutFormContentFilter;
import org.springframework.web.servlet.HandlerAdapter; import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.HandlerExceptionResolver;
@@ -118,6 +119,7 @@ import static org.mockito.Mockito.mock;
* @author Brian Clozel * @author Brian Clozel
* @author Eddú Meléndez * @author Eddú Meléndez
* @author Kristine Jetzke * @author Kristine Jetzke
* @author Artsiom Yudovin
*/ */
public class WebMvcAutoConfigurationTests { public class WebMvcAutoConfigurationTests {
@@ -572,6 +574,20 @@ public class WebMvcAutoConfigurationTests {
.doesNotHaveBean(HttpPutFormContentFilter.class)); .doesNotHaveBean(HttpPutFormContentFilter.class));
} }
@Test
public void hiddenHttpMethodFilterCanBeDisabled() {
this.contextRunner
.withPropertyValues("spring.mvc.hiddenmethod.filter.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(HiddenHttpMethodFilter.class));
}
@Test
public void hiddenHttpMethodFilterEnabledByDefault() {
this.contextRunner.run((context) -> assertThat(context)
.hasSingleBean(HiddenHttpMethodFilter.class));
}
@Test @Test
public void customConfigurableWebBindingInitializer() { public void customConfigurableWebBindingInitializer() {
this.contextRunner this.contextRunner

View File

@@ -429,6 +429,7 @@ content into your application. Rather, pick only the properties that you need.
spring.mvc.dispatch-options-request=true # Whether to dispatch OPTIONS requests to the FrameworkServlet doService method. spring.mvc.dispatch-options-request=true # Whether to dispatch OPTIONS requests to the FrameworkServlet doService method.
spring.mvc.favicon.enabled=true # Whether to enable resolution of favicon.ico. spring.mvc.favicon.enabled=true # Whether to enable resolution of favicon.ico.
spring.mvc.formcontent.putfilter.enabled=true # Whether to enable Spring's HttpPutFormContentFilter. spring.mvc.formcontent.putfilter.enabled=true # Whether to enable Spring's HttpPutFormContentFilter.
spring.mvc.hiddenmethod.filter.enabled=true # Whether to enable Spring's HiddenHttpMethodFilter.
spring.mvc.ignore-default-model-on-redirect=true # Whether the content of the "default" model should be ignored during redirect scenarios. spring.mvc.ignore-default-model-on-redirect=true # Whether the content of the "default" model should be ignored during redirect scenarios.
spring.mvc.locale= # Locale to use. By default, this locale is overridden by the "Accept-Language" header. spring.mvc.locale= # Locale to use. By default, this locale is overridden by the "Accept-Language" header.
spring.mvc.locale-resolver=accept-header # Define how the locale should be resolved. spring.mvc.locale-resolver=accept-header # Define how the locale should be resolved.