From 04545e35763e3166e2e7a8db23bfe0dfbbd3d2a8 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 1 Aug 2024 16:20:13 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[style]=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index cbe79a71..8678ba5a 100644 --- a/build.gradle +++ b/build.gradle @@ -27,8 +27,9 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' // 스웨거 - implementation 'io.springfox:springfox-boot-starter:3.0.0' - implementation 'io.springfox:springfox-swagger-ui:3.0.0' +// implementation 'io.springfox:springfox-boot-starter:3.0.0' +// implementation 'io.springfox:springfox-swagger-ui:3.0.0' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' // S3 implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' From dccbf02b9fb5a9b2d5fc246c4abefe11e469c558 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 1 Aug 2024 16:20:39 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[fix]=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20url?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/security/SecurityConfig.java | 90 ++++++++++--------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java b/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java index 30ffad20..73ce8ba5 100644 --- a/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java +++ b/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java @@ -16,6 +16,8 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.servlet.handler.HandlerMappingIntrospector; import java.util.Arrays; +import java.util.List; + import static org.springframework.security.config.Customizer.withDefaults; @@ -27,7 +29,7 @@ public class SecurityConfig { @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(Arrays.asList("https://locahost:8080")); + configuration.setAllowedOrigins(List.of("http://locahost:8080")); configuration.setAllowedMethods(Arrays.asList("GET", "POST")); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); @@ -35,52 +37,56 @@ public CorsConfigurationSource corsConfigurationSource() { } @Bean - public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospector introspector) throws Exception { - MvcRequestMatcher.Builder mvcMatcherBuilder = new MvcRequestMatcher.Builder(introspector); - http - .formLogin(formLogin -> formLogin.disable()) - .httpBasic(httpBasic -> httpBasic.disable()) - .csrf(csrf -> csrf.disable()) - .cors(withDefaults()) - .headers(headers -> headers.frameOptions(frameOptions -> frameOptions.disable())) - .addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider), UsernamePasswordAuthenticationFilter.class) - .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) - .authorizeHttpRequests(request -> request - .requestMatchers( - "/api/auth/logout", - "/api/auth/reissue-token", - "/api/user/on-boarding/motivation", - "/api/user/on-boarding/level", - "/api/user/on-boarding/complete", - "/api/user", - "/api/user/profile-image", - "/api/user/profile", - "/api/veggie-info", - "/api/veggie-info/**", - "api/my-veggie", - "api/my-veggie/diary", - "/api/my-veggie/simple-list", - "/api/my-veggie/list" - ).permitAll() + public WebSecurityCustomizer configure() { + return (web -> web.ignoring() +// http://localhost:8080/swagger-ui/index.html + .requestMatchers( + "/swagger-ui/**", + "/v3/api-docs/**", + "/swagger-resources/**", + "/webjars/**" ) - .authorizeHttpRequests(request -> request.anyRequest().authenticated()); - - return http.build(); - - - } - @Bean - public WebSecurityCustomizer configure() { - return (web -> web.ignoring() - - .requestMatchers("/api/auth/kakao-login") + .requestMatchers("/api/auth/kakao-login") .requestMatchers("/api/auth/google-login") .requestMatchers("/api/my-veggie/routine") - .requestMatchers("/api/my-veggie/diary/{myVeggieId}/one") .requestMatchers("/api/my-veggie/diary/check") .requestMatchers("/api/my-veggie/{myVeggieId}/profile") - ); - } + ); + } + + + @Bean + public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospector introspector) throws Exception { + http + .addFilterAfter(new JwtAuthenticationFilter(jwtTokenProvider), UsernamePasswordAuthenticationFilter.class) + .authorizeHttpRequests(request -> request + .requestMatchers( + "/api/auth/logout", + "/api/auth/reissue-token", + "/api/user/on-boarding/motivation", + "/api/user/on-boarding/level", + "/api/user/on-boarding/complete", + "/api/user", + "/api/user/profile-image", + "/api/user/profile", + "/api/veggie-info", + "/api/veggie-info/**", + "api/my-veggie", + "api/my-veggie/diary", + "/api/my-veggie/simple-list", + "/api/my-veggie/list", + "/api/my-veggie/diary/{myVeggieId}/all", + "/api/my-veggie/diary/{myVeggieId}/one" + ) +// .authenticated() +// .anyRequest().denyAll() + .permitAll() + ) + .authorizeHttpRequests(request -> request.anyRequest().authenticated()); + return http.build(); + } + + } From a758f1eb9178f309ac0fa7387b6b09ab8f89d99a Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 1 Aug 2024 16:21:03 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[fix]=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85=20header=20authorization=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/SwaggerConfig.java | 71 ++++++++++++------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/global/config/SwaggerConfig.java b/src/main/java/com/modernfarmer/farmusspring/global/config/SwaggerConfig.java index a3a0beb7..06c49743 100644 --- a/src/main/java/com/modernfarmer/farmusspring/global/config/SwaggerConfig.java +++ b/src/main/java/com/modernfarmer/farmusspring/global/config/SwaggerConfig.java @@ -1,37 +1,58 @@ package com.modernfarmer.farmusspring.global.config; +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 springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; +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.ApiInfo; +//import springfox.documentation.spi.DocumentationType; +//import springfox.documentation.spring.web.plugins.Docket; + + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; + @Configuration -public class SwaggerConfig { - private static final String API_NAME = "Farmus Farm Service API"; - private static final String API_VERSION = "0.0.2"; - private static final String API_DESCRIPTION = "팜어스 팜 서비스 api 명세서입니다."; +public class SwaggerConfig implements WebMvcConfigurer { @Bean - public Docket api() { - return new Docket(DocumentationType.SWAGGER_2) - .useDefaultResponseMessages(false) //기본 응답코드 표시 - .apiInfo(apiInfo()) //Api 정보 - .select() - .apis(RequestHandlerSelectors.basePackage("com.example.farmusfarm.domain")) //적용할 패키지명 - .paths(PathSelectors.any()) //패키지 하위에서 적용할 url path 지정 - .build(); + public OpenAPI customOpenAPI() { + return new OpenAPI() + .info(new Info().title("My API").version("1.0")) + .addSecurityItem(new SecurityRequirement().addList("bearerAuth")) + .components(new io.swagger.v3.oas.models.Components() + .addSecuritySchemes("bearerAuth", new SecurityScheme() + .type(SecurityScheme.Type.HTTP) + .scheme("bearer") + .bearerFormat("JWT"))); } - public ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title(API_NAME) - .version(API_VERSION) - .description(API_DESCRIPTION) - .build(); - } +// private static final String API_NAME = "Farmus Farm Service API"; +// private static final String API_VERSION = "0.0.2"; +// private static final String API_DESCRIPTION = "팜어스 팜 서비스 api 명세서입니다."; +// +// @Bean +// public Docket api() { +// return new Docket(DocumentationType.SWAGGER_2) +// .useDefaultResponseMessages(false) //기본 응답코드 표시 +// .apiInfo(apiInfo()) //Api 정보 +// .select() +// .apis(RequestHandlerSelectors.basePackage("com.modernfarmer.farmusspring")) //적용할 패키지명 +// .paths(PathSelectors.any()) //패키지 하위에서 적용할 url path 지정 +// .build(); +// } +// +// public ApiInfo apiInfo() { +// return new ApiInfoBuilder() +// .title(API_NAME) +// .version(API_VERSION) +// .description(API_DESCRIPTION) +// .build(); +// } } From d4d764596abb46d73fc771cd3d32e949b96ab510 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 1 Aug 2024 16:21:18 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[fix]=20import=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/myveggiegarden/dto/response/MyVeggieDiaryCount.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieDiaryCount.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieDiaryCount.java index b3e43cae..059537f3 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieDiaryCount.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieDiaryCount.java @@ -3,7 +3,7 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; -import io.swagger.models.auth.In; + import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor;