Skip to content

Commit cdde2ac

Browse files
committed
Adding spring-security Hints
1 parent 41e00a5 commit cdde2ac

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/configuration/SpringDocSecurityConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.commons.lang3.reflect.FieldUtils;
4242
import org.slf4j.Logger;
4343
import org.slf4j.LoggerFactory;
44+
import org.springdoc.core.configuration.hints.SpringDocSecurityHints;
4445
import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
4546
import org.springdoc.core.customizers.OpenApiCustomizer;
4647

@@ -52,6 +53,7 @@
5253
import org.springframework.context.ApplicationContext;
5354
import org.springframework.context.annotation.Bean;
5455
import org.springframework.context.annotation.Configuration;
56+
import org.springframework.context.annotation.ImportRuntimeHints;
5557
import org.springframework.context.annotation.Lazy;
5658
import org.springframework.http.HttpStatus;
5759
import org.springframework.security.core.Authentication;
@@ -79,6 +81,7 @@
7981
@ConditionalOnClass(SecurityFilterChain.class)
8082
@ConditionalOnWebApplication
8183
@ConditionalOnBean(SpringDocConfiguration.class)
84+
@ImportRuntimeHints(SpringDocSecurityHints.class)
8285
public class SpringDocSecurityConfiguration {
8386

8487
private static final Logger LOGGER = LoggerFactory.getLogger(SpringDocSecurityConfiguration.class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2022 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
25+
package org.springdoc.core.configuration.hints;
26+
27+
import java.util.Arrays;
28+
29+
import org.springframework.aot.hint.MemberCategory;
30+
import org.springframework.aot.hint.RuntimeHints;
31+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
32+
33+
/**
34+
* The type Spring doc DataRest hints.
35+
* @author bnasslahsen
36+
*/
37+
public class SpringDocSecurityHints implements RuntimeHintsRegistrar {
38+
39+
//spring-security
40+
static String[] springSecurityTypeNames = { "org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter",
41+
"org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter",
42+
"org.springframework.security.web.util.matcher.OrRequestMatcher"
43+
};
44+
45+
@Override
46+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
47+
//spring-security
48+
Arrays.stream(springSecurityTypeNames).forEach(springDataRestTypeName ->
49+
hints.reflection()
50+
.registerTypeIfPresent(classLoader, springDataRestTypeName,
51+
hint -> hint.withMembers(MemberCategory.DECLARED_FIELDS,
52+
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
53+
MemberCategory.INVOKE_DECLARED_METHODS
54+
))
55+
);
56+
}
57+
58+
}
59+

0 commit comments

Comments
 (0)