Skip to content

Commit 756a640

Browse files
committed
Merge branch '3.5.x'
Closes gh-48055
2 parents 93b14bf + 5c711e2 commit 756a640

File tree

5 files changed

+138
-3
lines changed

5 files changed

+138
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
org.springframework.security.config.annotation.web.WebSecurityConfigurer
2+
org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer
13
org.springframework.security.web.SecurityFilterChain
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.security.test.autoconfigure.webmvc;
18+
19+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
20+
import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
21+
import org.springframework.security.config.annotation.web.builders.WebSecurity;
22+
import org.springframework.stereotype.Component;
23+
24+
/**
25+
* {@link WebSecurityConfigurer} used to test their inclusion in
26+
* {@link WebMvcTest @WebMvcTest}.
27+
*
28+
* @author Andy Wilkinson
29+
*/
30+
@Component
31+
class ExampleWebSecurityConfigurer implements WebSecurityConfigurer<WebSecurity> {
32+
33+
@Override
34+
public void init(WebSecurity builder) {
35+
}
36+
37+
@Override
38+
public void configure(WebSecurity builder) {
39+
}
40+
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.security.test.autoconfigure.webmvc;
18+
19+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
20+
import org.springframework.security.config.annotation.web.builders.WebSecurity;
21+
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
22+
import org.springframework.stereotype.Component;
23+
24+
/**
25+
* {@link WebSecurityCustomizer} used to test their inclusion in
26+
* {@link WebMvcTest @WebMvcTest}.
27+
*
28+
* @author Andy Wilkinson
29+
*/
30+
@Component
31+
class ExampleWebSecurityCustomizer implements WebSecurityCustomizer {
32+
33+
@Override
34+
public void customize(WebSecurity web) {
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.security.test.autoconfigure.webmvc;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
23+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
24+
import org.springframework.context.ConfigurableApplicationContext;
25+
import org.springframework.security.web.SecurityFilterChain;
26+
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
29+
/**
30+
* Integration tests for SpringSecurity with {@link WebMvcTest @WebMvcTest}.
31+
*
32+
* @author Andy Wilkinson
33+
*/
34+
@WebMvcTest
35+
class SecurityWebMvcTestIntegrationTests {
36+
37+
@Autowired
38+
private ConfigurableApplicationContext context;
39+
40+
@Test
41+
void includesWebSecurityConfigurer() {
42+
assertThat(AssertableApplicationContext.get(() -> this.context))
43+
.hasSingleBean(ExampleWebSecurityConfigurer.class);
44+
}
45+
46+
@Test
47+
void includesWebSecurityCustomizer() {
48+
assertThat(AssertableApplicationContext.get(() -> this.context))
49+
.hasSingleBean(ExampleWebSecurityCustomizer.class);
50+
}
51+
52+
@Test
53+
void includesSecurityFilterChain() {
54+
assertThat(AssertableApplicationContext.get(() -> this.context)).hasSingleBean(SecurityFilterChain.class);
55+
}
56+
57+
}

module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTypeExcludeFilter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ class WebMvcTypeExcludeFilter extends StandardAnnotationCustomizableTypeExcludeF
5050
private static final Class<?>[] NO_CONTROLLERS = {};
5151

5252
private static final String[] OPTIONAL_INCLUDES = { "tools.jackson.databind.JacksonModule",
53-
"org.springframework.boot.jackson.JacksonComponent",
54-
"org.springframework.security.config.annotation.web.WebSecurityConfigurer",
55-
"org.springframework.security.web.SecurityFilterChain", "org.thymeleaf.dialect.IDialect",
53+
"org.springframework.boot.jackson.JacksonComponent", "org.thymeleaf.dialect.IDialect",
5654
"com.fasterxml.jackson.databind.Module", "org.springframework.boot.jackson2.JsonComponent" };
5755

5856
private static final Set<Class<?>> KNOWN_INCLUDES;

0 commit comments

Comments
 (0)