Skip to content

Commit 364bc10

Browse files
Add hints for CompositeFilterChainProxy
Closes gh-14359
1 parent 8a93178 commit 364bc10

File tree

5 files changed

+114
-2
lines changed

5 files changed

+114
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2002-2023 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.security.config.aot.hint;
18+
19+
import org.springframework.aot.hint.MemberCategory;
20+
import org.springframework.aot.hint.RuntimeHints;
21+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
22+
import org.springframework.aot.hint.TypeReference;
23+
24+
/**
25+
* Runtime hints for
26+
* {@link org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration}
27+
*
28+
* @author Marcus da Coregio
29+
*/
30+
class WebMvcSecurityConfigurationRuntimeHints implements RuntimeHintsRegistrar {
31+
32+
@Override
33+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
34+
hints.reflection()
35+
.registerType(TypeReference
36+
.of("org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration$CompositeFilterChainProxy"),
37+
MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
38+
}
39+
40+
}

config/src/main/resources/META-INF/spring/aot.factories

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
22
org.springframework.security.config.annotation.authentication.configuration.AuthenticationManagerBeanRegistrationAotProcessor
33

44
org.springframework.aot.hint.RuntimeHintsRegistrar=\
5-
org.springframework.security.config.aot.hint.OAuth2LoginRuntimeHints
5+
org.springframework.security.config.aot.hint.OAuth2LoginRuntimeHints,\
6+
org.springframework.security.config.aot.hint.WebMvcSecurityConfigurationRuntimeHints
67

78
org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter=\
89
org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration.SpringSecurityHandlerMappingIntrospectorBeanRegistrationExcludeFilter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2002-2023 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.security.config.aot.hint;
18+
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.aot.hint.MemberCategory;
23+
import org.springframework.aot.hint.RuntimeHints;
24+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
25+
import org.springframework.aot.hint.TypeReference;
26+
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
27+
import org.springframework.core.io.support.SpringFactoriesLoader;
28+
import org.springframework.util.ClassUtils;
29+
30+
import static org.assertj.core.api.Assertions.assertThat;
31+
32+
/**
33+
* Tests for {@link WebMvcSecurityConfigurationRuntimeHints}
34+
*
35+
* @author Marcus da Coregio
36+
*/
37+
class WebMvcSecurityConfigurationRuntimeHintsTests {
38+
39+
private final RuntimeHints hints = new RuntimeHints();
40+
41+
@BeforeEach
42+
void setup() {
43+
SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
44+
.load(RuntimeHintsRegistrar.class)
45+
.forEach((registrar) -> registrar.registerHints(this.hints, ClassUtils.getDefaultClassLoader()));
46+
}
47+
48+
@Test
49+
void compositeFilterChainProxyHasHints() {
50+
assertThat(RuntimeHintsPredicates.reflection()
51+
.onType(TypeReference
52+
.of("org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration$CompositeFilterChainProxy"))
53+
.withMemberCategory(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(this.hints);
54+
}
55+
56+
}

test/src/main/java/org/springframework/security/test/aot/hint/WebTestUtilsTestRuntimeHints.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.aot.hint.MemberCategory;
2020
import org.springframework.aot.hint.RuntimeHints;
21+
import org.springframework.aot.hint.TypeReference;
2122
import org.springframework.security.web.FilterChainProxy;
2223
import org.springframework.security.web.context.SecurityContextHolderFilter;
2324
import org.springframework.security.web.context.SecurityContextPersistenceFilter;
@@ -46,6 +47,10 @@ public void registerHints(RuntimeHints hints, Class<?> testClass, ClassLoader cl
4647

4748
private void registerFilterChainProxyHints(RuntimeHints hints) {
4849
hints.reflection().registerType(FilterChainProxy.class, MemberCategory.INVOKE_DECLARED_METHODS);
50+
hints.reflection()
51+
.registerType(TypeReference
52+
.of("org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration$CompositeFilterChainProxy"),
53+
MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
4954
}
5055

5156
private void registerCsrfTokenRepositoryHints(RuntimeHints hints) {

test/src/test/java/org/springframework/security/test/aot/hint/WebTestUtilsTestRuntimeHintsTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121

2222
import org.springframework.aot.hint.MemberCategory;
2323
import org.springframework.aot.hint.RuntimeHints;
24+
import org.springframework.aot.hint.TypeReference;
2425
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
2526
import org.springframework.core.io.support.SpringFactoriesLoader;
2627
import org.springframework.security.web.FilterChainProxy;
@@ -56,6 +57,15 @@ void filterChainProxyHasHints() {
5657
.withMemberCategories(MemberCategory.INVOKE_DECLARED_METHODS)).accepts(this.hints);
5758
}
5859

60+
@Test
61+
void compositeFilterChainProxyHasHints() {
62+
assertThat(RuntimeHintsPredicates.reflection()
63+
.onType(TypeReference
64+
.of("org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration$CompositeFilterChainProxy"))
65+
.withMemberCategories(MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS))
66+
.accepts(this.hints);
67+
}
68+
5969
@Test
6070
void csrfFilterHasHints() {
6171
assertThat(RuntimeHintsPredicates.reflection()

0 commit comments

Comments
 (0)