Skip to content

Commit

Permalink
[feat] swagger 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
CYJhub committed Jan 22, 2024
1 parent be79a8b commit 2a67a6c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
"/select-role","/information", "/upload",
/* swagger v3 */
"/v3/api-docs/**",
"/swagger-ui/**"
"/swagger-ui/**",
"/v2/api-docs",
"/swagger-resources",
"/swagger-resources/**",
"/configuration/ui",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**"
).permitAll()
// .antMatchers("/api/v2/**").hasRole(Role.
// USER.name())
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/shop/hooking/hooking/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.SecurityReference;
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.util.*;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket restAPI() {
return new Docket(DocumentationType.SWAGGER_2)
.securityContexts(Arrays.asList(securityContext()))
.securitySchemes(Arrays.asList(apiKey()))
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("shop.hooking.hooking"))
.apis(RequestHandlerSelectors.basePackage("shop.hooking.hooking.controller"))
.paths(PathSelectors.any())
.build();
}
Expand All @@ -30,4 +38,21 @@ private ApiInfo apiInfo() {
.description("후킹 API 명세서입니다.")
.build();
}

private SecurityContext securityContext() {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.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));
}

private ApiKey apiKey() {
return new ApiKey("Authorization", "Authorization", "header");
}
}

0 comments on commit 2a67a6c

Please sign in to comment.