Commit 500d2bd9 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge pull request #22138 from dreis2211

* gh-22138:
  Accept empty filter dispatcher types in auto-configurations

Closes gh-22138
parents abeab73b 8c0e302f
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -73,7 +73,7 @@ public class SecurityFilterAutoConfiguration { ...@@ -73,7 +73,7 @@ public class SecurityFilterAutoConfiguration {
} }
return securityProperties.getFilter().getDispatcherTypes().stream() return securityProperties.getFilter().getDispatcherTypes().stream()
.map((type) -> DispatcherType.valueOf(type.name())) .map((type) -> DispatcherType.valueOf(type.name()))
.collect(Collectors.collectingAndThen(Collectors.toSet(), EnumSet::copyOf)); .collect(Collectors.toCollection(() -> EnumSet.noneOf(DispatcherType.class)));
} }
} }
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -53,7 +53,7 @@ class SessionRepositoryFilterConfiguration { ...@@ -53,7 +53,7 @@ class SessionRepositoryFilterConfiguration {
return null; return null;
} }
return servletProperties.getFilterDispatcherTypes().stream().map((type) -> DispatcherType.valueOf(type.name())) return servletProperties.getFilterDispatcherTypes().stream().map((type) -> DispatcherType.valueOf(type.name()))
.collect(Collectors.collectingAndThen(Collectors.toSet(), EnumSet::copyOf)); .collect(Collectors.toCollection(() -> EnumSet.noneOf(DispatcherType.class)));
} }
} }
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -164,6 +164,19 @@ class SecurityAutoConfigurationTests { ...@@ -164,6 +164,19 @@ class SecurityAutoConfigurationTests {
}); });
} }
@Test
void emptyFilterDispatcherTypesDoNotThrowException() {
this.contextRunner.withPropertyValues("spring.security.filter.dispatcher-types:")
.withConfiguration(AutoConfigurations.of(SecurityFilterAutoConfiguration.class)).run((context) -> {
DelegatingFilterProxyRegistrationBean bean = context.getBean("securityFilterChainRegistration",
DelegatingFilterProxyRegistrationBean.class);
@SuppressWarnings("unchecked")
EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils
.getField(bean, "dispatcherTypes");
assertThat(dispatcherTypes).isEmpty();
});
}
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(City.class) @TestAutoConfigurationPackage(City.class)
static class EntityConfiguration { static class EntityConfiguration {
......
...@@ -142,6 +142,17 @@ class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurationTest ...@@ -142,6 +142,17 @@ class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurationTest
}); });
} }
@SuppressWarnings("unchecked")
@Test
void emptyFilterDispatcherTypesDoNotThrowException() {
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class)
.withPropertyValues("spring.session.servlet.filter-dispatcher-types=").run((context) -> {
FilterRegistrationBean<?> registration = context.getBean(FilterRegistrationBean.class);
Object dispatcherTypes = ReflectionTestUtils.getField(registration, "dispatcherTypes");
assertThat((EnumSet<DispatcherType>) dispatcherTypes).isEmpty();
});
}
@Test @Test
void sessionCookieConfigurationIsAppliedToAutoConfiguredCookieSerializer() { void sessionCookieConfigurationIsAppliedToAutoConfiguredCookieSerializer() {
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class) this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment