Skip to content

Commit

Permalink
Adding spring-security Hints
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Aug 6, 2023
1 parent 41e00a5 commit cdde2ac
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.commons.lang3.reflect.FieldUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springdoc.core.configuration.hints.SpringDocSecurityHints;
import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
import org.springdoc.core.customizers.OpenApiCustomizer;

Expand All @@ -52,6 +53,7 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -79,6 +81,7 @@
@ConditionalOnClass(SecurityFilterChain.class)
@ConditionalOnWebApplication
@ConditionalOnBean(SpringDocConfiguration.class)
@ImportRuntimeHints(SpringDocSecurityHints.class)
public class SpringDocSecurityConfiguration {

private static final Logger LOGGER = LoggerFactory.getLogger(SpringDocSecurityConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
*
* *
* * *
* * * *
* * * * * Copyright 2019-2022 the original author or authors.
* * * * *
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * * you may not use this file except in compliance with the License.
* * * * * You may obtain a copy of the License at
* * * * *
* * * * * https://www.apache.org/licenses/LICENSE-2.0
* * * * *
* * * * * Unless required by applicable law or agreed to in writing, software
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * * See the License for the specific language governing permissions and
* * * * * limitations under the License.
* * * *
* * *
* *
*
*/

package org.springdoc.core.configuration.hints;

import java.util.Arrays;

import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;

/**
* The type Spring doc DataRest hints.
* @author bnasslahsen
*/
public class SpringDocSecurityHints implements RuntimeHintsRegistrar {

//spring-security
static String[] springSecurityTypeNames = { "org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter",
"org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter",
"org.springframework.security.web.util.matcher.OrRequestMatcher"
};

@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
//spring-security
Arrays.stream(springSecurityTypeNames).forEach(springDataRestTypeName ->
hints.reflection()
.registerTypeIfPresent(classLoader, springDataRestTypeName,
hint -> hint.withMembers(MemberCategory.DECLARED_FIELDS,
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
MemberCategory.INVOKE_DECLARED_METHODS
))
);
}

}

0 comments on commit cdde2ac

Please sign in to comment.