-
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.
Complete access and refresh token implementation.
- Loading branch information
1 parent
cdade4d
commit 0152f47
Showing
19 changed files
with
158 additions
and
176 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
3 changes: 2 additions & 1 deletion
3
src/main/java/com/example/holidayplanner/HolidayPlannerApplication.java
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
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
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
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
78 changes: 19 additions & 59 deletions
78
src/main/java/com/example/holidayplanner/config/SwaggerConfig.java
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,71 +1,31 @@ | ||
package com.example.holidayplanner.config; | ||
|
||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.info.License; | ||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import springfox.documentation.builders.ApiInfoBuilder; | ||
import springfox.documentation.builders.PathSelectors; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.service.*; | ||
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; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Configuration | ||
@EnableSwagger2 | ||
public class SwaggerConfig implements WebMvcConfigurer { | ||
@Bean | ||
public Docket api() { | ||
return new Docket(DocumentationType.SWAGGER_2) | ||
.apiInfo(apiInfo()) | ||
.securityContexts(Arrays.asList(securityContext())) | ||
.securitySchemes(Arrays.asList(apiKey())) | ||
.pathMapping("/") | ||
.select() | ||
.apis(RequestHandlerSelectors.any()) | ||
.paths(PathSelectors.any()) | ||
.build() | ||
.tags(new Tag("User", "All User Endpoints"), new Tag("Group", "All Group Endpoints"), new Tag("Holiday", "All Holiday Endpoints")) | ||
|
||
.directModelSubstitute(LocalDate.class, String.class) | ||
.genericModelSubstitutes(ResponseEntity.class) | ||
; | ||
} | ||
|
||
ApiInfo apiInfo() { | ||
return new ApiInfoBuilder() | ||
.title("Holiday Planner") | ||
.version("1.0.0") | ||
.description("Swagger page for the Holiday Planner Monolith") | ||
.build() | ||
; | ||
} | ||
|
||
@Override | ||
public void addViewControllers(final ViewControllerRegistry registry) { | ||
registry.addRedirectViewController("/", "/swagger-ui/#/"); | ||
} | ||
|
||
private ApiKey apiKey () { | ||
return new ApiKey("Access Token", "Authorization", SecurityScheme.In.HEADER.name()); | ||
} | ||
|
||
private SecurityContext securityContext() { | ||
return SecurityContext.builder().securityReferences(securityReference()).build(); | ||
} | ||
|
||
private List<SecurityReference> securityReference() { | ||
AuthorizationScope[] authorizationScope = { new AuthorizationScope("global", "Empty Description")}; | ||
return Collections.singletonList(new SecurityReference("Access Token", authorizationScope)); | ||
public OpenAPI springShopOpenAPI() { | ||
return new OpenAPI().info(new Info().title("GetAway") | ||
.description("Api documentation for GetAway") | ||
.version("v0.01") | ||
.license(new License() | ||
.name("Apache 2.0").url("http://springdoc.org") | ||
)) | ||
.components(new Components().addSecuritySchemes("Api Key", new SecurityScheme() | ||
.type(SecurityScheme.Type.APIKEY) | ||
.scheme("bearer") | ||
.bearerFormat("jwt") | ||
.in(SecurityScheme.In.HEADER) | ||
.name("Authorization") | ||
)).addSecurityItem(new SecurityRequirement().addList("Api Key")); | ||
} | ||
} |
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
Oops, something went wrong.