Skip to content

Commit ae82be7

Browse files
committed
Add Needed Runtime Hints
Issue gh-16536
1 parent a5fa197 commit ae82be7

File tree

5 files changed

+67
-2
lines changed

5 files changed

+67
-2
lines changed

config/src/main/java/org/springframework/security/config/aot/hint/WebSecurityConfigurationRuntimeHints.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* Runtime hints for
26-
* {@link org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration}
26+
* {@link org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration}
2727
*
2828
* @author Marcus da Coregio
2929
*/

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ org.springframework.security.config.annotation.authentication.configuration.Auth
33

44
org.springframework.aot.hint.RuntimeHintsRegistrar=\
55
org.springframework.security.config.aot.hint.OAuth2LoginRuntimeHints,\
6-
org.springframework.security.config.aot.hint.WebMvcSecurityConfigurationRuntimeHints
6+
org.springframework.security.config.aot.hint.WebMvcSecurityConfigurationRuntimeHints, \
7+
org.springframework.security.config.aot.hint.WebSecurityConfigurationRuntimeHints
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 WebSecurityConfigurationRuntimeHints}
34+
*
35+
* @author Marcus da Coregio
36+
*/
37+
class WebSecurityConfigurationRuntimeHintsTests {
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.WebSecurityConfiguration$CompositeFilterChainProxy"))
53+
.withMemberCategory(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(this.hints);
54+
}
55+
56+
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ private void registerFilterChainProxyHints(RuntimeHints hints) {
5151
.registerType(TypeReference
5252
.of("org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration$CompositeFilterChainProxy"),
5353
MemberCategory.INVOKE_DECLARED_METHODS);
54+
hints.reflection()
55+
.registerType(TypeReference
56+
.of("org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$CompositeFilterChainProxy"),
57+
MemberCategory.INVOKE_DECLARED_METHODS);
5458
}
5559

5660
private void registerCsrfTokenRepositoryHints(RuntimeHints hints) {

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

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ void compositeFilterChainProxyHasHints() {
6262
.onType(TypeReference
6363
.of("org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration$CompositeFilterChainProxy"))
6464
.withMemberCategory(MemberCategory.INVOKE_DECLARED_METHODS)).accepts(this.hints);
65+
assertThat(RuntimeHintsPredicates.reflection()
66+
.onType(TypeReference
67+
.of("org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$CompositeFilterChainProxy"))
68+
.withMemberCategory(MemberCategory.INVOKE_DECLARED_METHODS)).accepts(this.hints);
6569
}
6670

6771
@Test

0 commit comments

Comments
 (0)