diff --git a/src/main/java/shop/hooking/hooking/config/SecurityConfig.java b/src/main/java/shop/hooking/hooking/config/SecurityConfig.java index 9ac5755..5c4234a 100644 --- a/src/main/java/shop/hooking/hooking/config/SecurityConfig.java +++ b/src/main/java/shop/hooking/hooking/config/SecurityConfig.java @@ -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()) diff --git a/src/main/java/shop/hooking/hooking/config/SwaggerConfig.java b/src/main/java/shop/hooking/hooking/config/SwaggerConfig.java index 9c4573d..7edfb52 100644 --- a/src/main/java/shop/hooking/hooking/config/SwaggerConfig.java +++ b/src/main/java/shop/hooking/hooking/config/SwaggerConfig.java @@ -5,10 +5,16 @@ 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 { @@ -16,9 +22,11 @@ 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(); } @@ -30,4 +38,21 @@ private ApiInfo apiInfo() { .description("후킹 API 명세서입니다.") .build(); } + + private SecurityContext securityContext() { + return SecurityContext.builder() + .securityReferences(defaultAuth()) + .build(); + } + + private List 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"); + } }