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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
import springfox.documentation.builders.PathSelectors;
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
import springfox.documentation.service.*;
|
import springfox.documentation.service.*;
|
||||||
|
@ -19,20 +20,12 @@ public class SwaggerConfiguration {
|
||||||
public static final String AUTHORIZATION_HEADER = "Authorization";
|
public static final String AUTHORIZATION_HEADER = "Authorization";
|
||||||
|
|
||||||
private ApiInfo apiInfo() {
|
private ApiInfo apiInfo() {
|
||||||
return new ApiInfo("My REST API",
|
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());
|
||||||
"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
|
@Bean
|
||||||
public Docket api() {
|
public Docket api() {
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
|
||||||
.apiInfo(apiInfo())
|
|
||||||
.securityContexts(Arrays.asList(securityContext()))
|
.securityContexts(Arrays.asList(securityContext()))
|
||||||
.securitySchemes(Arrays.asList(apiKey()))
|
.securitySchemes(Arrays.asList(apiKey()))
|
||||||
.select()
|
.select()
|
||||||
|
@ -47,16 +40,17 @@ public class SwaggerConfiguration {
|
||||||
|
|
||||||
private SecurityContext securityContext() {
|
private SecurityContext securityContext() {
|
||||||
return SecurityContext.builder()
|
return SecurityContext.builder()
|
||||||
.securityReferences(defaultAuth())
|
.securityReferences(List.of(defaultAuth()))
|
||||||
|
.operationSelector(o -> o.requestMappingPattern()
|
||||||
|
.matches("/.*"))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SecurityReference> defaultAuth() {
|
private SecurityReference defaultAuth() {
|
||||||
AuthorizationScope authorizationScope
|
return SecurityReference.builder()
|
||||||
= new AuthorizationScope("global", "accessEverything");
|
.scopes(new AuthorizationScope[0])
|
||||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
.reference("JWT")
|
||||||
authorizationScopes[0] = authorizationScope;
|
.build();
|
||||||
return Arrays.asList(new SecurityReference("JWT", authorizationScopes));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue