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 Kristine Jetzke
* @author Bruce Brouwer
* @author Artsiom Yudovin
*/
@Configuration
@ConditionalOnWebApplication(type = Type.SERVLET)
@@ -153,6 +154,7 @@ public class WebMvcAutoConfiguration {
@Bean
@ConditionalOnMissingBean(HiddenHttpMethodFilter.class)
@ConditionalOnProperty(prefix = "spring.mvc.hiddenmethod.filter", name = "enabled", matchIfMissing = true)
public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new OrderedHiddenHttpMethodFilter();
}

View File

@@ -466,6 +466,12 @@
"description": "Whether to enable Spring's HttpPutFormContentFilter.",
"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",
"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.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.filter.HttpPutFormContentFilter;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerExceptionResolver;
@@ -118,6 +119,7 @@ import static org.mockito.Mockito.mock;
* @author Brian Clozel
* @author Eddú Meléndez
* @author Kristine Jetzke
* @author Artsiom Yudovin
*/
public class WebMvcAutoConfigurationTests {
@@ -572,6 +574,20 @@ public class WebMvcAutoConfigurationTests {
.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
public void customConfigurableWebBindingInitializer() {
this.contextRunner