forked from murraco/spring-boot-jwt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package murraco.configuration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
|
@@ -14,9 +15,12 @@ | |
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.service.ApiInfo; | ||
import springfox.documentation.service.ApiKey; | ||
import springfox.documentation.service.AuthorizationScope; | ||
import springfox.documentation.service.Contact; | ||
import springfox.documentation.service.SecurityReference; | ||
import springfox.documentation.service.Tag; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spi.service.contexts.SecurityContext; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
|
@@ -33,22 +37,40 @@ public Docket api() { | |
.build()// | ||
.apiInfo(metadata())// | ||
.useDefaultResponseMessages(false)// | ||
.securitySchemes(new ArrayList<>(Arrays.asList(new ApiKey("Bearer %token", "Authorization", "Header"))))// | ||
.securitySchemes(Collections.singletonList(apiKey())) | ||
.securityContexts(Collections.singletonList(securityContext())) | ||
// .securitySchemes(Arrays.asList(new ApiKey("Bearer %token", "Authorization", "Header")))// | ||
.tags(new Tag("users", "Operations about users"))// | ||
.tags(new Tag("ping", "Just a ping"))// | ||
.genericModelSubstitutes(Optional.class); | ||
|
||
} | ||
|
||
private ApiInfo metadata() { | ||
return new ApiInfoBuilder()// | ||
.title("JSON Web Token Authentication API")// | ||
.description( | ||
"This is a sample JWT authentication service. You can find out more about JWT at [https://jwt.io/](https://jwt.io/). For this sample, you can use the `admin` or `client` users (password: admin and client respectively) to test the authorization filters. Once you have successfully logged in and obtained the token, you should click on the right top button `Authorize` and introduce it with the prefix \"Bearer \".")// | ||
.description("This is a sample JWT authentication service. You can find out more about JWT at [https://jwt.io/](https://jwt.io/). For this sample, you can use the `admin` or `client` users (password: admin and client respectively) to test the authorization filters. Once you have successfully logged in and obtained the token, you should click on the right top button `Authorize` and introduce it with the prefix \"Bearer \".")// | ||
.version("1.0.0")// | ||
.license("MIT License").licenseUrl("http://opensource.org/licenses/MIT")// | ||
.contact(new Contact(null, null, "[email protected]"))// | ||
.build(); | ||
} | ||
|
||
private ApiKey apiKey() { | ||
return new ApiKey("Authorization", "Authorization", "header"); | ||
} | ||
|
||
private SecurityContext securityContext() { | ||
return SecurityContext.builder() | ||
.securityReferences(defaultAuth()) | ||
.forPaths(PathSelectors.any()) | ||
.build(); | ||
} | ||
|
||
private List<SecurityReference> defaultAuth() { | ||
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); | ||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; | ||
authorizationScopes[0] = authorizationScope; | ||
return Arrays.asList(new SecurityReference("Authorization", authorizationScopes)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters