This commit is contained in:
2023-10-16 15:30:17 +08:00
parent 73aec7279e
commit 1b20b0c34c

View File

@ -2,6 +2,7 @@ package com.jnssd.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.AntPathMatcher;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.OAuthBuilder;
import springfox.documentation.builders.PathSelectors;
@ -51,7 +52,6 @@ public class SwaggerConfig {
}
public List<SecurityScheme> initSecuritySchemeList() {
List<SecurityScheme> list = new ArrayList<>();
list.add(securitySchemeBasicAuth());
@ -113,7 +113,16 @@ public class SwaggerConfig {
private SecurityContext securityContext() {
List<SecurityReference> list = new ArrayList<>();
Arrays.stream(securitySchemeNames).forEach(s -> list.add(new SecurityReference(s, new AuthorizationScope[0])));
return SecurityContext.builder().securityReferences(list).build();
return SecurityContext.builder().operationSelector(operationContext -> {
System.out.println("operationContext" + operationContext);
// 除了get方法其他方法都要校验
// return !operationContext.httpMethod().name().equals("GET");
// 通过地址模糊匹配
AntPathMatcher pathMatcher = new AntPathMatcher();
String path = operationContext.requestMappingPattern();
return pathMatcher.match("/menu/**", path) || pathMatcher.match("/user/**", path);
}).securityReferences(list).build();
}
private List<AuthorizationScope> scopes() {
@ -123,6 +132,7 @@ public class SwaggerConfig {
list.add(new AuthorizationScope("admin_scope", "Grants read write and delete access"));
return list;
}
@Bean
public SecurityConfiguration security() {
return SecurityConfigurationBuilder.builder().clientId("").clientSecret("").realm("*").appName("").scopeSeparator("").useBasicAuthenticationWithAccessCodeGrant(false).build();