mirror of https://github.com/jeecgboot/jeecg-boot
修改token验证请求头信息及排除不需要的接口信息
parent
20037ae02b
commit
299f63c6e9
|
@ -11,9 +11,9 @@ import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.common.constant.CommonConstant;
|
||||||
import org.springdoc.core.GroupedOpenApi;
|
import org.springdoc.core.GroupedOpenApi;
|
||||||
|
import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
/**
|
/**
|
||||||
|
@ -43,9 +43,26 @@ public class Swagger3Config implements WebMvcConfigurer {
|
||||||
.packagesToExclude("org.jeecg.modules.drag", "org.jeecg.modules.online", "org.jeecg.modules.jmreport")
|
.packagesToExclude("org.jeecg.modules.drag", "org.jeecg.modules.online", "org.jeecg.modules.jmreport")
|
||||||
// 加了Operation注解的方法,才生成接口文档
|
// 加了Operation注解的方法,才生成接口文档
|
||||||
.addOpenApiMethodFilter(method -> method.isAnnotationPresent(Operation.class))
|
.addOpenApiMethodFilter(method -> method.isAnnotationPresent(Operation.class))
|
||||||
|
.addOpenApiCustomiser(globalOpenApiCustomizer())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GlobalOpenApiCustomizer globalOpenApiCustomizer() {
|
||||||
|
return openApi -> {
|
||||||
|
// 全局添加鉴权参数
|
||||||
|
if (openApi.getPaths() != null) {
|
||||||
|
openApi.getPaths().forEach((s, pathItem) -> {
|
||||||
|
// 接口添加鉴权参数
|
||||||
|
pathItem.readOperations()
|
||||||
|
.forEach(operation ->
|
||||||
|
operation.addSecurityItem(new SecurityRequirement().addList(CommonConstant.X_ACCESS_TOKEN))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public OpenAPI customOpenAPI() {
|
public OpenAPI customOpenAPI() {
|
||||||
return new OpenAPI()
|
return new OpenAPI()
|
||||||
|
@ -56,8 +73,8 @@ public class Swagger3Config implements WebMvcConfigurer {
|
||||||
.description( "后台API接口")
|
.description( "后台API接口")
|
||||||
.termsOfService("NO terms of service")
|
.termsOfService("NO terms of service")
|
||||||
.license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html")))
|
.license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html")))
|
||||||
.addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION))
|
.addSecurityItem(new SecurityRequirement().addList(CommonConstant.X_ACCESS_TOKEN))
|
||||||
.components(new Components().addSecuritySchemes(HttpHeaders.AUTHORIZATION,
|
.components(new Components().addSecuritySchemes(CommonConstant.X_ACCESS_TOKEN,
|
||||||
new SecurityScheme().name(HttpHeaders.AUTHORIZATION).type(SecurityScheme.Type.HTTP)));
|
new SecurityScheme().name(CommonConstant.X_ACCESS_TOKEN).type(SecurityScheme.Type.HTTP)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
server:
|
server:
|
||||||
port: 7001
|
port: 7001
|
||||||
|
|
||||||
|
springdoc:
|
||||||
|
packages-to-exclude:
|
||||||
|
- org.jeecg.modules.drag
|
||||||
|
- org.jeecg.modules.online
|
||||||
|
- org.jeecg.modules.jmreport
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: jeecg-system
|
name: jeecg-system
|
||||||
|
|
Loading…
Reference in New Issue