replace the securityContext (#14202)
This commit is contained in:
parent
fec7001cbd
commit
18baf2eed6
|
@ -2,6 +2,7 @@ package com.baeldung.swaggerjwt.configuration;
|
|||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.*;
|
||||
|
@ -19,20 +20,12 @@ public class SwaggerConfiguration {
|
|||
public static final String AUTHORIZATION_HEADER = "Authorization";
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfo("My REST API",
|
||||
"Some custom description of API.",
|
||||
"1.0",
|
||||
"Terms of service",
|
||||
new Contact("Sallo Szrajbman", "www.baeldung.com", "salloszraj@gmail.com"),
|
||||
"License of API",
|
||||
"API license URL",
|
||||
Collections.emptyList());
|
||||
return new ApiInfo("My REST API", "Some custom description of API.", "1.0", "Terms of service", new Contact("Sallo Szrajbman", "www.baeldung.com", "salloszraj@gmail.com"), "License of API", "API license URL", Collections.emptyList());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket api() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
|
||||
.securityContexts(Arrays.asList(securityContext()))
|
||||
.securitySchemes(Arrays.asList(apiKey()))
|
||||
.select()
|
||||
|
@ -47,16 +40,17 @@ public class SwaggerConfiguration {
|
|||
|
||||
private SecurityContext securityContext() {
|
||||
return SecurityContext.builder()
|
||||
.securityReferences(defaultAuth())
|
||||
.securityReferences(List.of(defaultAuth()))
|
||||
.operationSelector(o -> o.requestMappingPattern()
|
||||
.matches("/.*"))
|
||||
.build();
|
||||
}
|
||||
|
||||
List<SecurityReference> defaultAuth() {
|
||||
AuthorizationScope authorizationScope
|
||||
= new AuthorizationScope("global", "accessEverything");
|
||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
||||
authorizationScopes[0] = authorizationScope;
|
||||
return Arrays.asList(new SecurityReference("JWT", authorizationScopes));
|
||||
private SecurityReference defaultAuth() {
|
||||
return SecurityReference.builder()
|
||||
.scopes(new AuthorizationScope[0])
|
||||
.reference("JWT")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue