|
28 | 28 | import org.junit.jupiter.api.Test; |
29 | 29 | import org.junit.jupiter.api.extension.ExtendWith; |
30 | 30 |
|
| 31 | +import org.springframework.beans.BeansException; |
31 | 32 | import org.springframework.beans.factory.BeanCreationException; |
32 | 33 | import org.springframework.beans.factory.annotation.Autowired; |
| 34 | +import org.springframework.beans.factory.config.BeanPostProcessor; |
33 | 35 | import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; |
34 | 36 | import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException; |
35 | 37 | import org.springframework.security.config.test.SpringTestContext; |
36 | 38 | import org.springframework.security.config.test.SpringTestContextExtension; |
37 | 39 | import org.springframework.security.core.Authentication; |
38 | 40 | import org.springframework.security.web.authentication.session.SessionLimit; |
| 41 | +import org.springframework.security.web.header.HeaderWriterFilter; |
39 | 42 | import org.springframework.test.web.servlet.MockMvc; |
40 | 43 | import org.springframework.test.web.servlet.ResultMatcher; |
41 | 44 | import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; |
@@ -150,6 +153,16 @@ public void requestWhenHeadersElementUsedThenResponseContainsAllSecureHeaders() |
150 | 153 | // @formatter:on |
151 | 154 | } |
152 | 155 |
|
| 156 | + @Test |
| 157 | + public void requestWhenHeadersEagerlyConfiguredThenHeadersAreWritten() throws Exception { |
| 158 | + this.spring.configLocations(this.xml("HeadersEagerlyConfigured")).autowire(); |
| 159 | + // @formatter:off |
| 160 | + this.mvc.perform(get("/").secure(true)) |
| 161 | + .andExpect(status().isOk()) |
| 162 | + .andExpect(includesDefaults()); |
| 163 | + // @formatter:on |
| 164 | + } |
| 165 | + |
153 | 166 | @Test |
154 | 167 | public void requestWhenFrameOptionsConfiguredThenIncludesHeader() throws Exception { |
155 | 168 | Map<String, String> headers = new HashMap(defaultHeaders); |
@@ -955,6 +968,18 @@ public String ok() { |
955 | 968 |
|
956 | 969 | } |
957 | 970 |
|
| 971 | + public static class EagerHeadersBeanPostProcessor implements BeanPostProcessor { |
| 972 | + |
| 973 | + @Override |
| 974 | + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { |
| 975 | + if (bean instanceof HeaderWriterFilter headerWriterFilter) { |
| 976 | + headerWriterFilter.setShouldWriteHeadersEagerly(true); |
| 977 | + } |
| 978 | + return bean; |
| 979 | + } |
| 980 | + |
| 981 | + } |
| 982 | + |
958 | 983 | public static class CustomSessionLimit implements SessionLimit { |
959 | 984 |
|
960 | 985 | @Override |
|
0 commit comments