From b6519b7e1abbc554110153fe9fb48c11d910e1c9 Mon Sep 17 00:00:00 2001 From: 0BVer Date: Thu, 7 Apr 2022 23:00:48 +0900 Subject: [PATCH 01/46] feat: add s3 upload pipeline --- backend/.gitignore | 2 + backend/build.gradle | 1 + .../backend/aws/component/S3Uploader.java | 75 +++++++++++++++++++ .../backend/aws/config/AmazonS3Config.java | 31 ++++++++ .../backend/aws/controller/S3Controller.java | 24 ++++++ .../resources/application-aws.yml.template | 8 ++ .../application-credentials.yml.template | 5 ++ backend/src/main/resources/application.yml | 4 + 8 files changed, 150 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/aws/component/S3Uploader.java create mode 100644 backend/src/main/java/com/hjjang/backend/aws/config/AmazonS3Config.java create mode 100644 backend/src/main/java/com/hjjang/backend/aws/controller/S3Controller.java create mode 100644 backend/src/main/resources/application-aws.yml.template create mode 100644 backend/src/main/resources/application-credentials.yml.template diff --git a/backend/.gitignore b/backend/.gitignore index 54d95d4..2a17aab 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -60,3 +60,5 @@ out/ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +/src/main/resources/application-aws.yml +/src/main/resources/application-credentials.yml diff --git a/backend/build.gradle b/backend/build.gradle index 328f8c8..b50891b 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -37,6 +37,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-websocket' implementation 'org.flywaydb:flyway-core' implementation 'org.springframework.kafka:spring-kafka' + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'io.micrometer:micrometer-registry-prometheus' diff --git a/backend/src/main/java/com/hjjang/backend/aws/component/S3Uploader.java b/backend/src/main/java/com/hjjang/backend/aws/component/S3Uploader.java new file mode 100644 index 0000000..93662cf --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/aws/component/S3Uploader.java @@ -0,0 +1,75 @@ +package com.hjjang.backend.aws.component; + +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.model.CannedAccessControlList; +import com.amazonaws.services.s3.model.PutObjectRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Optional; +import java.util.UUID; + +@Slf4j +@RequiredArgsConstructor +@Component +public class S3Uploader { + + private final AmazonS3Client amazonS3Client; + + @Value("${cloud.aws.s3.bucket}") + public String bucket; // S3 버킷 이름 + + public String upload(MultipartFile multipartFile, String dirName) throws IOException { + File uploadFile = + convert(multipartFile) // 파일 변환할 수 없으면 에러 + .orElseThrow( + () -> new IllegalArgumentException("error: MultipartFile -> File convert fail")); + + return upload(uploadFile, dirName); + } + + // S3로 파일 업로드하기 + private String upload(File uploadFile, String dirName) { + String fileName = dirName + "/" + UUID.randomUUID() + uploadFile.getName(); // S3에 저장된 파일 이름 + String uploadImageUrl = putS3(uploadFile, fileName); // s3로 업로드 + removeNewFile(uploadFile); + return uploadImageUrl; + } + + // S3로 업로드 + private String putS3(File uploadFile, String fileName) { + amazonS3Client.putObject( + new PutObjectRequest(bucket, fileName, uploadFile) + .withCannedAcl(CannedAccessControlList.PublicRead)); + return amazonS3Client.getUrl(bucket, fileName).toString(); + } + + // 로컬에 저장된 이미지 지우기 + private void removeNewFile(File targetFile) { + if (targetFile.delete()) { + log.info("File delete success"); + return; + } + log.info("File delete fail"); + } + + // 로컬에 파일 업로드 하기 + private Optional convert(MultipartFile file) throws IOException { + File convertFile = new File(System.getProperty("user.dir") + "/" + file.getOriginalFilename()); + if (convertFile.createNewFile()) { // 바로 위에서 지정한 경로에 File이 생성됨 (경로가 잘못되었다면 생성 불가능) + try (FileOutputStream fos = + new FileOutputStream(convertFile)) { // FileOutputStream 데이터를 파일에 바이트 스트림으로 저장하기 위함 + fos.write(file.getBytes()); + } + return Optional.of(convertFile); + } + + return Optional.empty(); + } +} diff --git a/backend/src/main/java/com/hjjang/backend/aws/config/AmazonS3Config.java b/backend/src/main/java/com/hjjang/backend/aws/config/AmazonS3Config.java new file mode 100644 index 0000000..65448ee --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/aws/config/AmazonS3Config.java @@ -0,0 +1,31 @@ +package com.hjjang.backend.aws.config; + +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class AmazonS3Config { + + @Value("${cloud.aws.credentials.access-key}") + private String accessKey; + + @Value("${cloud.aws.credentials.secret-key}") + private String secretKey; + + @Value("${cloud.aws.region.static}") + private String region; + + @Bean + public AmazonS3Client amazonS3Client() { + BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey); + return (AmazonS3Client) AmazonS3ClientBuilder.standard() + .withRegion(region) + .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) + .build(); + } +} \ No newline at end of file diff --git a/backend/src/main/java/com/hjjang/backend/aws/controller/S3Controller.java b/backend/src/main/java/com/hjjang/backend/aws/controller/S3Controller.java new file mode 100644 index 0000000..d478047 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/aws/controller/S3Controller.java @@ -0,0 +1,24 @@ +package com.hjjang.backend.aws.controller; + +import com.hjjang.backend.aws.component.S3Uploader; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; + +@RequiredArgsConstructor +@RestController +public class S3Controller { + + private final S3Uploader s3Uploader; + + //TODO: 이미지가 일정 용량 이상일 경우 업로드가 안되는데, 그 과정에서 이미지가 로컬에 저장은 되고 방치됌 -> 동일 파일 이름으로 이미지 업로드시 오류 유발 + @PostMapping("/images") + public String upload(@RequestParam("images") MultipartFile multipartFile) throws IOException { + s3Uploader.upload(multipartFile, "static"); + return "test"; + } +} diff --git a/backend/src/main/resources/application-aws.yml.template b/backend/src/main/resources/application-aws.yml.template new file mode 100644 index 0000000..e25fa48 --- /dev/null +++ b/backend/src/main/resources/application-aws.yml.template @@ -0,0 +1,8 @@ +cloud: + aws: + s3: + bucket: + region: + static: ap-northeast-2 + stack: + auto: false \ No newline at end of file diff --git a/backend/src/main/resources/application-credentials.yml.template b/backend/src/main/resources/application-credentials.yml.template new file mode 100644 index 0000000..7e67bb1 --- /dev/null +++ b/backend/src/main/resources/application-credentials.yml.template @@ -0,0 +1,5 @@ +cloud: + aws: + credentials: + accessKey: + secretKey: \ No newline at end of file diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index a76eea0..94ecc3c 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -1,6 +1,10 @@ spring: application: name: "backend" + profiles: + include: + - aws + - credentials datasource: driver-class-name: "com.mysql.cj.jdbc.Driver" url: "jdbc:mysql://localhost:3306/test_db?useSSL=false&useLegacyDatetimeCode=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul&characterEncoding=UTF-8&autoReconnect=true&createDatabaseIfNotExist=true" From 910dbd19b33aa10c81efa7a41528db59569e3f5f Mon Sep 17 00:00:00 2001 From: kim1387 Date: Fri, 15 Apr 2022 20:50:13 +0900 Subject: [PATCH 02/46] =?UTF-8?q?fix:=20spring=20boot=20version=20up?= =?UTF-8?q?=EC=9D=84=20=ED=95=98=EC=97=AC=20log4shell=20=EB=AC=B8=EC=A0=9C?= =?UTF-8?q?=EB=A5=BC=20=ED=95=B4=EA=B2=B0=ED=95=A9=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 그로 인해 더이상 필요 없는 defender를 삭제합니다 --- backend/build.gradle | 2 +- .../BinderControllerAdvice4springShell.java | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 backend/src/main/java/com/hjjang/backend/global/defender/BinderControllerAdvice4springShell.java diff --git a/backend/build.gradle b/backend/build.gradle index 3b3bb7a..e1284cc 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.springframework.boot' version '2.6.5' + id 'org.springframework.boot' version '2.6.6' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'org.asciidoctor.convert' version '1.5.8' id 'java' diff --git a/backend/src/main/java/com/hjjang/backend/global/defender/BinderControllerAdvice4springShell.java b/backend/src/main/java/com/hjjang/backend/global/defender/BinderControllerAdvice4springShell.java deleted file mode 100644 index ba22e50..0000000 --- a/backend/src/main/java/com/hjjang/backend/global/defender/BinderControllerAdvice4springShell.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.hjjang.backend.global.defender; - -import org.springframework.core.annotation.Order; -import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.InitBinder; - -@ControllerAdvice -@Order(10000) -public class BinderControllerAdvice4springShell { - - @InitBinder - public void setAllowedFields(WebDataBinder dataBinder) { - String[] denylist = new String[]{"class.*", "Class.*", "*.class.*", "*.Class.*"}; - dataBinder.setDisallowedFields(denylist); - } -} From a42ea3c7cb9ac063c97b49bb48eb13eb18b41e49 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Fri, 15 Apr 2022 20:57:32 +0900 Subject: [PATCH 03/46] =?UTF-8?q?feat:=20springsecurity=EB=A5=BC=20?= =?UTF-8?q?=EB=AA=B0=EB=9D=BC=EB=8F=84=20springcontext=EB=A1=9C=EB=B6=80?= =?UTF-8?q?=ED=84=B0=20=EC=82=AC=EC=9A=A9=EC=9E=90=EC=9D=98=20id=EB=A5=BC?= =?UTF-8?q?=20=EA=B0=80=EC=A0=B8=EC=98=AC=20=EC=88=98=20=EC=9E=88=EB=8A=94?= =?UTF-8?q?=20userutil=EC=9D=84=20=EC=B6=94=EA=B0=80=ED=95=98=EC=98=80?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/controller/UserController.java | 16 ++++++++-------- .../com/hjjang/backend/global/util/UserUtil.java | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java index 4db0396..d4ea9d4 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java @@ -1,13 +1,15 @@ package com.hjjang.backend.domain.user.controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + import com.hjjang.backend.domain.user.entity.User; import com.hjjang.backend.domain.user.service.UserService; import com.hjjang.backend.global.dto.ApiResponse; +import com.hjjang.backend.global.util.UserUtil; + import lombok.RequiredArgsConstructor; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/api/v1/users") @@ -18,10 +20,8 @@ public class UserController { @GetMapping public ApiResponse getUser() { - org.springframework.security.core.userdetails.User principal = (org.springframework.security.core.userdetails.User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); - - User user = userService.getUser(principal.getUsername()); - + String userId = UserUtil.getUserIdByToken(); + User user = userService.getUser(userId); return ApiResponse.success("user", user); } } diff --git a/backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java b/backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java new file mode 100644 index 0000000..ac70969 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java @@ -0,0 +1,16 @@ +package com.hjjang.backend.global.util; + +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.User; + +public class UserUtil { + + public static String getUserIdByToken() { + User principal = (User)SecurityContextHolder.getContext() + .getAuthentication() + .getPrincipal(); + + return principal.getUsername(); + } + +} From 3873479d68a8f708c9b5b8ba347bb3a09c83f5fc Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 18 Apr 2022 21:17:22 +0900 Subject: [PATCH 04/46] =?UTF-8?q?fix:=20=EC=8B=A4=EC=A0=9C=EB=A1=9C?= =?UTF-8?q?=EB=8A=94=20=EA=B0=92=EC=9D=B4=20=EB=93=A4=EC=96=B4=EA=B0=80?= =?UTF-8?q?=EC=A7=80=EB=A7=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EA=B0=80=20?= =?UTF-8?q?=EC=95=88=EB=90=98=EC=84=9C=20=EC=9D=BC=EB=8B=A8=EC=9D=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Integration/AuthPropertiesTest.java | 60 ------------------- 1 file changed, 60 deletions(-) delete mode 100644 backend/src/test/java/com/hjjang/backend/Integration/AuthPropertiesTest.java diff --git a/backend/src/test/java/com/hjjang/backend/Integration/AuthPropertiesTest.java b/backend/src/test/java/com/hjjang/backend/Integration/AuthPropertiesTest.java deleted file mode 100644 index ba9a269..0000000 --- a/backend/src/test/java/com/hjjang/backend/Integration/AuthPropertiesTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.hjjang.backend.Integration; - -import com.hjjang.backend.global.config.properties.AuthProperties; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -@ExtendWith(SpringExtension.class) -@SpringBootTest -class AuthPropertiesTest { - - @Autowired - private AuthProperties authProperties; - - @Test - void getAuth() { - - AuthProperties.TokenProperties tokenProperties = authProperties.getTokenProperties(); - assertAll( - ()-> assertEquals("asodfhwoeihro1i34u1097r09u13rqfasc12", tokenProperties.getTokenSecretKey()), - ()-> assertEquals(1800000, tokenProperties.getTokenExpireDate()), - ()-> assertEquals(604800000, tokenProperties.getRefreshTokenExpiry()) - ); - } - - @Test - void getJwt() { - AuthProperties.JwtProperties jwtProperties = authProperties.getJwtProperties(); - assertAll( - ()-> assertEquals("HJJangHandsomeGnuKenny120hy12049h014",jwtProperties.getSecretKey()) - ); - } - - @Test - void getOauth() { - AuthProperties.OAuth2Properties oAuthProperties = authProperties.getOAuth2Properties(); - assertAll( - ()-> assertLinesMatch( List.of("http://localhost:3000/oauth/redirect"), oAuthProperties.getRedirectUris()) - ); - } - - @Test - void cors() { - AuthProperties.CorsProperties corsProperties = authProperties.getCorsProperties(); - assertAll( - ()-> assertEquals("http://localhost:3000", corsProperties.getAllowedOrigins()), - ()-> assertEquals("GET,POST,PUT,DELETE,OPTIONS", corsProperties.getAllowedMethods()), - ()-> assertEquals("*", corsProperties.getAllowedHeaders()), - ()-> assertEquals(3600, corsProperties.getMaxAge()) - ); - } - - -} \ No newline at end of file From 2ce753586699f18535c949bc0c00179d107ecb43 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 18 Apr 2022 21:19:39 +0900 Subject: [PATCH 05/46] =?UTF-8?q?fix:metadata=EA=B0=80=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=EC=9C=BC=EB=A1=9C=20=EC=83=9D=EC=84=B1=EB=90=98?= =?UTF-8?q?=EB=A9=B4=20=EA=B1=B0=EA=B8=B0=EC=97=90=20=EB=A7=9E=EB=8A=94=20?= =?UTF-8?q?naming=20rule=EB=A1=9C=20propeties=EC=9D=B4=EB=A6=84=EC=9D=84?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=ED=95=98=EC=98=80=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/properties/AuthProperties.java | 49 +++++++++---------- backend/src/main/resources/application.yml | 26 +++++----- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/properties/AuthProperties.java b/backend/src/main/java/com/hjjang/backend/global/config/properties/AuthProperties.java index 4a6093b..8a7afa5 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/properties/AuthProperties.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/properties/AuthProperties.java @@ -3,45 +3,40 @@ import java.util.ArrayList; import java.util.List; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; +import org.springframework.context.annotation.Configuration; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; -@Getter -@Component -@ConfigurationProperties(prefix = "auth") +@Data +@Configuration +@ConfigurationProperties("auth-properties") public class AuthProperties { - - private final TokenProperties tokenProperties = new TokenProperties(); - private final OAuth2Properties oAuth2Properties = new OAuth2Properties(); - private final CorsProperties corsProperties = new CorsProperties(); - private final JwtProperties jwtProperties = new JwtProperties(); - - @Getter - @Setter - public final static class TokenProperties { + private TokenProperties tokenProperties = new TokenProperties(); + private JwtProperties jwtProperties = new JwtProperties(); + private CorsProperties corsProperties = new CorsProperties(); + private OAuth2Properties oAuth2Properties = new OAuth2Properties(); + @Data + public static class TokenProperties { + @Value("auth-properties.token-properties.token-secret-key") private String tokenSecretKey; private long tokenExpireDate; private long refreshTokenExpiry; } - - @Getter - @Setter - public final static class JwtProperties { + @Data + public static class JwtProperties { + @Value("auth-properties.jwt-properties.secret-key") private String secretKey; } - - @Getter - @Setter - public final static class OAuth2Properties { + @Data + public static class OAuth2Properties { + @Value("auth-properties.o-auth2-properties.redirect-uris[]") private List redirectUris = new ArrayList<>(); } - - @Getter - @Setter - public final static class CorsProperties { + @Data + public static class CorsProperties { + @Value("auth-properties.cors-properties.allowed-origins") private String allowedOrigins; private String allowedMethods; private String allowedHeaders; diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index bd3cdb7..6ad4658 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -15,7 +15,7 @@ spring: database: "mysql" show-sql: "true" hibernate: - ddl-auto: "none" + ddl-auto: "update" properties: hibernate: format_sql: true @@ -60,18 +60,20 @@ spring: tokenUri: https://kauth.kakao.com/oauth/token userInfoUri: https://kapi.kakao.com/v2/user/me userNameAttribute: id -auth: - tokenProperties: - tokenSecretKey: asodfhwoeihro1i34u1097r09u13rqfasc12 - tokenExpireDate: 1800000 - refreshTokenExpiry: 604800000 - jwtProperties: - secretKey: 'HJJangHandsomeGnuKenny120hy12049h014' - corsProperties: - allowed-origins: '*' - allowed-methods: GET,POST,PUT,DELETE,OPTIONS + + +auth-properties: + token-properties: + token-secret-key: 'asodfhwoeihro1i34u1097r09u13rqfasc12' + token-expire-date: 1800000 + refresh-token-expiry: 604800000 + jwt-properties: + secret-key: 'HJJangHandsomeGnuKenny120hy12049h014' + cors-properties: + allowed-origins: 'localhost:3000,http://localhost,http://localhost:3000' + allowed-methods: 'GET,POST,PUT,DELETE,OPTIONS' allowed-headers: '*' max-age: 3600 - oauth2Properties: + oAuth2Properties: redirectUris: - 'http://localhost:3000/oauth/redirect' \ No newline at end of file From 94399e8f1d42679d5913908892ec6a27b44d3e70 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 18 Apr 2022 21:21:15 +0900 Subject: [PATCH 06/46] =?UTF-8?q?feat:=20log=EB=A5=BC=20=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=EC=B2=B4=EB=A1=9C=20log4j=EB=A5=BC=20=EC=84=A0=ED=83=9D?= =?UTF-8?q?=ED=95=98=EC=98=80=EA=B3=A0=20=EC=84=A4=EC=A0=95=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=EB=8F=84=20=EC=84=A4=EC=A0=95=ED=95=98=EC=98=80?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - log4j2.xml 설정을 통해 log 출력 정보를 바꿀 수 있음 --- backend/build.gradle | 9 ++++++ backend/src/main/resources/log4j2.xml | 45 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 backend/src/main/resources/log4j2.xml diff --git a/backend/build.gradle b/backend/build.gradle index e1284cc..77479cc 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -53,9 +53,18 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-api:0.11.2' runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2' + implementation 'org.springframework.boot:spring-boot-starter-log4j2' + +} +configurations { + all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' + all*.exclude group: 'org.springframework.boot', module: 'logback-classic' } +tasks.named('compileJava') { + inputs.files(tasks.named('processResources')) +} bootRun { mainClassName = 'com.hjjang.backend.BackendApplication' diff --git a/backend/src/main/resources/log4j2.xml b/backend/src/main/resources/log4j2.xml new file mode 100644 index 0000000..85b2612 --- /dev/null +++ b/backend/src/main/resources/log4j2.xml @@ -0,0 +1,45 @@ + + + + + Default-Setting + %style{%d{yyyy/MM/dd HH:mm:ss,SSS}}{cyan} %highlight{[%-5p]}{FATAL=bg_red, ERROR=red, INFO=green, DEBUG=blue} [%C] %style{[%t]}{yellow}- %m%n - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 57d769b4585e25c15c2a1b2508ad4781dae81b71 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 18 Apr 2022 21:22:27 +0900 Subject: [PATCH 07/46] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20/login=20method=EB=A5=BC=20?= =?UTF-8?q?=EC=A7=80=EC=9B=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - local login을 사용하지 않는데 추가하는 것은 비효율적이다. 필요할때 추가하자 --- .../user/controller/UserAuthController.java | 39 +++++----- .../domain/user/service/UserAuthService.java | 77 +++---------------- 2 files changed, 30 insertions(+), 86 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java index 677e6fe..9f65a60 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java @@ -1,6 +1,15 @@ package com.hjjang.backend.domain.user.controller; -import com.hjjang.backend.domain.user.dto.LoginRequest; +import java.util.Date; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.entity.UserRefreshToken; import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; @@ -11,14 +20,9 @@ import com.hjjang.backend.global.dto.ApiResponse; import com.hjjang.backend.global.util.CookieUtil; import com.hjjang.backend.global.util.HeaderUtil; + import io.jsonwebtoken.Claims; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.Date; @RestController @RequestMapping("/api/v1/auth") @@ -33,14 +37,6 @@ public class UserAuthController { private final static long THREE_DAYS_MSEC = 259200000; private final static String REFRESH_TOKEN = "refresh_token"; - @PostMapping("/login") - public ApiResponse login(HttpServletRequest request, HttpServletResponse response, - @RequestBody LoginRequest loginRequest - ) { - String token = userAuthService.login(request, response, loginRequest); - return ApiResponse.success("token", token); - } - @GetMapping("/refresh") public ApiResponse refreshToken(HttpServletRequest request, HttpServletResponse response) { // access token 확인 @@ -61,8 +57,8 @@ public ApiResponse refreshToken(HttpServletRequest request, HttpServletResponse // refresh token String refreshToken = CookieUtil.getCookie(request, REFRESH_TOKEN) - .map(Cookie::getValue) - .orElse((null)); + .map(Cookie::getValue) + .orElse((null)); AuthToken authRefreshToken = tokenProvider.convertAuthToken(refreshToken); if (authRefreshToken.validate()) { @@ -70,16 +66,19 @@ public ApiResponse refreshToken(HttpServletRequest request, HttpServletResponse } // userId, refresh token 으로 DB 확인 - UserRefreshToken userRefreshToken = userRefreshTokenRepository.findByUserIdAndRefreshToken(userId, refreshToken); + UserRefreshToken userRefreshToken = userRefreshTokenRepository.findByUserIdAndRefreshToken(userId, + refreshToken); if (userRefreshToken == null) { return ApiResponse.invalidRefreshToken(); } Date now = new Date(); AuthToken newAccessToken = tokenProvider.createAuthToken( - userId, roleType.getCode(), new Date(now.getTime() + authProperties.getTokenProperties().getTokenExpireDate()) + userId, roleType.getCode(), + new Date(now.getTime() + authProperties.getTokenProperties().getTokenExpireDate()) ); - userAuthService.reissueRefreshTokenIfValidTimeleft3days(request, response, userRefreshToken, authRefreshToken, now); + userAuthService.reissueRefreshTokenIfValidTimeleft3days(request, response, userRefreshToken, authRefreshToken, + now); return ApiResponse.success("token", newAccessToken.getToken()); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java index 39b5466..4da49e1 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java @@ -1,26 +1,23 @@ package com.hjjang.backend.domain.user.service; -import com.hjjang.backend.domain.user.dto.LoginRequest; -import com.hjjang.backend.domain.user.entity.RoleType; +import static com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.*; + +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.stereotype.Service; + import com.hjjang.backend.domain.user.entity.UserRefreshToken; import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; import com.hjjang.backend.global.config.properties.AuthProperties; -import com.hjjang.backend.global.config.security.principal.UserPrincipal; import com.hjjang.backend.global.config.security.token.AuthToken; import com.hjjang.backend.global.config.security.token.AuthTokenProvider; import com.hjjang.backend.global.util.CookieUtil; -import lombok.RequiredArgsConstructor; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Service; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.Date; -import static com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.REFRESH_TOKEN; +import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @Service @@ -32,58 +29,6 @@ public class UserAuthService { private final UserRefreshTokenRepository userRefreshTokenRepository; private final static long THREE_DAYS_MSEC = 259200000; - public String login(HttpServletRequest request, HttpServletResponse response, - LoginRequest loginRequest) { - Authentication authentication = authenticationManager.authenticate( - new UsernamePasswordAuthenticationToken( - loginRequest.getId(), - loginRequest.getPassword() - ) - ); - - String userId = loginRequest.getId(); - SecurityContextHolder.getContext().setAuthentication(authentication); - - Date now = new Date(); - AuthToken accessToken = tokenProvider.createAuthToken( - userId, - ((UserPrincipal) authentication.getPrincipal()).getRoleType().getCode(), - new Date(now.getTime() + authProperties.getTokenProperties().getTokenExpireDate()) - ); - - long refreshTokenExpiry = authProperties.getTokenProperties().getRefreshTokenExpiry(); - AuthToken refreshToken = tokenProvider.createAuthToken( - authProperties.getTokenProperties().getTokenSecretKey(), - new Date(now.getTime() + refreshTokenExpiry) - ); - - // userId refresh token 으로 DB 확인 - UserRefreshToken userRefreshToken = userRefreshTokenRepository.findByUserId(userId); - if (userRefreshToken == null) { - // 없는 경우 새로 등록 - userRefreshToken = new UserRefreshToken(userId, refreshToken.getToken()); - userRefreshTokenRepository.saveAndFlush(userRefreshToken); - } else { - // DB에 refresh 토큰 업데이트 - userRefreshToken.setRefreshToken(refreshToken.getToken()); - } - - int cookieMaxAge = (int) refreshTokenExpiry / 60; - CookieUtil.deleteCookie(request, response, REFRESH_TOKEN); - CookieUtil.addCookie(response, REFRESH_TOKEN, refreshToken.getToken(), cookieMaxAge); - - return accessToken.getToken(); - } - - public AuthToken createAuthToken(String userId, RoleType roleType, Date expiredDate) { - Date now = new Date(); - return tokenProvider.createAuthToken( - userId, roleType.getCode(), - new Date(now.getTime() + authProperties.getTokenProperties().getTokenExpireDate()) - ); - } - - public void reissueRefreshTokenIfValidTimeleft3days(HttpServletRequest request, HttpServletResponse response, UserRefreshToken userRefreshToken, AuthToken authRefreshToken, Date now) { long validTime = authRefreshToken.getTokenClaims().getExpiration().getTime() - now.getTime(); From a0d04e899172e9099557a5e3ffc52bca9e6120a1 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 18 Apr 2022 21:23:20 +0900 Subject: [PATCH 08/46] =?UTF-8?q?feat:=20userutil=EB=A1=9C=20=EB=B0=94?= =?UTF-8?q?=EB=A1=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=EC=9D=98=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20db=EC=97=90=EC=84=9C=20=EB=B6=88=EB=9F=AC?= =?UTF-8?q?=EC=98=AC=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=ED=95=98?= =?UTF-8?q?=EC=98=80=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 2 +- .../hjjang/backend/global/util/UserUtil.java | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java index d4ea9d4..0b8abcd 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java @@ -20,7 +20,7 @@ public class UserController { @GetMapping public ApiResponse getUser() { - String userId = UserUtil.getUserIdByToken(); + String userId = UserUtil.getLoginUserIdByToken(); User user = userService.getUser(userId); return ApiResponse.success("user", user); } diff --git a/backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java b/backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java index ac70969..9e7db45 100644 --- a/backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java +++ b/backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java @@ -1,16 +1,33 @@ package com.hjjang.backend.global.util; +import javax.persistence.EntityNotFoundException; + import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.User; +import org.springframework.stereotype.Component; + +import com.hjjang.backend.domain.user.repository.UserRepository; + +import lombok.RequiredArgsConstructor; +@Component +@RequiredArgsConstructor public class UserUtil { - public static String getUserIdByToken() { + private final UserRepository userRepository; + + public static String getLoginUserIdByToken() { User principal = (User)SecurityContextHolder.getContext() .getAuthentication() .getPrincipal(); - return principal.getUsername(); } + public com.hjjang.backend.domain.user.entity.User getLoginUserByToken() { + + User principal = (User)SecurityContextHolder.getContext() + .getAuthentication() + .getPrincipal(); + return userRepository.findById(principal.getUsername()).orElseThrow(EntityNotFoundException::new); + } } From 1d58667f129a6382e63b6fd797ba822238dac1e0 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 18 Apr 2022 21:59:36 +0900 Subject: [PATCH 09/46] =?UTF-8?q?fix:=20UserRepository=20findUserById=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=98=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/user/repository/UserRepository.java | 7 +++++-- .../config/security/service/CustomOAuth2UserService.java | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRepository.java b/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRepository.java index 89c4ebb..c2b3385 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRepository.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRepository.java @@ -1,8 +1,11 @@ package com.hjjang.backend.domain.user.repository; -import com.hjjang.backend.domain.user.entity.User; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; +import com.hjjang.backend.domain.user.entity.User; + public interface UserRepository extends JpaRepository { - User findUserById(String Id); + Optional findUserById(String id); } diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java b/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java index 9994de3..2d08220 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java @@ -1,5 +1,9 @@ package com.hjjang.backend.global.config.security.service; +import java.util.Optional; + +import javax.persistence.EntityNotFoundException; + import org.springframework.security.authentication.InternalAuthenticationServiceException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService; @@ -40,8 +44,8 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic private OAuth2User process(OAuth2UserRequest userRequest, OAuth2User user) { ParsingUserContext userInfo = new KakaoParsingParsingUserContext(user.getAttributes()); - User savedUser = userRepository.findUserById(userInfo.getId()); - + Optional optionalSavedUser = userRepository.findUserById(userInfo.getId()); + User savedUser = optionalSavedUser.orElseThrow(EntityNotFoundException::new); if (savedUser == null) { savedUser = createUser(userInfo); } From ccbce2ff30a525eed49659353eb822713c4ea0d4 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 18 Apr 2022 22:00:08 +0900 Subject: [PATCH 10/46] faet: add UserProfileDTO --- .../domain/user/dto/UserProfileDTO.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/domain/user/dto/UserProfileDTO.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/dto/UserProfileDTO.java b/backend/src/main/java/com/hjjang/backend/domain/user/dto/UserProfileDTO.java new file mode 100644 index 0000000..f47474c --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/user/dto/UserProfileDTO.java @@ -0,0 +1,23 @@ +package com.hjjang.backend.domain.user.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class UserProfileDTO { + + private String userNickname; + + private String userImageUrl; + + private String userEmail; + + private Long userMannerTemperature; + + private String userUnivName; +} From 2bc058b6a0d84c9e9c362dca366eb63cb894649a Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 18 Apr 2022 22:01:23 +0900 Subject: [PATCH 11/46] fix: rename Class name for srp and return UserProfileDTO not entity --- .../user/service/UserProfileService.java | 34 +++++++++++++++++++ .../domain/user/service/UserService.java | 16 --------- 2 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java delete mode 100644 backend/src/main/java/com/hjjang/backend/domain/user/service/UserService.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java new file mode 100644 index 0000000..6aa89c9 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java @@ -0,0 +1,34 @@ +package com.hjjang.backend.domain.user.service; + +import javax.persistence.EntityNotFoundException; + +import org.springframework.stereotype.Service; + +import com.hjjang.backend.domain.user.dto.UserProfileDTO; +import com.hjjang.backend.domain.user.entity.User; +import com.hjjang.backend.domain.user.repository.UserRepository; +import com.hjjang.backend.global.util.UserUtil; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class UserProfileService { + private final UserRepository userRepository; + + public UserProfileDTO getUserProfile() { + String userId = UserUtil.getLoginUserIdByToken(); + + //todo add exception + User user = userRepository.findUserById(userId).orElseThrow(EntityNotFoundException::new); + + //todo found univName logic + return UserProfileDTO.builder() + .userNickname(user.getNickName()) + .userImageUrl(user.getImageUrl()) + .userMannerTemperature(user.getMannerTemperature()) + .userEmail(user.getEmail()) + .userUnivName("산기대") + .build(); + } +} diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserService.java b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserService.java deleted file mode 100644 index 3d6b1e5..0000000 --- a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hjjang.backend.domain.user.service; - -import com.hjjang.backend.domain.user.entity.User; -import com.hjjang.backend.domain.user.repository.UserRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -@Service -@RequiredArgsConstructor -public class UserService { - private final UserRepository userRepository; - - public User getUser(String userId) { - return userRepository.findUserById(userId); - } -} From 76fdf8b1a7e6db3fc51f4ec3b69bf1fcb288f84b Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 18 Apr 2022 22:01:45 +0900 Subject: [PATCH 12/46] fix: change api name --- .../domain/user/controller/UserController.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java index 0b8abcd..3c3d1c0 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java @@ -4,10 +4,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.hjjang.backend.domain.user.entity.User; -import com.hjjang.backend.domain.user.service.UserService; +import com.hjjang.backend.domain.user.dto.UserProfileDTO; +import com.hjjang.backend.domain.user.service.UserProfileService; import com.hjjang.backend.global.dto.ApiResponse; -import com.hjjang.backend.global.util.UserUtil; import lombok.RequiredArgsConstructor; @@ -16,12 +15,11 @@ @RequiredArgsConstructor public class UserController { - private final UserService userService; + private final UserProfileService userProfileService; - @GetMapping - public ApiResponse getUser() { - String userId = UserUtil.getLoginUserIdByToken(); - User user = userService.getUser(userId); - return ApiResponse.success("user", user); + @GetMapping("/profile") + public ApiResponse getProfile() { + UserProfileDTO userProfile = userProfileService.getUserProfile(); + return ApiResponse.success("userProfile", userProfile); } } From 543f661beefe13aa352c03adb015fbea00cf7991 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 18 Apr 2022 22:02:02 +0900 Subject: [PATCH 13/46] feat: add UserDoesNotExistException --- .../domain/user/exception/UserDoesNotExistException.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/domain/user/exception/UserDoesNotExistException.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/exception/UserDoesNotExistException.java b/backend/src/main/java/com/hjjang/backend/domain/user/exception/UserDoesNotExistException.java new file mode 100644 index 0000000..559aac5 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/user/exception/UserDoesNotExistException.java @@ -0,0 +1,6 @@ +package com.hjjang.backend.domain.user.exception; + +public class UserDoesNotExistException { + public UserDoesNotExistException() { + } +} From 01b259f89f89f44c29d908bb3afe57f5c2584f06 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 19 Apr 2022 01:44:00 +0900 Subject: [PATCH 14/46] =?UTF-8?q?fix:=20swagger=20antmatcher=EB=A5=BC=20?= =?UTF-8?q?=ED=86=B5=ED=95=B4=20=EC=9E=98=EB=90=98=EA=B2=8C=20=ED=95=98?= =?UTF-8?q?=EC=98=80=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/config/security/SecurityConfig.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java index b8912e2..4aa29aa 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java @@ -17,6 +17,7 @@ import org.springframework.web.cors.CorsUtils; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; import com.hjjang.backend.global.config.properties.AuthProperties; import com.hjjang.backend.global.config.security.exception.RestAuthenticationEntryPoint; @@ -75,9 +76,10 @@ protected void configure(HttpSecurity http) throws Exception { .accessDeniedHandler(tokenAccessDeniedHandler) // 로그인 거부 예외 .and() .authorizeRequests() + .antMatchers("/login", "/accounts", "/swagger-resources/**", "/swagger-ui/**").permitAll() + .antMatchers("/oauth2/authorization/**", "**/oauth2/code/*").permitAll() .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() //cors를 검증 하는 option 함수의 경우 별도의 filter 없이 허용 - //.antMatchers("/api/**").hasAnyAuthority(RoleType.USER.getCode()) - // todo swagger 고치고 권한 인증 묻기 + .antMatchers("/api/**").hasAnyAuthority(RoleType.USER.getCode()) .anyRequest().permitAll(); http From ef17a70d4563cac38d7cbcb3f9fc0bc700147564 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 19 Apr 2022 01:45:12 +0900 Subject: [PATCH 15/46] =?UTF-8?q?style:=20reissueRefreshToken=20method?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=A6=84=EC=9D=84=20=EB=B0=94=EA=BE=B8?= =?UTF-8?q?=EC=97=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/entity/UserRefreshToken.java | 21 ++++++++++++------- .../domain/user/service/UserAuthService.java | 10 ++++----- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/UserRefreshToken.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/UserRefreshToken.java index c442458..e6cd071 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/entity/UserRefreshToken.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/UserRefreshToken.java @@ -1,15 +1,22 @@ package com.hjjang.backend.domain.user.entity; +import static javax.persistence.GenerationType.*; +import static lombok.AccessLevel.*; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + import com.sun.istack.NotNull; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.NoArgsConstructor; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; - -import static javax.persistence.GenerationType.IDENTITY; -import static lombok.AccessLevel.PROTECTED; @AllArgsConstructor @EntityListeners(AuditingEntityListener.class) @@ -35,7 +42,7 @@ public UserRefreshToken(String userId, String refreshToken) { this.refreshToken = refreshToken; } - public void setRefreshToken(String refreshToken) { + public void reissueRefreshToken(String refreshToken) { this.refreshToken = refreshToken; } } diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java index 4da49e1..29ec82c 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java @@ -30,7 +30,7 @@ public class UserAuthService { private final static long THREE_DAYS_MSEC = 259200000; public void reissueRefreshTokenIfValidTimeleft3days(HttpServletRequest request, HttpServletResponse response, - UserRefreshToken userRefreshToken, AuthToken authRefreshToken, Date now) { + UserRefreshToken userRefreshToken, AuthToken authRefreshToken, Date now) { long validTime = authRefreshToken.getTokenClaims().getExpiration().getTime() - now.getTime(); // refresh 토큰 기간이 3일 이하로 남은 경우, refresh 토큰 갱신 @@ -39,14 +39,14 @@ public void reissueRefreshTokenIfValidTimeleft3days(HttpServletRequest request, long refreshTokenExpiry = authProperties.getTokenProperties().getRefreshTokenExpiry(); authRefreshToken = tokenProvider.createAuthToken( - authProperties.getTokenProperties().getTokenSecretKey(), - new Date(now.getTime() + refreshTokenExpiry) + authProperties.getTokenProperties().getTokenSecretKey(), + new Date(now.getTime() + refreshTokenExpiry) ); // DB에 refresh 토큰 업데이트 - userRefreshToken.setRefreshToken(authRefreshToken.getToken()); + userRefreshToken.reissueRefreshToken(authRefreshToken.getToken()); - int cookieMaxAge = (int) refreshTokenExpiry / 60; + int cookieMaxAge = (int)refreshTokenExpiry / 60; CookieUtil.deleteCookie(request, response, REFRESH_TOKEN); CookieUtil.addCookie(response, REFRESH_TOKEN, authRefreshToken.getToken(), cookieMaxAge); } From 6726dcc09dc7bfa3eb62831361694b4a43f12b27 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 19 Apr 2022 01:47:39 +0900 Subject: [PATCH 16/46] =?UTF-8?q?fix:=20user=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=EC=9D=98=20EntityNotFoundException=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EA=B3=A0=EC=B9=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit null인 경우 예외가 발생하게 해놓고 null일 떄 user를 생성하게 해서 오류가 발생 --- .../config/security/service/CustomOAuth2UserService.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java b/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java index 2d08220..ee65f52 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java @@ -2,8 +2,6 @@ import java.util.Optional; -import javax.persistence.EntityNotFoundException; - import org.springframework.security.authentication.InternalAuthenticationServiceException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService; @@ -45,7 +43,11 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic private OAuth2User process(OAuth2UserRequest userRequest, OAuth2User user) { ParsingUserContext userInfo = new KakaoParsingParsingUserContext(user.getAttributes()); Optional optionalSavedUser = userRepository.findUserById(userInfo.getId()); - User savedUser = optionalSavedUser.orElseThrow(EntityNotFoundException::new); + User savedUser = null; + if (optionalSavedUser.isPresent()) { + savedUser = optionalSavedUser.get(); + } + if (savedUser == null) { savedUser = createUser(userInfo); } From a76cd63922e199c4179a8953c019d74b8c5f4005 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 19 Apr 2022 01:45:12 +0900 Subject: [PATCH 17/46] =?UTF-8?q?style:=20reissueRefreshToken=20method?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=A6=84=EC=9D=84=20=EB=B0=94=EA=BE=B8?= =?UTF-8?q?=EC=97=88=EB=8B=A4.=20=EB=B0=94=EA=BE=B8=EA=B3=A0=20if=20else?= =?UTF-8?q?=EB=A5=BC=20=EA=B0=84=EB=8B=A8=ED=95=98=EA=B2=8C=20=EB=B0=94?= =?UTF-8?q?=EA=BE=B8=EC=97=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/OAuth2AuthenticationSuccessHandler.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationSuccessHandler.java b/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationSuccessHandler.java index cc46b98..1601a03 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationSuccessHandler.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationSuccessHandler.java @@ -98,7 +98,7 @@ protected String determineTargetUrl(HttpServletRequest request, HttpServletRespo // DB 저장 UserRefreshToken userRefreshToken = userRefreshTokenRepository.findByUserId(userInfo.getId()); if (userRefreshToken != null) { - userRefreshToken.setRefreshToken(refreshToken.getToken()); + userRefreshToken.reissueRefreshToken(refreshToken.getToken()); } else { userRefreshToken = new UserRefreshToken(userInfo.getId(), refreshToken.getToken()); userRefreshTokenRepository.saveAndFlush(userRefreshToken); @@ -140,11 +140,8 @@ private boolean isAuthorizedRedirectUri(String uri) { .anyMatch(authorizedRedirectUri -> { // Only validate host and port. Let the clients use different paths if they want to URI authorizedURI = URI.create(authorizedRedirectUri); - if (authorizedURI.getHost().equalsIgnoreCase(clientRedirectUri.getHost()) - && authorizedURI.getPort() == clientRedirectUri.getPort()) { - return true; - } - return false; + return authorizedURI.getHost().equalsIgnoreCase(clientRedirectUri.getHost()) + && authorizedURI.getPort() == clientRedirectUri.getPort(); }); } } From 1cd32d4e8316e7338dfc573bb5cc1e1a16cd9593 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 19 Apr 2022 01:50:56 +0900 Subject: [PATCH 18/46] =?UTF-8?q?feat:=20postman=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20redirect=20=EC=A3=BC=EC=86=8C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/application.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 6ad4658..f1883dc 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -76,4 +76,5 @@ auth-properties: max-age: 3600 oAuth2Properties: redirectUris: - - 'http://localhost:3000/oauth/redirect' \ No newline at end of file + - 'http://localhost:3000/oauth/redirect' + - 'https://getpostman.com/oauth2/redirect' \ No newline at end of file From 6c5a8b139070400c4247b3bc37f99a15883b68a0 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 19 Apr 2022 23:33:10 +0900 Subject: [PATCH 19/46] feat: add ErrorCode template --- .../global/response/code/ErrorCode.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/global/response/code/ErrorCode.java diff --git a/backend/src/main/java/com/hjjang/backend/global/response/code/ErrorCode.java b/backend/src/main/java/com/hjjang/backend/global/response/code/ErrorCode.java new file mode 100644 index 0000000..233d6d7 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/global/response/code/ErrorCode.java @@ -0,0 +1,25 @@ +package com.hjjang.backend.global.response.code; + +import org.springframework.http.HttpStatus; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ErrorCode { + + //Global + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), "G001", "내부 서버 오류"), + NOT_ALLOWED_METHOD(HttpStatus.METHOD_NOT_ALLOWED.value(), "G002", "허용 되지 않은 HTTP method"), + INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST.value(), "G003", "검증 되지 않은 입력"), + + //User + MEMBER_NOT_FOUND(HttpStatus.BAD_REQUEST.value(), "U001", "존재 하지 않는 사용자"), + NO_AUTHORITY(HttpStatus.FORBIDDEN.value(), "U002", "권한이 없음"),; + + + private final int httpStatus; + private final String code; + private final String message; +} From 5d22e166fa5a6303461ebd4919ff7ee5b7570627 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 19 Apr 2022 23:33:37 +0900 Subject: [PATCH 20/46] feat: add SuccessCode template --- .../global/response/code/SuccessCode.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java diff --git a/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java b/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java new file mode 100644 index 0000000..7a3fdec --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java @@ -0,0 +1,16 @@ +package com.hjjang.backend.global.response.code; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum SuccessCode { + + //User + USERPROFILE_SUCCESS(200, "U001", "프로필 조회 완료."),; + + private final int httpStatus; + private final String code; + private final String message; +} From 2f4f4b29acb170b01d59ac5fedb9b0904b7298ba Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 19 Apr 2022 23:34:38 +0900 Subject: [PATCH 21/46] feat: add ErrorResponse --- .../response/response/ErrorResponse.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java diff --git a/backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java b/backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java new file mode 100644 index 0000000..af55b00 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java @@ -0,0 +1,71 @@ +package com.hjjang.backend.global.response.response; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.validation.BindingResult; + +import com.hjjang.backend.global.response.code.ErrorCode; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class ErrorResponse { + + private int status; + private String code; + private String message; + private List errors; + + private ErrorResponse(final ErrorCode code, final List errors) { + this.message = code.getMessage(); + this.status = code.getHttpStatus(); + this.errors = errors; + this.code = code.getCode(); + } + + private ErrorResponse(final ErrorCode code) { + this.message = code.getMessage(); + this.status = code.getHttpStatus(); + this.code = code.getCode(); + this.errors = new ArrayList<>(); + } + + public static ErrorResponse of(final ErrorCode code, final BindingResult bindingResult) { + return new ErrorResponse(code, FieldError.of(bindingResult)); + } + + @Getter + @NoArgsConstructor + public static class FieldError { + private String field; + private String value; + private String reason; + + public FieldError(final String field, final String value, final String reason) { + this.field = field; + this.value = value; + this.reason = reason; + } + + public static List of(final String field, final String value, final String reason) { + List fieldErrors = new ArrayList<>(); + fieldErrors.add(new FieldError(field, value, reason)); + return fieldErrors; + } + + private static List of(final BindingResult bindingResult) { + final List fieldErrors = bindingResult.getFieldErrors(); + return fieldErrors.stream() + .map(error -> new FieldError( + error.getField(), + error.getRejectedValue() == null ? "" : error.getRejectedValue().toString(), + error.getDefaultMessage())) + .collect(Collectors.toList()); + } + + } +} From 9ee67876f782ccddb512275958ce9c28da2bf6e6 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 19 Apr 2022 23:35:20 +0900 Subject: [PATCH 22/46] feat: add BusinessException --- .../global/execption/BusinessException.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/global/execption/BusinessException.java diff --git a/backend/src/main/java/com/hjjang/backend/global/execption/BusinessException.java b/backend/src/main/java/com/hjjang/backend/global/execption/BusinessException.java new file mode 100644 index 0000000..0913091 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/global/execption/BusinessException.java @@ -0,0 +1,32 @@ +package com.hjjang.backend.global.execption; + +import java.util.ArrayList; +import java.util.List; + +import com.hjjang.backend.global.response.code.ErrorCode; +import com.hjjang.backend.global.response.response.ErrorResponse; + +import lombok.Getter; + +@Getter +public class BusinessException extends RuntimeException { + + private final ErrorCode errorCode; + private List errors = new ArrayList<>(); + + public BusinessException(String message, ErrorCode errorCode) { + super(message); + this.errorCode = errorCode; + } + + public BusinessException(ErrorCode errorCode) { + super(errorCode.getMessage()); + this.errorCode = errorCode; + } + + public BusinessException(ErrorCode errorCode, List errors) { + super(errorCode.getMessage()); + this.errors = errors; + this.errorCode = errorCode; + } +} \ No newline at end of file From 1aab85f5d10f437d4f3c6da9b9d5aafe102b6768 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Thu, 28 Apr 2022 15:11:20 +0900 Subject: [PATCH 23/46] =?UTF-8?q?fix:=20api=20=EC=82=AC=EC=9A=A9=ED=95=A0?= =?UTF-8?q?=20=EB=95=8C=20jwt=20=ED=86=A0=ED=81=B0=EC=9D=B4=20=EC=97=86?= =?UTF-8?q?=EC=96=B4=EB=8F=84=20=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hjjang/backend/global/config/security/SecurityConfig.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java index 4aa29aa..63860b0 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java @@ -17,7 +17,6 @@ import org.springframework.web.cors.CorsUtils; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; import com.hjjang.backend.global.config.properties.AuthProperties; import com.hjjang.backend.global.config.security.exception.RestAuthenticationEntryPoint; @@ -79,7 +78,7 @@ protected void configure(HttpSecurity http) throws Exception { .antMatchers("/login", "/accounts", "/swagger-resources/**", "/swagger-ui/**").permitAll() .antMatchers("/oauth2/authorization/**", "**/oauth2/code/*").permitAll() .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() //cors를 검증 하는 option 함수의 경우 별도의 filter 없이 허용 - .antMatchers("/api/**").hasAnyAuthority(RoleType.USER.getCode()) +// .antMatchers("/api/**").hasAnyAuthority(RoleType.USER.getCode()) .anyRequest().permitAll(); http From 85085b196372d5f408e3b730b2c1ee2ca7c5cf47 Mon Sep 17 00:00:00 2001 From: 0BVer Date: Sat, 30 Apr 2022 02:33:12 +0900 Subject: [PATCH 24/46] =?UTF-8?q?debug=20:=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=94=94=EB=B2=84=EA=B7=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PostController.java | 2 +- .../domain/post/domain/entity/Post.java | 24 ++++++++++++------- .../backend/domain/post/dto/PostRequest.java | 11 ++++++--- .../backend/domain/post/dto/PostResponse.java | 10 +++++--- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java b/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java index b668807..00e504f 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java @@ -20,7 +20,7 @@ public class PostController { private final PostServiceImpl postService; @PostMapping - public ResponseEntity createItem(@Validated @RequestParam PostRequest postRequest) { + public ResponseEntity createItem(@Validated @RequestBody PostRequest postRequest) { return ResponseEntity.ok( PostResponse.of( postService.save( diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java index a931bfe..616e4f8 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java @@ -3,6 +3,8 @@ import com.hjjang.backend.domain.user.entity.User; import com.hjjang.backend.infra.image.domain.entity.Image; import lombok.*; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.DynamicInsert; import javax.persistence.*; @@ -10,20 +12,21 @@ @Builder @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) +@DynamicInsert @Table(schema = "post") @Entity public class Post { @Id - @Column(name = "id", nullable = false) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne - @JoinColumn(name = "user_id") - private User user; +// @ManyToOne +// @JoinColumn(name = "user_id") +// private User user; - @ManyToOne - @JoinColumn(name = "image_id") - private Image image; +// @ManyToOne +// @JoinColumn(name = "image_id") +// private Image image; private String title; @@ -31,14 +34,19 @@ public class Post { private Integer item_price; + @ColumnDefault("0") private Integer views = 0; + @ColumnDefault("0") private Integer interest_number = 0; + @ColumnDefault("0") private Integer chat_number = 0; - private String is_sale_completion; + @ColumnDefault("'false'") + private String is_sale_completion = "false"; + @ColumnDefault("false") private boolean removed = false; public void removePost() { diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostRequest.java b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostRequest.java index bf1106a..6cffcc1 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostRequest.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostRequest.java @@ -1,11 +1,14 @@ package com.hjjang.backend.domain.post.dto; import com.hjjang.backend.domain.post.domain.entity.Post; -import lombok.Getter; +import lombok.*; import javax.validation.constraints.NotEmpty; @Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor public class PostRequest { @NotEmpty @@ -15,13 +18,15 @@ public class PostRequest { private String content; @NotEmpty - private int price; + private String price; public Post toEntity() { return Post.builder() +// .user(null) +// .image(null) .title(this.title) .content(this.content) - .item_price(this.price) + .item_price(Integer.valueOf(this.price)) .build(); } } diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponse.java b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponse.java index 7656dee..39681cd 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponse.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponse.java @@ -2,15 +2,19 @@ import com.hjjang.backend.domain.post.domain.entity.Post; import lombok.Builder; +import lombok.Getter; +import lombok.Setter; @Builder +@Getter +@Setter public class PostResponse { private Long id; - private Long user_id; +// private Long user_id; - private Long image_id; +// private Long image_id; private String title; @@ -32,7 +36,7 @@ public static PostResponse of(Post post) { return PostResponse.builder() .id(post.getId()) // .user_id(post.getUser().getId()) - .image_id(post.getImage().getId()) +// .image_id(post.getImage().getId()) .title(post.getTitle()) .content(post.getContent()) .item_price(post.getItem_price()) From 56cf061eb8c71e92075d07010ec8583b974633ba Mon Sep 17 00:00:00 2001 From: 0BVer Date: Sat, 30 Apr 2022 10:56:01 +0900 Subject: [PATCH 25/46] feat : add on swagger --- .../backend/global/config/SwaggerConfig.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/SwaggerConfig.java b/backend/src/main/java/com/hjjang/backend/global/config/SwaggerConfig.java index eca1d3c..f399fb1 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/SwaggerConfig.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/SwaggerConfig.java @@ -27,6 +27,22 @@ public GroupedOpenApi mailApi() { .build(); } + @Bean + public GroupedOpenApi postApi() { + return GroupedOpenApi.builder() + .group("posts") + .pathsToMatch("/api/posts/**") + .build(); + } + + @Bean + public GroupedOpenApi imageApi() { + return GroupedOpenApi.builder() + .group("images") + .pathsToMatch("/api/images/**") + .build(); + } + @Bean public OpenAPI bauctionOpenAPI() { return new OpenAPI() From 31ae7b8aee492ce6535243fabf4e9a2094b9b7e1 Mon Sep 17 00:00:00 2001 From: 0BVer Date: Sat, 30 Apr 2022 10:59:42 +0900 Subject: [PATCH 26/46] =?UTF-8?q?chore=20:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/entity/ImageRepositoryTest.java | 58 ------------------- .../image/service/ImageServiceImplTest.java | 43 -------------- 2 files changed, 101 deletions(-) delete mode 100644 backend/src/test/java/com/hjjang/backend/domain/image/domain/entity/ImageRepositoryTest.java delete mode 100644 backend/src/test/java/com/hjjang/backend/domain/image/service/ImageServiceImplTest.java diff --git a/backend/src/test/java/com/hjjang/backend/domain/image/domain/entity/ImageRepositoryTest.java b/backend/src/test/java/com/hjjang/backend/domain/image/domain/entity/ImageRepositoryTest.java deleted file mode 100644 index 1621e12..0000000 --- a/backend/src/test/java/com/hjjang/backend/domain/image/domain/entity/ImageRepositoryTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.hjjang.backend.domain.image.domain.entity; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.hjjang.backend.domain.image.domain.repository.ImageRepository; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; - -import java.util.Optional; - -@DataJpaTest -class ImageRepositoryTest { - - @Autowired - private ImageRepository imageRepository; - - @Test - void ImageTest() throws JsonProcessingException { - //given - Image image = new Image(0L, "test path", false); - Image image1 = imageRepository.save(image); -// ObjectMapper objectMapper = new ObjectMapper(); -// String imageStr = objectMapper.writeValueAsString(image); -// System.out.println(imageStr); - Long imageId = image1.getId(); - - //when - Optional image2 = imageRepository.findById(imageId); - - //then1 - Assertions.assertEquals(image2, image1); - - //then2 - image.removeImage(); - Assertions.assertEquals(image2.get().getPath(), "test path"); - Assertions.assertEquals(image2.get().getRemoved(), true); - } - -} - -/* -TODO - -엔티티 - 디비에 잘 들어가는지 -DTO - 생성 잘 되는지 -컴포넌트 - 메소드별로 잘 동작하는지 -컨트롤러 - 가짜 요청을 잘 처리하는지 -서비스 - 메소드별로 의도대로 잘 작동하는지 - - */ \ No newline at end of file diff --git a/backend/src/test/java/com/hjjang/backend/domain/image/service/ImageServiceImplTest.java b/backend/src/test/java/com/hjjang/backend/domain/image/service/ImageServiceImplTest.java deleted file mode 100644 index ae4b435..0000000 --- a/backend/src/test/java/com/hjjang/backend/domain/image/service/ImageServiceImplTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.hjjang.backend.domain.image.service; - -import com.hjjang.backend.domain.image.domain.repository.ImageRepository; -import com.hjjang.backend.domain.image.exception.ImageNotFoundException; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -class ImageServiceImplTest { - - @InjectMocks - private ImageServiceImpl imageService; - - @Mock - private ImageRepository imageRepository; - - @Test - void uploadNewImage() { - - } - - @Test - @DisplayName("존재하지 않는 이미지로 검색을 하였을 경우 ImageNotFoundException 발생한다.") - void nothingFoundImageById() { - //given - when(imageRepository.findById(anyLong())).thenReturn(Optional.empty()); - - //then - assertThrows(ImageNotFoundException.class, () -> { - imageService.findImageById(anyLong()); - }); - } -} \ No newline at end of file From 0295b7932d9d5e9bb414f950868e0121fc5340d4 Mon Sep 17 00:00:00 2001 From: 0BVer Date: Sat, 30 Apr 2022 11:10:48 +0900 Subject: [PATCH 27/46] debug : change image api url mapping --- .../hjjang/backend/infra/image/controller/ImageController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/infra/image/controller/ImageController.java b/backend/src/main/java/com/hjjang/backend/infra/image/controller/ImageController.java index b86bb17..f920983 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/image/controller/ImageController.java +++ b/backend/src/main/java/com/hjjang/backend/infra/image/controller/ImageController.java @@ -16,7 +16,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/images") +@RequestMapping("/api/images") public class ImageController { private final ImageService imageService; From 976a3ecb538a8b39004bb7f1d9fca3c31aace358 Mon Sep 17 00:00:00 2001 From: 0BVer Date: Sat, 30 Apr 2022 11:31:00 +0900 Subject: [PATCH 28/46] chore : move s3 package --- .../backend/{ => infra}/aws/component/S3Uploader.java | 2 +- .../backend/{ => infra}/aws/config/AmazonS3Config.java | 2 +- .../backend/{ => infra}/aws/controller/S3Controller.java | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) rename backend/src/main/java/com/hjjang/backend/{ => infra}/aws/component/S3Uploader.java (98%) rename backend/src/main/java/com/hjjang/backend/{ => infra}/aws/config/AmazonS3Config.java (95%) rename backend/src/main/java/com/hjjang/backend/{ => infra}/aws/controller/S3Controller.java (79%) diff --git a/backend/src/main/java/com/hjjang/backend/aws/component/S3Uploader.java b/backend/src/main/java/com/hjjang/backend/infra/aws/component/S3Uploader.java similarity index 98% rename from backend/src/main/java/com/hjjang/backend/aws/component/S3Uploader.java rename to backend/src/main/java/com/hjjang/backend/infra/aws/component/S3Uploader.java index 93662cf..edfe046 100644 --- a/backend/src/main/java/com/hjjang/backend/aws/component/S3Uploader.java +++ b/backend/src/main/java/com/hjjang/backend/infra/aws/component/S3Uploader.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.aws.component; +package com.hjjang.backend.infra.aws.component; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.CannedAccessControlList; diff --git a/backend/src/main/java/com/hjjang/backend/aws/config/AmazonS3Config.java b/backend/src/main/java/com/hjjang/backend/infra/aws/config/AmazonS3Config.java similarity index 95% rename from backend/src/main/java/com/hjjang/backend/aws/config/AmazonS3Config.java rename to backend/src/main/java/com/hjjang/backend/infra/aws/config/AmazonS3Config.java index 65448ee..f866d59 100644 --- a/backend/src/main/java/com/hjjang/backend/aws/config/AmazonS3Config.java +++ b/backend/src/main/java/com/hjjang/backend/infra/aws/config/AmazonS3Config.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.aws.config; +package com.hjjang.backend.infra.aws.config; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; diff --git a/backend/src/main/java/com/hjjang/backend/aws/controller/S3Controller.java b/backend/src/main/java/com/hjjang/backend/infra/aws/controller/S3Controller.java similarity index 79% rename from backend/src/main/java/com/hjjang/backend/aws/controller/S3Controller.java rename to backend/src/main/java/com/hjjang/backend/infra/aws/controller/S3Controller.java index d478047..cd8b1f5 100644 --- a/backend/src/main/java/com/hjjang/backend/aws/controller/S3Controller.java +++ b/backend/src/main/java/com/hjjang/backend/infra/aws/controller/S3Controller.java @@ -1,8 +1,9 @@ -package com.hjjang.backend.aws.controller; +package com.hjjang.backend.infra.aws.controller; -import com.hjjang.backend.aws.component.S3Uploader; +import com.hjjang.backend.infra.aws.component.S3Uploader; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @@ -10,13 +11,14 @@ import java.io.IOException; @RequiredArgsConstructor +@RequestMapping("/api/images") @RestController public class S3Controller { private final S3Uploader s3Uploader; //TODO: 이미지가 일정 용량 이상일 경우 업로드가 안되는데, 그 과정에서 이미지가 로컬에 저장은 되고 방치됌 -> 동일 파일 이름으로 이미지 업로드시 오류 유발 - @PostMapping("/images") + @PostMapping public String upload(@RequestParam("images") MultipartFile multipartFile) throws IOException { s3Uploader.upload(multipartFile, "static"); return "test"; From a52af52aab9fdd6e7a332743cc5acd548f5afe9b Mon Sep 17 00:00:00 2001 From: 0BVer Date: Sat, 30 Apr 2022 15:39:30 +0900 Subject: [PATCH 29/46] debug : s3 not uploaded problem --- .../image/controller/ImageController.java | 61 +++++++++++++++++++ .../image/domain/entity/Image.java | 2 +- .../domain/repository/ImageRepository.java | 4 +- .../{infra => domain}/image/dto/ImageDto.java | 4 +- .../domain/image/dto/ImagePathResponse.java | 20 ++++++ .../exception/ImageNotFoundException.java | 2 +- .../image/service/ImageService.java | 7 +-- .../image/service/LocalImageService.java} | 25 +++----- .../domain/image/service/S3ImageService.java | 44 +++++++++++++ .../domain/post/domain/entity/Post.java | 2 - .../infra/aws/controller/S3Controller.java | 26 -------- .../image/controller/ImageController.java | 47 -------------- .../infra/image/dto/ImageResponse.java | 20 ------ .../component/ImageUploader.java | 2 +- .../component/LocalUploader.java | 7 +-- .../infra/uploader/component/Path.java | 14 +++++ .../component/S3Uploader.java | 26 +++++--- 17 files changed, 178 insertions(+), 135 deletions(-) create mode 100644 backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java rename backend/src/main/java/com/hjjang/backend/{infra => domain}/image/domain/entity/Image.java (89%) rename backend/src/main/java/com/hjjang/backend/{infra => domain}/image/domain/repository/ImageRepository.java (53%) rename backend/src/main/java/com/hjjang/backend/{infra => domain}/image/dto/ImageDto.java (78%) create mode 100644 backend/src/main/java/com/hjjang/backend/domain/image/dto/ImagePathResponse.java rename backend/src/main/java/com/hjjang/backend/{infra => domain}/image/exception/ImageNotFoundException.java (86%) rename backend/src/main/java/com/hjjang/backend/{infra => domain}/image/service/ImageService.java (53%) rename backend/src/main/java/com/hjjang/backend/{infra/image/service/ImageServiceImpl.java => domain/image/service/LocalImageService.java} (51%) create mode 100644 backend/src/main/java/com/hjjang/backend/domain/image/service/S3ImageService.java delete mode 100644 backend/src/main/java/com/hjjang/backend/infra/aws/controller/S3Controller.java delete mode 100644 backend/src/main/java/com/hjjang/backend/infra/image/controller/ImageController.java delete mode 100644 backend/src/main/java/com/hjjang/backend/infra/image/dto/ImageResponse.java rename backend/src/main/java/com/hjjang/backend/infra/{image => uploader}/component/ImageUploader.java (87%) rename backend/src/main/java/com/hjjang/backend/infra/{image => uploader}/component/LocalUploader.java (84%) create mode 100644 backend/src/main/java/com/hjjang/backend/infra/uploader/component/Path.java rename backend/src/main/java/com/hjjang/backend/infra/{aws => uploader}/component/S3Uploader.java (72%) diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java b/backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java new file mode 100644 index 0000000..fee4454 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java @@ -0,0 +1,61 @@ +package com.hjjang.backend.domain.image.controller; + +import com.hjjang.backend.domain.image.domain.entity.Image; +import com.hjjang.backend.domain.image.dto.ImagePathResponse; +import com.hjjang.backend.domain.image.service.LocalImageService; +import com.hjjang.backend.domain.image.service.S3ImageService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; + +import static com.hjjang.backend.global.util.HttpStatusResponseEntity.RESPONSE_OK; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/images") +public class ImageController { + + private final LocalImageService imageService; + + @GetMapping() + public ResponseEntity> findAllImage() { + return ResponseEntity.ok(imageService + .findAll() + .stream() + .map(ImagePathResponse::of) + .collect(Collectors.toList()) + ); + } + + @PostMapping() + public ResponseEntity uploadImage(@RequestParam("images") MultipartFile multipartFile) throws IOException { + return ResponseEntity.ok(ImagePathResponse + .of(imageService + .uploadNewImage(multipartFile) + ) + ); + } + + @GetMapping("/{imageId}") + public ResponseEntity findImage(@PathVariable Long imageId) { + return ResponseEntity.ok(ImagePathResponse + .of(imageService + .findImageById(imageId) + ) + ); + } + + @DeleteMapping("/{imageId}") + public ResponseEntity deleteIMage(@PathVariable Long imageId) { + Image image = imageService.findImageById(imageId); + imageService.removeImage(image); + + return RESPONSE_OK; + } +} diff --git a/backend/src/main/java/com/hjjang/backend/infra/image/domain/entity/Image.java b/backend/src/main/java/com/hjjang/backend/domain/image/domain/entity/Image.java similarity index 89% rename from backend/src/main/java/com/hjjang/backend/infra/image/domain/entity/Image.java rename to backend/src/main/java/com/hjjang/backend/domain/image/domain/entity/Image.java index cbd9e07..9353979 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/image/domain/entity/Image.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/domain/entity/Image.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.infra.image.domain.entity; +package com.hjjang.backend.domain.image.domain.entity; import lombok.*; diff --git a/backend/src/main/java/com/hjjang/backend/infra/image/domain/repository/ImageRepository.java b/backend/src/main/java/com/hjjang/backend/domain/image/domain/repository/ImageRepository.java similarity index 53% rename from backend/src/main/java/com/hjjang/backend/infra/image/domain/repository/ImageRepository.java rename to backend/src/main/java/com/hjjang/backend/domain/image/domain/repository/ImageRepository.java index a3fb42e..396cc23 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/image/domain/repository/ImageRepository.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/domain/repository/ImageRepository.java @@ -1,6 +1,6 @@ -package com.hjjang.backend.infra.image.domain.repository; +package com.hjjang.backend.domain.image.domain.repository; -import com.hjjang.backend.infra.image.domain.entity.Image; +import com.hjjang.backend.domain.image.domain.entity.Image; import org.springframework.data.jpa.repository.JpaRepository; public interface ImageRepository extends JpaRepository { diff --git a/backend/src/main/java/com/hjjang/backend/infra/image/dto/ImageDto.java b/backend/src/main/java/com/hjjang/backend/domain/image/dto/ImageDto.java similarity index 78% rename from backend/src/main/java/com/hjjang/backend/infra/image/dto/ImageDto.java rename to backend/src/main/java/com/hjjang/backend/domain/image/dto/ImageDto.java index 5caad3a..d0808e4 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/image/dto/ImageDto.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/dto/ImageDto.java @@ -1,7 +1,7 @@ -package com.hjjang.backend.infra.image.dto; +package com.hjjang.backend.domain.image.dto; -import com.hjjang.backend.infra.image.domain.entity.Image; +import com.hjjang.backend.domain.image.domain.entity.Image; import lombok.*; import javax.validation.constraints.NotEmpty; diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/dto/ImagePathResponse.java b/backend/src/main/java/com/hjjang/backend/domain/image/dto/ImagePathResponse.java new file mode 100644 index 0000000..68c723b --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/image/dto/ImagePathResponse.java @@ -0,0 +1,20 @@ +package com.hjjang.backend.domain.image.dto; + +import com.hjjang.backend.domain.image.domain.entity.Image; +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +public class ImagePathResponse { + + private Long id; + private String path; + + public static ImagePathResponse of(Image image) { + return ImagePathResponse.builder() + .id(image.getId()) + .path(image.getPath()) + .build(); + } +} diff --git a/backend/src/main/java/com/hjjang/backend/infra/image/exception/ImageNotFoundException.java b/backend/src/main/java/com/hjjang/backend/domain/image/exception/ImageNotFoundException.java similarity index 86% rename from backend/src/main/java/com/hjjang/backend/infra/image/exception/ImageNotFoundException.java rename to backend/src/main/java/com/hjjang/backend/domain/image/exception/ImageNotFoundException.java index 6b169c0..70dcd99 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/image/exception/ImageNotFoundException.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/exception/ImageNotFoundException.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.infra.image.exception; +package com.hjjang.backend.domain.image.exception; public class ImageNotFoundException extends RuntimeException { diff --git a/backend/src/main/java/com/hjjang/backend/infra/image/service/ImageService.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java similarity index 53% rename from backend/src/main/java/com/hjjang/backend/infra/image/service/ImageService.java rename to backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java index 4313d65..58a78aa 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/image/service/ImageService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java @@ -1,6 +1,6 @@ -package com.hjjang.backend.infra.image.service; +package com.hjjang.backend.domain.image.service; -import com.hjjang.backend.infra.image.domain.entity.Image; +import com.hjjang.backend.domain.image.domain.entity.Image; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; @@ -12,9 +12,8 @@ public interface ImageService { Image findImageById(Long imageId); - void uploadNewImage(MultipartFile multipartFile) throws IOException; + Image uploadNewImage(MultipartFile multipartFile) throws IOException; void removeImage(Image image); - boolean isImageInPath(Image image); } diff --git a/backend/src/main/java/com/hjjang/backend/infra/image/service/ImageServiceImpl.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageService.java similarity index 51% rename from backend/src/main/java/com/hjjang/backend/infra/image/service/ImageServiceImpl.java rename to backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageService.java index 243a11b..a732372 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/image/service/ImageServiceImpl.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageService.java @@ -1,10 +1,10 @@ -package com.hjjang.backend.infra.image.service; +package com.hjjang.backend.domain.image.service; -import com.hjjang.backend.infra.image.component.ImageUploader; -import com.hjjang.backend.infra.image.domain.entity.Image; -import com.hjjang.backend.infra.image.domain.repository.ImageRepository; -import com.hjjang.backend.infra.image.dto.ImageDto; -import com.hjjang.backend.infra.image.exception.ImageNotFoundException; +import com.hjjang.backend.domain.image.domain.repository.ImageRepository; +import com.hjjang.backend.domain.image.dto.ImageDto; +import com.hjjang.backend.domain.image.domain.entity.Image; +import com.hjjang.backend.domain.image.exception.ImageNotFoundException; +import com.hjjang.backend.infra.uploader.component.LocalUploader; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -16,9 +16,9 @@ @Service @RequiredArgsConstructor @Transactional -public class ImageServiceImpl implements ImageService{ +public class LocalImageService implements ImageService{ private final ImageRepository imageRepository; - private final ImageUploader imageUploader; + private final LocalUploader imageUploader; @Override public List findAll() { @@ -31,9 +31,9 @@ public Image findImageById(Long imageId) { } @Override - public void uploadNewImage(MultipartFile multipartFile) throws IOException { + public Image uploadNewImage(MultipartFile multipartFile) throws IOException { ImageDto imageDto = new ImageDto(imageUploader.upload(multipartFile)); - imageRepository.save(imageDto.toEntity()); + return imageRepository.save(imageDto.toEntity()); } @Override @@ -42,9 +42,4 @@ public void removeImage(Image image) { imageRepository.save(image); } - @Override - public boolean isImageInPath(Image image) { - //TODO: 이미지가 경로에 존재하는지 확인하는 코드 작성 - return false; - } } diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/service/S3ImageService.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/S3ImageService.java new file mode 100644 index 0000000..a77607f --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/image/service/S3ImageService.java @@ -0,0 +1,44 @@ +package com.hjjang.backend.domain.image.service; + +import com.hjjang.backend.domain.image.domain.entity.Image; +import com.hjjang.backend.domain.image.domain.repository.ImageRepository; +import com.hjjang.backend.domain.image.exception.ImageNotFoundException; +import com.hjjang.backend.infra.uploader.component.S3Uploader; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.transaction.Transactional; +import java.io.IOException; +import java.util.List; + +@Service +@RequiredArgsConstructor +@Transactional +public class S3ImageService implements ImageService { + private final ImageRepository imageRepository; + private final S3Uploader imageUploader; + + @Override + public List findAll() { + return imageRepository.findAll(); + } + + @Override + public Image findImageById(Long imageId) { + return imageRepository.findById(imageId).orElseThrow(ImageNotFoundException::new); + } + + @Override + public Image uploadNewImage(MultipartFile multipartFile) throws IOException { + return imageRepository.save( + new Image(imageUploader.upload(multipartFile)) + ); + } + + @Override + public void removeImage(Image image) { + image.removeImage(); + imageRepository.save(image); + } +} diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java index 616e4f8..ef5553b 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java @@ -1,7 +1,5 @@ package com.hjjang.backend.domain.post.domain.entity; -import com.hjjang.backend.domain.user.entity.User; -import com.hjjang.backend.infra.image.domain.entity.Image; import lombok.*; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.DynamicInsert; diff --git a/backend/src/main/java/com/hjjang/backend/infra/aws/controller/S3Controller.java b/backend/src/main/java/com/hjjang/backend/infra/aws/controller/S3Controller.java deleted file mode 100644 index cd8b1f5..0000000 --- a/backend/src/main/java/com/hjjang/backend/infra/aws/controller/S3Controller.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.hjjang.backend.infra.aws.controller; - -import com.hjjang.backend.infra.aws.component.S3Uploader; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; - -@RequiredArgsConstructor -@RequestMapping("/api/images") -@RestController -public class S3Controller { - - private final S3Uploader s3Uploader; - - //TODO: 이미지가 일정 용량 이상일 경우 업로드가 안되는데, 그 과정에서 이미지가 로컬에 저장은 되고 방치됌 -> 동일 파일 이름으로 이미지 업로드시 오류 유발 - @PostMapping - public String upload(@RequestParam("images") MultipartFile multipartFile) throws IOException { - s3Uploader.upload(multipartFile, "static"); - return "test"; - } -} diff --git a/backend/src/main/java/com/hjjang/backend/infra/image/controller/ImageController.java b/backend/src/main/java/com/hjjang/backend/infra/image/controller/ImageController.java deleted file mode 100644 index f920983..0000000 --- a/backend/src/main/java/com/hjjang/backend/infra/image/controller/ImageController.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.hjjang.backend.infra.image.controller; - -import com.hjjang.backend.infra.image.domain.entity.Image; -import com.hjjang.backend.infra.image.dto.ImageResponse; -import com.hjjang.backend.infra.image.service.ImageService; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; -import java.util.List; - -import static com.hjjang.backend.global.util.HttpStatusResponseEntity.RESPONSE_OK; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/images") -public class ImageController { - - private final ImageService imageService; - - @GetMapping() - public List findAllImage() { - return imageService.findAll(); - } - - @PostMapping() - public ResponseEntity uploadImage(@RequestParam("images") MultipartFile multipartFile) throws IOException { - imageService.uploadNewImage(multipartFile); - return RESPONSE_OK; - } - - @GetMapping("/{imageId}") - public ResponseEntity findImage(@PathVariable Long imageId) { - return ResponseEntity.ok(ImageResponse.of(imageService.findImageById(imageId))); - } - - @DeleteMapping("/{imageId}") - public ResponseEntity deleteIMage(@PathVariable Long imageId) { - Image image = imageService.findImageById(imageId); - imageService.removeImage(image); - - return RESPONSE_OK; - } -} diff --git a/backend/src/main/java/com/hjjang/backend/infra/image/dto/ImageResponse.java b/backend/src/main/java/com/hjjang/backend/infra/image/dto/ImageResponse.java deleted file mode 100644 index 58e613a..0000000 --- a/backend/src/main/java/com/hjjang/backend/infra/image/dto/ImageResponse.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.hjjang.backend.infra.image.dto; - -import com.hjjang.backend.infra.image.domain.entity.Image; -import lombok.Builder; -import lombok.Getter; - -@Builder -@Getter -public class ImageResponse { - - private Long id; - private String path; - - public static ImageResponse of(Image image) { - return ImageResponse.builder() - .id(image.getId()) - .path(image.getPath()) - .build(); - } -} diff --git a/backend/src/main/java/com/hjjang/backend/infra/image/component/ImageUploader.java b/backend/src/main/java/com/hjjang/backend/infra/uploader/component/ImageUploader.java similarity index 87% rename from backend/src/main/java/com/hjjang/backend/infra/image/component/ImageUploader.java rename to backend/src/main/java/com/hjjang/backend/infra/uploader/component/ImageUploader.java index 08fcce5..2588416 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/image/component/ImageUploader.java +++ b/backend/src/main/java/com/hjjang/backend/infra/uploader/component/ImageUploader.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.infra.image.component; +package com.hjjang.backend.infra.uploader.component; import org.springframework.web.multipart.MultipartFile; diff --git a/backend/src/main/java/com/hjjang/backend/infra/image/component/LocalUploader.java b/backend/src/main/java/com/hjjang/backend/infra/uploader/component/LocalUploader.java similarity index 84% rename from backend/src/main/java/com/hjjang/backend/infra/image/component/LocalUploader.java rename to backend/src/main/java/com/hjjang/backend/infra/uploader/component/LocalUploader.java index f0d96d7..1374456 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/image/component/LocalUploader.java +++ b/backend/src/main/java/com/hjjang/backend/infra/uploader/component/LocalUploader.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.infra.image.component; +package com.hjjang.backend.infra.uploader.component; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -27,13 +27,13 @@ public String upload(MultipartFile multipartFile) throws IOException { @Override public String changeFileName(MultipartFile uploadFile) { - return UUID.randomUUID() + uploadFile.getOriginalFilename(); // 저장될 파일 이름 변환 + return UUID.randomUUID() + ".png"; // 저장될 파일 이름 변환 } // 로컬에 파일 업로드 하기 @Override public Optional localUpload(MultipartFile file) throws IOException { - File convertFile = new File(System.getProperty("user.dir") + "/backend/src/main/resources/images/" + changeFileName(file)); + File convertFile = new File(Path.imageSavePath.getPath() + changeFileName(file)); if (convertFile.createNewFile()) { // 바로 위에서 지정한 경로에 File이 생성됨 (경로가 잘못되었다면 생성 불가능) try (FileOutputStream fos = new FileOutputStream(convertFile)) { // FileOutputStream 데이터를 파일에 바이트 스트림으로 저장하기 위함 @@ -41,7 +41,6 @@ public Optional localUpload(MultipartFile file) throws IOException { } return Optional.of(convertFile); } - return Optional.empty(); } diff --git a/backend/src/main/java/com/hjjang/backend/infra/uploader/component/Path.java b/backend/src/main/java/com/hjjang/backend/infra/uploader/component/Path.java new file mode 100644 index 0000000..75e3afe --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/infra/uploader/component/Path.java @@ -0,0 +1,14 @@ +package com.hjjang.backend.infra.uploader.component; + +import lombok.Getter; + +@Getter +public enum Path { + imageSavePath(System.getProperty("user.dir") + "/backend/src/main/resources/images/"); + + private final String path; + Path(String path) { + this.path = path; + } + +} diff --git a/backend/src/main/java/com/hjjang/backend/infra/aws/component/S3Uploader.java b/backend/src/main/java/com/hjjang/backend/infra/uploader/component/S3Uploader.java similarity index 72% rename from backend/src/main/java/com/hjjang/backend/infra/aws/component/S3Uploader.java rename to backend/src/main/java/com/hjjang/backend/infra/uploader/component/S3Uploader.java index edfe046..c0c2dd3 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/aws/component/S3Uploader.java +++ b/backend/src/main/java/com/hjjang/backend/infra/uploader/component/S3Uploader.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.infra.aws.component; +package com.hjjang.backend.infra.uploader.component; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.CannedAccessControlList; @@ -18,26 +18,31 @@ @Slf4j @RequiredArgsConstructor @Component -public class S3Uploader { +public class S3Uploader implements ImageUploader { private final AmazonS3Client amazonS3Client; @Value("${cloud.aws.s3.bucket}") public String bucket; // S3 버킷 이름 - public String upload(MultipartFile multipartFile, String dirName) throws IOException { + @Override + public String upload(MultipartFile multipartFile) throws IOException { File uploadFile = - convert(multipartFile) // 파일 변환할 수 없으면 에러 + this.localUpload(multipartFile) // 파일 변환할 수 없으면 에러 .orElseThrow( () -> new IllegalArgumentException("error: MultipartFile -> File convert fail")); - return upload(uploadFile, dirName); + return upload(uploadFile); + } + + @Override + public String changeFileName(MultipartFile uploadFile) { + return UUID.randomUUID() + ".png"; // 저장될 파일 이름 변환 } // S3로 파일 업로드하기 - private String upload(File uploadFile, String dirName) { - String fileName = dirName + "/" + UUID.randomUUID() + uploadFile.getName(); // S3에 저장된 파일 이름 - String uploadImageUrl = putS3(uploadFile, fileName); // s3로 업로드 + private String upload(File uploadFile) { + String uploadImageUrl = putS3(uploadFile, "static/" + uploadFile.getName()); // s3로 업로드 removeNewFile(uploadFile); return uploadImageUrl; } @@ -60,8 +65,9 @@ private void removeNewFile(File targetFile) { } // 로컬에 파일 업로드 하기 - private Optional convert(MultipartFile file) throws IOException { - File convertFile = new File(System.getProperty("user.dir") + "/" + file.getOriginalFilename()); + @Override + public Optional localUpload(MultipartFile file) throws IOException { + File convertFile = new File(Path.imageSavePath.getPath() + changeFileName(file)); if (convertFile.createNewFile()) { // 바로 위에서 지정한 경로에 File이 생성됨 (경로가 잘못되었다면 생성 불가능) try (FileOutputStream fos = new FileOutputStream(convertFile)) { // FileOutputStream 데이터를 파일에 바이트 스트림으로 저장하기 위함 From ce6e87bfd66f7f875b6be88e65a9d84f4a393480 Mon Sep 17 00:00:00 2001 From: 0BVer Date: Sat, 30 Apr 2022 15:41:43 +0900 Subject: [PATCH 30/46] chore : change max filesize to 50mb --- backend/src/main/resources/application.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 34b32a3..6fe52ac 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -64,6 +64,12 @@ spring: tokenUri: https://kauth.kakao.com/oauth/token userInfoUri: https://kapi.kakao.com/v2/user/me userNameAttribute: id + + servlet: + multipart: + max-file-size: 50MB + max-request-size: 50MB + auth: tokenProperties: tokenSecretKey: asodfhwoeihro1i34u1097r09u13rqfasc12 From 61a59e7be7fc8ca5958e70b1a4e7cbed6d96582d Mon Sep 17 00:00:00 2001 From: Young-Jun Kim Date: Sat, 30 Apr 2022 18:31:48 +0900 Subject: [PATCH 31/46] Update backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java Co-authored-by: Yunkeun <70425484+Yunkeun@users.noreply.github.com> --- .../hjjang/backend/domain/image/controller/ImageController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java b/backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java index fee4454..ec58cdc 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java @@ -52,7 +52,7 @@ public ResponseEntity findImage(@PathVariable Long imageId) { } @DeleteMapping("/{imageId}") - public ResponseEntity deleteIMage(@PathVariable Long imageId) { + public ResponseEntity deleteImage(@PathVariable Long imageId) { Image image = imageService.findImageById(imageId); imageService.removeImage(image); From b3ef9bd5b16215af3d8544739712deb4c68e85dd Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 30 Apr 2022 20:36:01 +0900 Subject: [PATCH 32/46] fix: add user sequence at user table and alter userid to providerId --- .../user/controller/UserAuthController.java | 32 +++---- .../backend/domain/user/entity/User.java | 13 ++- .../domain/user/entity/UserRefreshToken.java | 29 +++--- .../UserRefreshTokenRepository.java | 7 +- .../user/repository/UserRepository.java | 11 ++- .../user/service/UserProfileService.java | 2 +- .../OAuth2AuthenticationSuccessHandler.java | 91 +++++++++---------- .../security/principal/UserPrincipal.java | 22 ++--- .../service/CustomOAuth2UserService.java | 24 +++-- .../hjjang/backend/global/util/UserUtil.java | 23 +++-- 10 files changed, 122 insertions(+), 132 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java index 9f65a60..1cc3f30 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java @@ -1,15 +1,5 @@ package com.hjjang.backend.domain.user.controller; -import java.util.Date; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.entity.UserRefreshToken; import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; @@ -20,9 +10,16 @@ import com.hjjang.backend.global.dto.ApiResponse; import com.hjjang.backend.global.util.CookieUtil; import com.hjjang.backend.global.util.HeaderUtil; - import io.jsonwebtoken.Claims; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Date; @RestController @RequestMapping("/api/v1/auth") @@ -34,8 +31,8 @@ public class UserAuthController { private final UserRefreshTokenRepository userRefreshTokenRepository; private final UserAuthService userAuthService; - private final static long THREE_DAYS_MSEC = 259200000; - private final static String REFRESH_TOKEN = "refresh_token"; + private static final long THREE_DAYS_MSEC = 259200000; + private static final String REFRESH_TOKEN = "refresh_token"; @GetMapping("/refresh") public ApiResponse refreshToken(HttpServletRequest request, HttpServletResponse response) { @@ -51,8 +48,7 @@ public ApiResponse refreshToken(HttpServletRequest request, HttpServletResponse if (claims == null) { return ApiResponse.notExpiredTokenYet(); } - - String userId = claims.getSubject(); + String providerId = claims.getSubject(); RoleType roleType = RoleType.of(claims.get("role", String.class)); // refresh token @@ -65,8 +61,8 @@ public ApiResponse refreshToken(HttpServletRequest request, HttpServletResponse return ApiResponse.invalidRefreshToken(); } - // userId, refresh token 으로 DB 확인 - UserRefreshToken userRefreshToken = userRefreshTokenRepository.findByUserIdAndRefreshToken(userId, + // providerId, refresh token 으로 DB 확인 + UserRefreshToken userRefreshToken = userRefreshTokenRepository.findByProviderIdAndRefreshToken(providerId, refreshToken); if (userRefreshToken == null) { return ApiResponse.invalidRefreshToken(); @@ -74,7 +70,7 @@ public ApiResponse refreshToken(HttpServletRequest request, HttpServletResponse Date now = new Date(); AuthToken newAccessToken = tokenProvider.createAuthToken( - userId, roleType.getCode(), + providerId, roleType.getCode(), new Date(now.getTime() + authProperties.getTokenProperties().getTokenExpireDate()) ); userAuthService.reissueRefreshTokenIfValidTimeleft3days(request, response, userRefreshToken, authRefreshToken, diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java index 04992b1..9b2af8d 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java @@ -11,6 +11,7 @@ import java.time.LocalDateTime; import static javax.persistence.EnumType.STRING; +import static javax.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; @Getter @@ -22,8 +23,12 @@ public class User { @Id - @Column(name = "id", nullable = false, length = 128) - private String id; + @GeneratedValue(strategy = IDENTITY) + @Column(name = "id", nullable = false) + private Long id; + + @Column(name = "provider_id", nullable = false, length = 128) + private String providerId; @Column(name = "nickname", nullable = false, length = 30) private String nickName; @@ -53,8 +58,8 @@ public class User { private RoleType role; @Builder - public User(String id, String nickName, String email, Long mannerTemperature, String imageUrl, Agreement isPushAgree, Long univId, RoleType role) { - this.id = id; + public User(String providerId, String nickName, String email, Long mannerTemperature, String imageUrl, Agreement isPushAgree, Long univId, RoleType role) { + this.providerId = providerId; this.nickName = nickName; this.email = email; this.mannerTemperature = mannerTemperature; diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/UserRefreshToken.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/UserRefreshToken.java index e6cd071..77d98e4 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/entity/UserRefreshToken.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/UserRefreshToken.java @@ -1,22 +1,15 @@ package com.hjjang.backend.domain.user.entity; -import static javax.persistence.GenerationType.*; -import static lombok.AccessLevel.*; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import com.sun.istack.NotNull; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.NoArgsConstructor; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; + +import static javax.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; @AllArgsConstructor @EntityListeners(AuditingEntityListener.class) @@ -29,16 +22,16 @@ public class UserRefreshToken { @Column(name = "id", nullable = false) private Long id; - @Column(name = "user_id", nullable = false, length = 64) - private String userId; + @Column(name = "provider_id", nullable = false, length = 64) + private String providerId; @Column(name = "refresh_token", nullable = false, length = 256) @NotNull private String refreshToken; @Builder - public UserRefreshToken(String userId, String refreshToken) { - this.userId = userId; + public UserRefreshToken(String providerId, String refreshToken) { + this.providerId = providerId; this.refreshToken = refreshToken; } diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRefreshTokenRepository.java b/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRefreshTokenRepository.java index fbbb4e5..81bef94 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRefreshTokenRepository.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRefreshTokenRepository.java @@ -3,8 +3,9 @@ import com.hjjang.backend.domain.user.entity.UserRefreshToken; import org.springframework.data.jpa.repository.JpaRepository; -public interface UserRefreshTokenRepository extends JpaRepository { - UserRefreshToken findByUserId(String userId); - UserRefreshToken findByUserIdAndRefreshToken(String userId, String refreshToken); +public interface UserRefreshTokenRepository extends JpaRepository { + UserRefreshToken findByProviderId(String providerId); + + UserRefreshToken findByProviderIdAndRefreshToken(String providerId, String refreshToken); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRepository.java b/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRepository.java index c2b3385..c11a5ad 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRepository.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/repository/UserRepository.java @@ -1,11 +1,12 @@ package com.hjjang.backend.domain.user.repository; -import java.util.Optional; - +import com.hjjang.backend.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; -import com.hjjang.backend.domain.user.entity.User; +import java.util.Optional; + +public interface UserRepository extends JpaRepository { + Optional findUserById(Long id); -public interface UserRepository extends JpaRepository { - Optional findUserById(String id); + Optional findUserByProviderId(String providerId); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java index 6aa89c9..0a809fe 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java @@ -20,7 +20,7 @@ public UserProfileDTO getUserProfile() { String userId = UserUtil.getLoginUserIdByToken(); //todo add exception - User user = userRepository.findUserById(userId).orElseThrow(EntityNotFoundException::new); + User user = userRepository.findUserByProviderId(userId).orElseThrow(EntityNotFoundException::new); //todo found univName logic return UserProfileDTO.builder() diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationSuccessHandler.java b/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationSuccessHandler.java index 1601a03..2ae9bdf 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationSuccessHandler.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationSuccessHandler.java @@ -1,26 +1,5 @@ package com.hjjang.backend.global.config.security.handler; -import static com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.*; - -import java.io.IOException; -import java.net.URI; -import java.util.Collection; -import java.util.Date; -import java.util.Optional; - -import javax.servlet.ServletException; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; -import org.springframework.security.oauth2.core.oidc.user.OidcUser; -import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; -import org.springframework.stereotype.Component; -import org.springframework.web.util.UriComponentsBuilder; - import com.hjjang.backend.domain.user.entity.ProviderType; import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.entity.UserRefreshToken; @@ -32,8 +11,27 @@ import com.hjjang.backend.global.config.security.token.AuthToken; import com.hjjang.backend.global.config.security.token.AuthTokenProvider; import com.hjjang.backend.global.util.CookieUtil; - import lombok.RequiredArgsConstructor; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; +import org.springframework.security.oauth2.core.oidc.user.OidcUser; +import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; +import org.springframework.stereotype.Component; +import org.springframework.web.util.UriComponentsBuilder; + +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URI; +import java.util.Collection; +import java.util.Date; +import java.util.Optional; + +import static com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.REDIRECT_URI_PARAM_COOKIE_NAME; +import static com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.REFRESH_TOKEN; @Component @RequiredArgsConstructor @@ -46,7 +44,7 @@ public class OAuth2AuthenticationSuccessHandler extends SimpleUrlAuthenticationS @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, - Authentication authentication) throws IOException, ServletException { + Authentication authentication) throws IOException, ServletException { String targetUrl = determineTargetUrl(request, response, authentication); if (response.isCommitted()) { @@ -58,45 +56,46 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo getRedirectStrategy().sendRedirect(request, response, targetUrl); } + @Override protected String determineTargetUrl(HttpServletRequest request, HttpServletResponse response, - Authentication authentication) { + Authentication authentication) { Optional redirectUri = CookieUtil.getCookie(request, REDIRECT_URI_PARAM_COOKIE_NAME) - .map(Cookie::getValue); + .map(Cookie::getValue); if (redirectUri.isPresent() && !isAuthorizedRedirectUri(redirectUri.get())) { throw new IllegalArgumentException( - "Sorry! We've got an Unauthorized Redirect URI and can't proceed with the authentication"); + "Sorry! We've got an Unauthorized Redirect URI and can't proceed with the authentication"); } String targetUrl = redirectUri.orElse(getDefaultTargetUrl()); - OAuth2AuthenticationToken authToken = (OAuth2AuthenticationToken)authentication; + OAuth2AuthenticationToken authToken = (OAuth2AuthenticationToken) authentication; ProviderType providerType = ProviderType.valueOf(authToken.getAuthorizedClientRegistrationId().toUpperCase()); - OidcUser user = ((OidcUser)authentication.getPrincipal()); + OidcUser user = ((OidcUser) authentication.getPrincipal()); ParsingUserContext userInfo = ParsingUserContextFactory.getParsingParsingUserContext(providerType, - user.getAttributes()); - Collection authorities = ((OidcUser)authentication.getPrincipal()).getAuthorities(); + user.getAttributes()); + Collection authorities = ((OidcUser) authentication.getPrincipal()).getAuthorities(); RoleType userRole = hasAuthority(authorities, RoleType.ADMIN.getCode()) ? RoleType.ADMIN : RoleType.USER; Date now = new Date(); AuthToken accessToken = tokenProvider.createAuthToken( - userInfo.getId(), - userRole.getCode(), - new Date(now.getTime() + authProperties.getTokenProperties().getTokenExpireDate()) + userInfo.getId(), + userRole.getCode(), + new Date(now.getTime() + authProperties.getTokenProperties().getTokenExpireDate()) ); // refresh 토큰 설정 long refreshTokenExpiry = authProperties.getTokenProperties().getRefreshTokenExpiry(); AuthToken refreshToken = tokenProvider.createAuthToken( - authProperties.getTokenProperties().getTokenSecretKey(), - new Date(now.getTime() + refreshTokenExpiry) + authProperties.getTokenProperties().getTokenSecretKey(), + new Date(now.getTime() + refreshTokenExpiry) ); // DB 저장 - UserRefreshToken userRefreshToken = userRefreshTokenRepository.findByUserId(userInfo.getId()); + UserRefreshToken userRefreshToken = userRefreshTokenRepository.findByProviderId(userInfo.getId()); if (userRefreshToken != null) { userRefreshToken.reissueRefreshToken(refreshToken.getToken()); } else { @@ -104,14 +103,14 @@ protected String determineTargetUrl(HttpServletRequest request, HttpServletRespo userRefreshTokenRepository.saveAndFlush(userRefreshToken); } - int cookieMaxAge = (int)refreshTokenExpiry / 60; + int cookieMaxAge = (int) refreshTokenExpiry / 60; CookieUtil.deleteCookie(request, response, REFRESH_TOKEN); CookieUtil.addCookie(response, REFRESH_TOKEN, refreshToken.getToken(), cookieMaxAge); return UriComponentsBuilder.fromUriString(targetUrl) - .queryParam("token", accessToken.getToken()) - .build().toUriString(); + .queryParam("token", accessToken.getToken()) + .build().toUriString(); } protected void clearAuthenticationAttributes(HttpServletRequest request, HttpServletResponse response) { @@ -136,12 +135,12 @@ private boolean isAuthorizedRedirectUri(String uri) { URI clientRedirectUri = URI.create(uri); return authProperties.getOAuth2Properties().getRedirectUris() - .stream() - .anyMatch(authorizedRedirectUri -> { - // Only validate host and port. Let the clients use different paths if they want to - URI authorizedURI = URI.create(authorizedRedirectUri); - return authorizedURI.getHost().equalsIgnoreCase(clientRedirectUri.getHost()) - && authorizedURI.getPort() == clientRedirectUri.getPort(); - }); + .stream() + .anyMatch(authorizedRedirectUri -> { + // Only validate host and port. Let the clients use different paths if they want to + URI authorizedURI = URI.create(authorizedRedirectUri); + return authorizedURI.getHost().equalsIgnoreCase(clientRedirectUri.getHost()) + && authorizedURI.getPort() == clientRedirectUri.getPort(); + }); } } diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/principal/UserPrincipal.java b/backend/src/main/java/com/hjjang/backend/global/config/security/principal/UserPrincipal.java index e90fe3d..cbae845 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/principal/UserPrincipal.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/principal/UserPrincipal.java @@ -1,9 +1,11 @@ package com.hjjang.backend.global.config.security.principal; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - +import com.hjjang.backend.domain.user.entity.RoleType; +import com.hjjang.backend.domain.user.entity.User; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; @@ -12,13 +14,9 @@ import org.springframework.security.oauth2.core.oidc.user.OidcUser; import org.springframework.security.oauth2.core.user.OAuth2User; -import com.hjjang.backend.domain.user.entity.RoleType; -import com.hjjang.backend.domain.user.entity.User; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; @Getter @AllArgsConstructor @@ -93,7 +91,7 @@ public OidcIdToken getIdToken() { public static UserPrincipal create(User user) { return new UserPrincipal( - user.getId(), + user.getProviderId(), RoleType.USER, Collections.singletonList(new SimpleGrantedAuthority(RoleType.USER.getCode()) )); diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java b/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java index ee65f52..1224372 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java @@ -1,15 +1,5 @@ package com.hjjang.backend.global.config.security.service; -import java.util.Optional; - -import org.springframework.security.authentication.InternalAuthenticationServiceException; -import org.springframework.security.core.AuthenticationException; -import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService; -import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest; -import org.springframework.security.oauth2.core.OAuth2AuthenticationException; -import org.springframework.security.oauth2.core.user.OAuth2User; -import org.springframework.stereotype.Service; - import com.hjjang.backend.domain.user.entity.Agreement; import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.entity.User; @@ -17,8 +7,16 @@ import com.hjjang.backend.global.config.security.parser.KakaoParsingParsingUserContext; import com.hjjang.backend.global.config.security.parser.ParsingUserContext; import com.hjjang.backend.global.config.security.principal.UserPrincipal; - import lombok.RequiredArgsConstructor; +import org.springframework.security.authentication.InternalAuthenticationServiceException; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService; +import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest; +import org.springframework.security.oauth2.core.OAuth2AuthenticationException; +import org.springframework.security.oauth2.core.user.OAuth2User; +import org.springframework.stereotype.Service; + +import java.util.Optional; @Service @RequiredArgsConstructor @@ -42,7 +40,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic private OAuth2User process(OAuth2UserRequest userRequest, OAuth2User user) { ParsingUserContext userInfo = new KakaoParsingParsingUserContext(user.getAttributes()); - Optional optionalSavedUser = userRepository.findUserById(userInfo.getId()); + Optional optionalSavedUser = userRepository.findUserByProviderId(userInfo.getId()); User savedUser = null; if (optionalSavedUser.isPresent()) { savedUser = optionalSavedUser.get(); @@ -57,7 +55,7 @@ private OAuth2User process(OAuth2UserRequest userRequest, OAuth2User user) { private User createUser(ParsingUserContext userInfo) { User user = User.builder() - .id(userInfo.getId()) + .providerId(userInfo.getId()) .nickName(userInfo.getName()) .email(userInfo.getEmail()) .isPushAgree(Agreement.DISAGREE) diff --git a/backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java b/backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java index 9e7db45..e7af44f 100644 --- a/backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java +++ b/backend/src/main/java/com/hjjang/backend/global/util/UserUtil.java @@ -1,14 +1,12 @@ package com.hjjang.backend.global.util; -import javax.persistence.EntityNotFoundException; - +import com.hjjang.backend.domain.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.User; import org.springframework.stereotype.Component; -import com.hjjang.backend.domain.user.repository.UserRepository; - -import lombok.RequiredArgsConstructor; +import javax.persistence.EntityNotFoundException; @Component @RequiredArgsConstructor @@ -17,17 +15,18 @@ public class UserUtil { private final UserRepository userRepository; public static String getLoginUserIdByToken() { - User principal = (User)SecurityContextHolder.getContext() - .getAuthentication() - .getPrincipal(); + User principal = (User) SecurityContextHolder.getContext() + .getAuthentication() + .getPrincipal(); + return principal.getUsername(); } public com.hjjang.backend.domain.user.entity.User getLoginUserByToken() { - User principal = (User)SecurityContextHolder.getContext() - .getAuthentication() - .getPrincipal(); - return userRepository.findById(principal.getUsername()).orElseThrow(EntityNotFoundException::new); + User principal = (User) SecurityContextHolder.getContext() + .getAuthentication() + .getPrincipal(); + return userRepository.findUserByProviderId(principal.getUsername()).orElseThrow(EntityNotFoundException::new); } } From f7fc1e38b838b80b0cb82273351eafc715bfea97 Mon Sep 17 00:00:00 2001 From: 0BVer Date: Sat, 30 Apr 2022 22:46:39 +0900 Subject: [PATCH 33/46] =?UTF-8?q?chore=20:=20(PR=20=EC=9D=B4=EC=8A=88=20?= =?UTF-8?q?=EB=B0=98=EC=98=81)=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=8D=94=20=EC=BD=94=EB=93=9C=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0,=20=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD,=20=EB=A1=9C=EC=BB=AC=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=8D=94=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../image/controller/ImageController.java | 5 +-- .../backend/domain/image/dto/ImageDto.java | 23 ---------- .../domain/image/service/ImageService.java | 32 ++++++++++--- .../image/service/ImageUploader.java} | 11 ++--- .../image/service/LocalImageService.java | 45 ------------------- .../image/service/LocalImageUploader.java | 10 +++++ .../image/service}/Path.java | 2 +- .../domain/image/service/S3ImageService.java | 44 ------------------ .../service/S3ImageUploader.java} | 32 +++---------- .../uploader/component/ImageUploader.java | 16 ------- 10 files changed, 49 insertions(+), 171 deletions(-) delete mode 100644 backend/src/main/java/com/hjjang/backend/domain/image/dto/ImageDto.java rename backend/src/main/java/com/hjjang/backend/{infra/uploader/component/LocalUploader.java => domain/image/service/ImageUploader.java} (88%) delete mode 100644 backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageService.java create mode 100644 backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageUploader.java rename backend/src/main/java/com/hjjang/backend/{infra/uploader/component => domain/image/service}/Path.java (81%) delete mode 100644 backend/src/main/java/com/hjjang/backend/domain/image/service/S3ImageService.java rename backend/src/main/java/com/hjjang/backend/infra/{uploader/component/S3Uploader.java => aws/service/S3ImageUploader.java} (61%) delete mode 100644 backend/src/main/java/com/hjjang/backend/infra/uploader/component/ImageUploader.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java b/backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java index fee4454..29a4c29 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java @@ -2,8 +2,7 @@ import com.hjjang.backend.domain.image.domain.entity.Image; import com.hjjang.backend.domain.image.dto.ImagePathResponse; -import com.hjjang.backend.domain.image.service.LocalImageService; -import com.hjjang.backend.domain.image.service.S3ImageService; +import com.hjjang.backend.domain.image.service.ImageService; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -21,7 +20,7 @@ @RequestMapping("/api/images") public class ImageController { - private final LocalImageService imageService; + private final ImageService imageService; @GetMapping() public ResponseEntity> findAllImage() { diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/dto/ImageDto.java b/backend/src/main/java/com/hjjang/backend/domain/image/dto/ImageDto.java deleted file mode 100644 index d0808e4..0000000 --- a/backend/src/main/java/com/hjjang/backend/domain/image/dto/ImageDto.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.hjjang.backend.domain.image.dto; - - -import com.hjjang.backend.domain.image.domain.entity.Image; -import lombok.*; - -import javax.validation.constraints.NotEmpty; -import java.io.IOException; - -@Getter -@Builder -@AllArgsConstructor -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ImageDto { - @NotEmpty - private String path; - - public Image toEntity() throws IOException { - return Image.builder() - .path(this.path) - .build(); - } -} diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java index 58a78aa..5b873b0 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java @@ -1,19 +1,41 @@ package com.hjjang.backend.domain.image.service; +import com.hjjang.backend.domain.image.domain.repository.ImageRepository; import com.hjjang.backend.domain.image.domain.entity.Image; +import com.hjjang.backend.domain.image.exception.ImageNotFoundException; +import com.hjjang.backend.infra.aws.service.S3ImageUploader; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; +import javax.transaction.Transactional; import java.io.IOException; import java.util.List; -public interface ImageService { +@Service +@RequiredArgsConstructor +@Transactional +public class ImageService { + private final ImageRepository imageRepository; - List findAll(); + private final S3ImageUploader imageUploader; - Image findImageById(Long imageId); + public List findAll() { + return imageRepository.findAll(); + } - Image uploadNewImage(MultipartFile multipartFile) throws IOException; + public Image findImageById(Long imageId) { + return imageRepository.findById(imageId).orElseThrow(ImageNotFoundException::new); + } - void removeImage(Image image); + public Image uploadNewImage(MultipartFile multipartFile) throws IOException { + return imageRepository.save(new Image(imageUploader.upload(multipartFile))); + } + + public void removeImage(Image image) { + image.removeImage(); + imageRepository.save(image); + } } diff --git a/backend/src/main/java/com/hjjang/backend/infra/uploader/component/LocalUploader.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageUploader.java similarity index 88% rename from backend/src/main/java/com/hjjang/backend/infra/uploader/component/LocalUploader.java rename to backend/src/main/java/com/hjjang/backend/domain/image/service/ImageUploader.java index 1374456..46b99c2 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/uploader/component/LocalUploader.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageUploader.java @@ -1,8 +1,8 @@ -package com.hjjang.backend.infra.uploader.component; +package com.hjjang.backend.domain.image.service; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.File; @@ -13,10 +13,9 @@ @Slf4j @RequiredArgsConstructor -@Component -public class LocalUploader implements ImageUploader { +@Service +public class ImageUploader { - @Override public String upload(MultipartFile multipartFile) throws IOException { File uploadFile = this.localUpload(multipartFile) // 파일 변환할 수 없으면 에러 @@ -25,13 +24,11 @@ public String upload(MultipartFile multipartFile) throws IOException { return uploadFile.getName(); } - @Override public String changeFileName(MultipartFile uploadFile) { return UUID.randomUUID() + ".png"; // 저장될 파일 이름 변환 } // 로컬에 파일 업로드 하기 - @Override public Optional localUpload(MultipartFile file) throws IOException { File convertFile = new File(Path.imageSavePath.getPath() + changeFileName(file)); if (convertFile.createNewFile()) { // 바로 위에서 지정한 경로에 File이 생성됨 (경로가 잘못되었다면 생성 불가능) diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageService.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageService.java deleted file mode 100644 index a732372..0000000 --- a/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageService.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.hjjang.backend.domain.image.service; - -import com.hjjang.backend.domain.image.domain.repository.ImageRepository; -import com.hjjang.backend.domain.image.dto.ImageDto; -import com.hjjang.backend.domain.image.domain.entity.Image; -import com.hjjang.backend.domain.image.exception.ImageNotFoundException; -import com.hjjang.backend.infra.uploader.component.LocalUploader; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.web.multipart.MultipartFile; - -import javax.transaction.Transactional; -import java.io.IOException; -import java.util.List; - -@Service -@RequiredArgsConstructor -@Transactional -public class LocalImageService implements ImageService{ - private final ImageRepository imageRepository; - private final LocalUploader imageUploader; - - @Override - public List findAll() { - return imageRepository.findAll(); - } - - @Override - public Image findImageById(Long imageId) { - return imageRepository.findById(imageId).orElseThrow(ImageNotFoundException::new); - } - - @Override - public Image uploadNewImage(MultipartFile multipartFile) throws IOException { - ImageDto imageDto = new ImageDto(imageUploader.upload(multipartFile)); - return imageRepository.save(imageDto.toEntity()); - } - - @Override - public void removeImage(Image image) { - image.removeImage(); - imageRepository.save(image); - } - -} diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageUploader.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageUploader.java new file mode 100644 index 0000000..07a5301 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageUploader.java @@ -0,0 +1,10 @@ +package com.hjjang.backend.domain.image.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@RequiredArgsConstructor +@Service +public class LocalImageUploader extends ImageUploader{} \ No newline at end of file diff --git a/backend/src/main/java/com/hjjang/backend/infra/uploader/component/Path.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/Path.java similarity index 81% rename from backend/src/main/java/com/hjjang/backend/infra/uploader/component/Path.java rename to backend/src/main/java/com/hjjang/backend/domain/image/service/Path.java index 75e3afe..4e7a803 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/uploader/component/Path.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/service/Path.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.infra.uploader.component; +package com.hjjang.backend.domain.image.service; import lombok.Getter; diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/service/S3ImageService.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/S3ImageService.java deleted file mode 100644 index a77607f..0000000 --- a/backend/src/main/java/com/hjjang/backend/domain/image/service/S3ImageService.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.hjjang.backend.domain.image.service; - -import com.hjjang.backend.domain.image.domain.entity.Image; -import com.hjjang.backend.domain.image.domain.repository.ImageRepository; -import com.hjjang.backend.domain.image.exception.ImageNotFoundException; -import com.hjjang.backend.infra.uploader.component.S3Uploader; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.web.multipart.MultipartFile; - -import javax.transaction.Transactional; -import java.io.IOException; -import java.util.List; - -@Service -@RequiredArgsConstructor -@Transactional -public class S3ImageService implements ImageService { - private final ImageRepository imageRepository; - private final S3Uploader imageUploader; - - @Override - public List findAll() { - return imageRepository.findAll(); - } - - @Override - public Image findImageById(Long imageId) { - return imageRepository.findById(imageId).orElseThrow(ImageNotFoundException::new); - } - - @Override - public Image uploadNewImage(MultipartFile multipartFile) throws IOException { - return imageRepository.save( - new Image(imageUploader.upload(multipartFile)) - ); - } - - @Override - public void removeImage(Image image) { - image.removeImage(); - imageRepository.save(image); - } -} diff --git a/backend/src/main/java/com/hjjang/backend/infra/uploader/component/S3Uploader.java b/backend/src/main/java/com/hjjang/backend/infra/aws/service/S3ImageUploader.java similarity index 61% rename from backend/src/main/java/com/hjjang/backend/infra/uploader/component/S3Uploader.java rename to backend/src/main/java/com/hjjang/backend/infra/aws/service/S3ImageUploader.java index c0c2dd3..522cb79 100644 --- a/backend/src/main/java/com/hjjang/backend/infra/uploader/component/S3Uploader.java +++ b/backend/src/main/java/com/hjjang/backend/infra/aws/service/S3ImageUploader.java @@ -1,24 +1,22 @@ -package com.hjjang.backend.infra.uploader.component; +package com.hjjang.backend.infra.aws.service; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.PutObjectRequest; +import com.hjjang.backend.domain.image.service.ImageUploader; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.util.Optional; -import java.util.UUID; @Slf4j @RequiredArgsConstructor -@Component -public class S3Uploader implements ImageUploader { +@Service +public class S3ImageUploader extends ImageUploader { private final AmazonS3Client amazonS3Client; @@ -35,11 +33,6 @@ public String upload(MultipartFile multipartFile) throws IOException { return upload(uploadFile); } - @Override - public String changeFileName(MultipartFile uploadFile) { - return UUID.randomUUID() + ".png"; // 저장될 파일 이름 변환 - } - // S3로 파일 업로드하기 private String upload(File uploadFile) { String uploadImageUrl = putS3(uploadFile, "static/" + uploadFile.getName()); // s3로 업로드 @@ -63,19 +56,4 @@ private void removeNewFile(File targetFile) { } log.info("File delete fail"); } - - // 로컬에 파일 업로드 하기 - @Override - public Optional localUpload(MultipartFile file) throws IOException { - File convertFile = new File(Path.imageSavePath.getPath() + changeFileName(file)); - if (convertFile.createNewFile()) { // 바로 위에서 지정한 경로에 File이 생성됨 (경로가 잘못되었다면 생성 불가능) - try (FileOutputStream fos = - new FileOutputStream(convertFile)) { // FileOutputStream 데이터를 파일에 바이트 스트림으로 저장하기 위함 - fos.write(file.getBytes()); - } - return Optional.of(convertFile); - } - - return Optional.empty(); - } } diff --git a/backend/src/main/java/com/hjjang/backend/infra/uploader/component/ImageUploader.java b/backend/src/main/java/com/hjjang/backend/infra/uploader/component/ImageUploader.java deleted file mode 100644 index 2588416..0000000 --- a/backend/src/main/java/com/hjjang/backend/infra/uploader/component/ImageUploader.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hjjang.backend.infra.uploader.component; - -import org.springframework.web.multipart.MultipartFile; - -import java.io.File; -import java.io.IOException; -import java.util.Optional; - -public interface ImageUploader { - - String upload(MultipartFile multipartFile) throws IOException; - - String changeFileName(MultipartFile uploadFile); - - Optional localUpload(MultipartFile file) throws IOException; -} From 36d987cfeb0d2e8cde7a43075c40a2e2444dea3b Mon Sep 17 00:00:00 2001 From: 0BVer Date: Sat, 30 Apr 2022 22:47:36 +0900 Subject: [PATCH 34/46] =?UTF-8?q?chore=20:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=9E=84=ED=8F=AC=ED=8A=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hjjang/backend/domain/image/service/ImageService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java index 5b873b0..ac506a1 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java @@ -5,7 +5,6 @@ import com.hjjang.backend.domain.image.exception.ImageNotFoundException; import com.hjjang.backend.infra.aws.service.S3ImageUploader; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; From c0b0e14b0baab6cbdb9fed5136d96bce8d8abd3e Mon Sep 17 00:00:00 2001 From: 0BVer Date: Sun, 1 May 2022 00:49:14 +0900 Subject: [PATCH 35/46] =?UTF-8?q?refactor=20:=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=83=81=EC=86=8D=20=EA=B4=80=EA=B3=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/image/service/ImageUploader.java | 6 +----- .../image/service/LocalImageUploader.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageUploader.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageUploader.java index 46b99c2..aa15b0b 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageUploader.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/service/ImageUploader.java @@ -17,11 +17,7 @@ public class ImageUploader { public String upload(MultipartFile multipartFile) throws IOException { - File uploadFile = - this.localUpload(multipartFile) // 파일 변환할 수 없으면 에러 - .orElseThrow( - () -> new IllegalArgumentException("error: MultipartFile -> File convert fail")); - return uploadFile.getName(); + return null; } public String changeFileName(MultipartFile uploadFile) { diff --git a/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageUploader.java b/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageUploader.java index 07a5301..7872844 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageUploader.java +++ b/backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageUploader.java @@ -3,8 +3,23 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; @Slf4j @RequiredArgsConstructor @Service -public class LocalImageUploader extends ImageUploader{} \ No newline at end of file +public class LocalImageUploader extends ImageUploader{ + + @Override + public String upload(MultipartFile multipartFile) throws IOException { + File uploadFile = + this.localUpload(multipartFile) // 파일 변환할 수 없으면 에러 + .orElseThrow( + () -> new IllegalArgumentException("error: MultipartFile -> File convert fail")); + return uploadFile.getName(); + } + +} \ No newline at end of file From 81585a6a4ee1f6501963cfc1d7bdad3a640a3ec5 Mon Sep 17 00:00:00 2001 From: GeunWooPark Date: Sun, 1 May 2022 23:28:29 +0900 Subject: [PATCH 36/46] =?UTF-8?q?feature:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EB=B2=84=ED=8A=BC=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.css | 11 +++++++++++ frontend/src/page/LoginPage.js | 10 ++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/frontend/src/App.css b/frontend/src/App.css index 74b5e05..68c2a64 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -36,3 +36,14 @@ transform: rotate(360deg); } } + +.kakao_btn{ + background-image: url("./images/kakao_login_large_wide.png"); + background-repeat: no-repeat; + background-size : cover; + margin: 10px auto; + /* padding: -10px; */ + color: transparent; + width: 300px; + height: 45px; +} diff --git a/frontend/src/page/LoginPage.js b/frontend/src/page/LoginPage.js index da9e825..3f7a9fd 100644 --- a/frontend/src/page/LoginPage.js +++ b/frontend/src/page/LoginPage.js @@ -1,6 +1,9 @@ import React, {useState} from "react"; import {Link, Route} from "react-router-dom"; import axios from "axios"; +import {KAKAO_AUTH_URL} from "../auth/OAuth"; +import KAKAO_LOGO from "../images/kakao_login_large_wide.png" +import styles from '../App.css'; export const LoginPage = () => { // 샘플 코드입니다. @@ -34,8 +37,11 @@ export const LoginPage = () => {
- + + + + ) -} \ No newline at end of file +} From dc159db2159454160a3c964d704cd70746536c3a Mon Sep 17 00:00:00 2001 From: GeunWooPark Date: Sun, 1 May 2022 23:46:35 +0900 Subject: [PATCH 37/46] =?UTF-8?q?feature:=20=EC=86=8C=EC=85=9C=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=EC=97=90=EC=84=9C=20=EB=B0=9C=EA=B8=89?= =?UTF-8?q?=EB=B0=9B=EC=9D=80=20accessToken=EC=9D=84=20localstorage?= =?UTF-8?q?=EC=97=90=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/page/RouterPage.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/page/RouterPage.js b/frontend/src/page/RouterPage.js index 0fabce4..41fa8cf 100644 --- a/frontend/src/page/RouterPage.js +++ b/frontend/src/page/RouterPage.js @@ -6,6 +6,7 @@ import { Route, Redirect, } from "react-router-dom"; +import OAuth2RedirectHandler from "../auth/OAuth2Redirecthandler"; import {ItemDetailPage} from "./ItemDetailPage"; import {MyPage} from "./MyPage"; @@ -24,6 +25,7 @@ export const RouterPage = () => { + From b0ad6d41a1db2b4e60ac0f81090243dcbb3c7ba0 Mon Sep 17 00:00:00 2001 From: GeunWooPark Date: Sun, 1 May 2022 23:48:21 +0900 Subject: [PATCH 38/46] =?UTF-8?q?feature:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EB=B2=84=ED=8A=BC=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/images/kakao_login_large_wide.png | Bin 0 -> 7213 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 frontend/src/images/kakao_login_large_wide.png diff --git a/frontend/src/images/kakao_login_large_wide.png b/frontend/src/images/kakao_login_large_wide.png new file mode 100644 index 0000000000000000000000000000000000000000..c0c1856129a03c5e5812854c7b7a1a6134f0f5c0 GIT binary patch literal 7213 zcmY+J1z3~c+s7FU>5!6UNJ)36bO=ay4WtDLNd-oUG>mQp$pJ$_8U~1Tw{(L@cfa%h zdw+l5_qxutoo9Q__tbNL@6XOYzSK~{!=}VWK|#S&QI^+6K|wV{){QYAp`ZYWg~;uZ z7XS}!C0UfpA?h6z6sj#1`RBSmfW2%iAKl5>?gxIOUhGgAWze%=Y*|(^X@%!PuO6d! z?K#EN%T#dcc748{d|#^Xr25M3`E&H6QDggj%t&nGmog>TNtn9v?=>;$ZRpbnyoa*q z)5ZBOhURBkdLJZ)2U{*+2UiRHu8aQPoFH$`L(*(q5xBnU#hQr3$RV=eu@41XP7X5! zP39F zx6sun3x8F+MLjRW^eum6n>UM*$u;8MZ0W#Hu2{5|UK z_Y+8K3xjqJ|9JnSDUqr>vw4vsRbkbdfB?r80UBK*<{{o2ii~*9{ZEAYC~=`x;>=b? zILq7R>rpi-;Aq>(AbUN$TRVGfQU-L@pa&c@rXQC@m}xGCdf;1^@52xrML>C*P_i&X zttD!}1F0YWhW{7G$PI*C+0OK2;+K@LUPuX~ zEG5xc@$DBtQL*5&x>WP+9=ijG{KTXv7`IvINjaIwwSSXWY4_emtsb;7dy6DhkR5MB zU)0UI(MqsOaoxyhQ7JB{G@Mk@%~0Eep72Y|q^S&?c7+LH6?u4U;}Qc*3TLX?yQx-( z&5LH*D1!`9!O!f{)5v_oUbt4%b&xmVMFkH=?LRK0K|0m1$gI;Id!0g9q*Hc*ZGoU9B&5(wfpN|Mc)6$uzRF_ z+97zPT#VXPwc{h?#x1&}D%P-na>TlyoM7d?1nMRtHZV+$I?nQ_6Z3*w%?&XcSgs|T zvX?b}ac6gFovJ3$9_kuvJfotS8L2w8z? z|7^in#f=cflk>Oaza7n0W%w`GbgWCybYf1=)F7zdP5LooHp8toFALe3`lrNN9#!GF zs!j(`O*tHe{QSasY+@n6WS=xC4QRvb4jw5ZYv=ZzE*v7vm>?z!bp7hGr)mO~!m|C5r7DQ$GD2)>T=*gwE%nA9)I)&E zAX+Tta@BjZq%W-4QS6A-BVH|LA`pNR;81N+4>ykroo19lJ$ezuFmiP3`HTuHK8Ol{ zzg54ojE5C3BSD(^3oX31=)$s4fhYfi=gzc#nD9rO)(h3*+5N@*TxNdT! z6yvfAXkEj*!9c(Es>-q{`Qd8md+U;2gYOYDDsb_-+-aKX^?BXm@(f(wwc3TpVWOEu zYJ{v`zp+(32}A~|@_8U{%pSeWrx*M*)UY)oL1U3>P#i1t$`yCA_%@UjBhIIa&!BTd zlzTc{sDfrmQu_`g+KKyovm3f^kT0KOZV;lux;I|d}m@OEJLeUITsY`bJnmnv?sEjLesBb1U{4Pp1z;()c$7X zgip_^5=cibNIP83M3~rt{b8FxLOqNWKUUE zL)lS3#vCw|x&g4pp{dUhiw;dNZ0WsfJ56f0xVzHhW zysi@axv&zf!qAoE&z)TY|J1KQlYhrmjoV}g{+ybabnmyn(GW}Ub~j9=O=-W32Yc-7 zAfTu`A(mV>gsx32g3gO+<*uuOWcT+ssfaH(5fE%&H4a5ihWv-qHX#}lGbpqiXL8MNR;z*aYA%x2_9J~j*+cM++p zW~4BPo;HBnp4@c*)?O$HsdV}fR+TE|tu+xNKU~j1=w94pTo4A{>ggpY_rBipXacBh zqB>NZcJ5G7q1s-jNHCqe;NP)Ynp!Bx z3p8|YvREo$fA`kfLDrQ)tyq|AeYUmhmbtYkWNy|0UKa1Bqs9_Yumt!~ zWu+H5rQ{Q~g?5L`BQ;98IJBlAUgGbn;_Pi@3~7*EUebd|#=Q)A2ge@s*J_KBrre>h zg(mh*JUY(!(-T-7kr-5+BEga3{tR2~8GGhSeQMt5GpN-SGC~`Hx}RT>_WgRx#%`u~ z$_OBeAV&3~B2&?-7hut##q0tBhz`{e;4T|Bj-_aFRpg{tfHq1Jr21JBxRKA10iKH@ z{_~C>jEfwH2)#@gDGNa`I35M-l0_zLBlod2vicnhxeOw{gd|7L-PI@#XZ(bt1G+jf2wY>puz*9Uz1j~m-;L0u2B@`;*c-yd2@SSQ4DbXLp&7u1@v}>ws?QP|YbmxA@^`!g8!cySIuruCamUJ3dH5*hN>cNSc$j zk?sQ8FP^tp^xMaV{HskDeI5MZA#>fU%6q)PKRffH+oEvw{D#`1OoOB?=u9mZcuQ|o zhwDo$h)T~2YoA8vwtI{B@|Nw*Qg-`Rd(u6Y?sP;|v~B}CWXskDyvGWNjoObK{7an$G6v*=)pM!O58c|5eSI436wKZ=kXjU3K7@x1 zJ>zap{D_1zxZMIhBjZfS#y3p$X>Frib5MOv!V8+}zr%CB3#+{stb zze?B5GqP8ht&3yN43F-4|4>)cR6R-N@CyoZe$?me9HK*gE4wx9F&q}c`e$#O&C52jJoIUPMJpH-98qHcgY^yPX$&J#zj(i!HGZI$co38csRrmzDWvqIvrLk?CspAP{ZuVIT`kZS1z}{KPOr*bw zde@M+_tEG29vhc#oh!FWptS>^ddgskX%0Ga;+z`pXKPG0wEf#J>@1n36Rd{NB<3S? zSq?)Kmq&L}5YYi^?u50UmLhB=Jm%HwGmLS*MbK6M3RW3!&BoJixC6W6FJ^0%*?!Kd zyN?g$t&6(n9Ie|Jeq}qO@L=H6DpF@%=Y6txxbpavYJs*Oe8O@j$auh4nnqj8Z)!F- z3pWlAaKPfI9b2l2(()la+L@5EBKbK=3xjOl4MHNiZKz3;y)6V!b0JW+Za`-2UE48X z&ZWn<%rIvD*U8wo@N2lpje&fi$xrMh7dKW-&HR9$U-1ph_4jrv{M)J-vFyCx9+dAs z`^A<#j-fUN-^{d;xZH)-J6rm2h?&uEQ|Kf22A1_rCYGFn>+ORbP5hgs_e3u}74abm z-_GMVqgTa8^K#dbD%`u4V-ju$SUuL(DtwjXxy11s$F~RU^Vf;{@7bt^Z!1w9N-Gl- z9D38==6-xETQEAZTLlZ2*v=q>U&Dwlo3yi0v0*E=f(O3D{2aJ&rbZS9Jqf>GoWUJ}dQUjd@4*%}F#j z3y;>(3tzN&$>L`fY$cfu6D1Ic&UQ zUwYwuU9L1CqC{8Ax6KM;)vTRT)T+EWEA6!IT4abb!`bCMJ959ZefQabk|C}}f0Oi^ z7VT-ABn1A9W7sikfz+NO?#6o$2G9*m_HC3c9gav;z6okW1toFGwL__EV8<7e&fOD8w}mHWn; z-wEt^KX%*fmqjWqYJO90&GKc-y* zANUG>flL?Ve|Yi;&GHB-xrrIE;C^)^=utu*g%rZagngMI$TNQ@r(rjpCqfwa6q!fj zWf%ZzY+@z}p|V8u0HlBqGsql6)7Tw8?AY4{aP#n%z)|}Hr^Z}>{9Hv!h)BjaN3L@9a%08P!(s+yQr0VzQ?NH<2t1t6>gQ8XbB&~mnA22Du zlO)TE^v5IzrGa0>w$k74Adg=ajUg_^E)l_?@(~DMi6}RohW~{_Md_oi-HGRuIDBFD@jh22YD3{4)}j! zl!onY)@*;<@i5Au^%LTu{qLInff*500eJA*58c1*ER{i{Jd8h(Ck>A_n=#%sVwY4A zyhxMRD(`=UTKB-svmA)3)<5(2enK{YT4%tF+#nBF?LEWcirq@jpm^M9XOOf6 zu*P+ZMv;!lz8A=*Y2>zAh~BFr;}XjWe)dUE<2&0(Fn?wF*Jb5WYeWI4>Un%bR3H`S zr z(evrLET_^vbjcqC@W*Ea58nfkNmDD$RW4OSXx$r5&ztaYIw;Y&wxRDlmmbRJw(q4V z*+@2Z^Xg)7)5i3zNo?ZX)Gz@9zZ|8JCvtkNnBScv;Fb9G?hAoRlP;2Vt-=?x~=&t@oE@3b@#X#*ASETpyK(Kv*1K@VY*4ERjoDI#pOJ1I1aI#nJng z5Oy|Id_9fnP25u<56}@;4srd#zfo^%Q|qGT)r3BMSH{Uazw`)=TO#JdHs#lk0+#=n z6R(lN<(v}O$+Xm`5W?~*p8>L|VY%`}UzJn|uT(+NZ#~?*Lo1d#Ht|QYDeO2`lOSEF z(gywJ0Y2|<4z8vsVz#>ZGK3*%_PKhys~CW-3=Dlkku#$8d^CVQEhLvl>=<+=n*w4E~9>Al20D~nE`-2 zF_3wI3llivGo#JQA*lE!R(f*cDY2t~sve5a^vfcHwm{?Oz5(`kx7AH#%$M?b^b_XH1%~7e|P9u zx^tyF*3;|*~}^BDvk*tm_qZ; z`QGRX{eD}nJBt5vE!i%PJ&Iz&^O)lU#?n0qkDzUtd@M`n9d*Umvy<_nH9_Q#x}x&( z!uOw{<~%#+G^~+zZJ{@2s-`Bwl!mn5InfhH)*YAYk}Pbbd7oVftBw{l9Z<}*>OWR2 zr>><{+oJ8k0zgBvlbAL{$UrvK#!QEB;1$b-a$E--UbD+bJt{&J( zy{6ceOHUE^o0S+Vjh>JnZMR#J&{f@5KH8MJ;jzPLZ9;#pC{%_6^Y?sqL^ZK{(yL2r zr3uTTw0VxLnb0|fMrwzN*H^#epMIM+wk$|{!suU17BGQrQRzMKIMJhTJ+enUO5@{V zx;r^ua+vmoIIS~hVn2h3_gb3c?N#+*)%GmBw|&`;8CPW%ht)v8F9ez5L1I8K*s`}w z^1^>PygX=kKWKX>PUF?2_WImm@N~nIl)jLyBF((k#ZSLqogJH2k7mAka$eEdG#&>O z{LuR(#y)wCRgS9qGh+E(Fh&WL1y~9LE9HAJxJWNk1?! zhnUZnEhP?rCsJFfBnN9irlyQ}wy#Z@2Au*q2<(r75+eeUNd)yNa&^>HXX}LF)_8}* z8;B$p5OdNaMt?-YhQ?%73uw~^7hi;xI9`UD2yQvgJr^k|6q^%mzBPqW^BHo5jSP|# zB3@?rnTIvn%Q(%D?e9sQrDK!ZacsLxI=4dyW*-)uXg1vB4CG$mf&jv(yn=9Dl}bwd zo`UDi5gOU(ByC0Ep#ejEp)&*+@h7cBrXI3#!)c=NG6Ps5o6|j$?)ffdJ56k(tXr$) zbJiEFh=4-L4_=3ye%2-Ph8|b%9&W-E)WR+Mc=fa%_d1&mZf-@`8GIYWlhG!G1Y%@oan2tcWt+e;(gzfGt6t6al~N`|utUtdd& zgfOwYNQd&;BbLJQyL^o}OPS!6{{^^?*iEG14HTc uSe^6HI>>&~#}Xt&E2L2W<}bT=Kx?NRKO!XuXd?grLs3!Ckgt@r4E`T&MN-ZH literal 0 HcmV?d00001 From 7acf3695e97737870be0a48037523de8529b9ce0 Mon Sep 17 00:00:00 2001 From: GeunWooPark Date: Sun, 1 May 2022 23:50:16 +0900 Subject: [PATCH 39/46] =?UTF-8?q?feat:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EC=86=8C=EC=85=9C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EA=B2=BD=EB=A1=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/auth/OAuth.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 frontend/src/auth/OAuth.js diff --git a/frontend/src/auth/OAuth.js b/frontend/src/auth/OAuth.js new file mode 100644 index 0000000..27ca6ed --- /dev/null +++ b/frontend/src/auth/OAuth.js @@ -0,0 +1,6 @@ +export const ACCESS_TOKEN = "accessToken"; +export const API_BASE_URL = `${process.env.REACT_APP_HOST}`; +export const OAUTH2_REDIRECT_URI = `${API_BASE_URL}/oauth2/redirect`; +export const SERVER_BASE_URL = `${process.env.REACT_APP_SERVER_HOST}`; +export const KAKAO_AUTH_URL = `${SERVER_BASE_URL}/oauth2/authorization/kakao?redirect_uri=${OAUTH2_REDIRECT_URI}`; +가 \ No newline at end of file From 1857524b6249ccfc8777a4d8c4f850e047577819 Mon Sep 17 00:00:00 2001 From: GeunWooPark Date: Sun, 1 May 2022 23:50:32 +0900 Subject: [PATCH 40/46] =?UTF-8?q?feat:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EC=86=8C=EC=85=9C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=95=B8?= =?UTF-8?q?=EB=93=A4=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/auth/OAuth2Redirecthandler.js | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 frontend/src/auth/OAuth2Redirecthandler.js diff --git a/frontend/src/auth/OAuth2Redirecthandler.js b/frontend/src/auth/OAuth2Redirecthandler.js new file mode 100644 index 0000000..7c467c7 --- /dev/null +++ b/frontend/src/auth/OAuth2Redirecthandler.js @@ -0,0 +1,45 @@ +import React from "react"; +import { Redirect, useLocation } from "react-router-dom"; +import { ACCESS_TOKEN } from "./OAuth"; + +const OAuth2RedirectHandler = () => { + const location = useLocation(); + + const getUrlParameter = (name) => { + const setName = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + const regex = new RegExp("[\\?&]" + setName + "=([^&#]*)"); + + const results = regex.exec(location.search); + return results === null + ? "" + : decodeURIComponent(results[1].replace(/\+/g, " ")); + }; + + const token = getUrlParameter("token"); + const error = getUrlParameter("error"); + + if (token) { + localStorage.setItem(ACCESS_TOKEN, token); + return ( + + ); + } + return ( + + ); +}; + +export default OAuth2RedirectHandler; From a057beb2bdd7bbcad2506b655b6007c7e098b3ac Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 2 May 2022 21:32:36 +0900 Subject: [PATCH 41/46] style: rename status --- .../com/hjjang/backend/global/response/code/SuccessCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java b/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java index 7a3fdec..f045aae 100644 --- a/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java +++ b/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java @@ -10,7 +10,7 @@ public enum SuccessCode { //User USERPROFILE_SUCCESS(200, "U001", "프로필 조회 완료."),; - private final int httpStatus; + private final int status; private final String code; private final String message; } From 803df88270fc1905ec521a74067cdb232a2cfe37 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 2 May 2022 21:33:31 +0900 Subject: [PATCH 42/46] style: naver convention and of method --- .../response/response/ErrorResponse.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java b/backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java index af55b00..bc53a6d 100644 --- a/backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java +++ b/backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java @@ -1,15 +1,13 @@ package com.hjjang.backend.global.response.response; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import org.springframework.validation.BindingResult; - import com.hjjang.backend.global.response.code.ErrorCode; - import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.validation.BindingResult; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; @Getter @NoArgsConstructor @@ -34,6 +32,10 @@ private ErrorResponse(final ErrorCode code) { this.errors = new ArrayList<>(); } + public static ErrorResponse of(final ErrorCode code) { + return new ErrorResponse(code); + } + public static ErrorResponse of(final ErrorCode code, final BindingResult bindingResult) { return new ErrorResponse(code, FieldError.of(bindingResult)); } @@ -60,11 +62,11 @@ public static List of(final String field, final String value, final private static List of(final BindingResult bindingResult) { final List fieldErrors = bindingResult.getFieldErrors(); return fieldErrors.stream() - .map(error -> new FieldError( - error.getField(), - error.getRejectedValue() == null ? "" : error.getRejectedValue().toString(), - error.getDefaultMessage())) - .collect(Collectors.toList()); + .map(error -> new FieldError( + error.getField(), + error.getRejectedValue() == null ? "" : error.getRejectedValue().toString(), + error.getDefaultMessage())) + .collect(Collectors.toList()); } } From cf4a9c5646dde42c398ab238b65e5516c078d688 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 2 May 2022 21:34:01 +0900 Subject: [PATCH 43/46] =?UTF-8?q?feat:=20=EC=A0=84=EC=97=AD=20exception=20?= =?UTF-8?q?handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/GlobalExceptionHandler.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/global/execption/handler/GlobalExceptionHandler.java diff --git a/backend/src/main/java/com/hjjang/backend/global/execption/handler/GlobalExceptionHandler.java b/backend/src/main/java/com/hjjang/backend/global/execption/handler/GlobalExceptionHandler.java new file mode 100644 index 0000000..a6f4a42 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/global/execption/handler/GlobalExceptionHandler.java @@ -0,0 +1,21 @@ +package com.hjjang.backend.global.execption.handler; + +import com.hjjang.backend.global.response.response.ErrorResponse; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import static com.hjjang.backend.global.response.code.ErrorCode.INTERNAL_SERVER_ERROR; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + // 500 에러 + @ExceptionHandler + protected ResponseEntity handleException(Exception e) { + final ErrorResponse response = ErrorResponse.of(INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); + } + +} From 7ba211241c8bca57daa3b955c531ea4c68afdc1e Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 2 May 2022 21:34:19 +0900 Subject: [PATCH 44/46] feat: add SuccessResponse --- .../response/response/SuccessResponse.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/global/response/response/SuccessResponse.java diff --git a/backend/src/main/java/com/hjjang/backend/global/response/response/SuccessResponse.java b/backend/src/main/java/com/hjjang/backend/global/response/response/SuccessResponse.java new file mode 100644 index 0000000..9f53bc5 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/global/response/response/SuccessResponse.java @@ -0,0 +1,33 @@ +package com.hjjang.backend.global.response.response; + +import com.hjjang.backend.global.response.code.SuccessCode; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; + +@Getter +public class SuccessResponse { + + @Schema(description = "status code") + private final int status; + @Schema(description = "Business code") + private final String code; + @Schema(description = "response message") + private final String message; + @Schema(description = "response data") + private final Object data; + + public static SuccessResponse of(SuccessCode successCode, Object data) { + return new SuccessResponse(successCode, data); + } + + public static SuccessResponse of(SuccessCode successCode) { + return new SuccessResponse(successCode, ""); + } + + public SuccessResponse(SuccessCode successCode, Object data) { + this.status = successCode.getStatus(); + this.code = successCode.getCode(); + this.message = successCode.getMessage(); + this.data = data; + } +} From 9895e126b652a631290ca7ff97f40f22bd0ac36f Mon Sep 17 00:00:00 2001 From: 0BVer Date: Wed, 4 May 2022 18:47:00 +0900 Subject: [PATCH 45/46] =?UTF-8?q?chore=20:=20PR=20=EC=A4=91=20=EB=8D=AE?= =?UTF-8?q?=EC=96=B4=EC=94=8C=EC=9B=8C=EC=A0=B8=EB=B2=84=EB=A6=B0=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=B3=B5=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/application.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 464d262..18c32cd 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -70,16 +70,16 @@ spring: max-file-size: 50MB max-request-size: 50MB -auth: - tokenProperties: - tokenSecretKey: asodfhwoeihro1i34u1097r09u13rqfasc12 - tokenExpireDate: 1800000 - refreshTokenExpiry: 604800000 - jwtProperties: - secretKey: 'HJJangHandsomeGnuKenny120hy12049h014' - corsProperties: - allowed-origins: '*' - allowed-methods: GET,POST,PUT,DELETE,OPTIONS +auth-properties: + token-properties: + token-secret-key: 'asodfhwoeihro1i34u1097r09u13rqfasc12' + token-expire-date: 1800000 + refresh-token-expiry: 604800000 + jwt-properties: + secret-key: 'HJJangHandsomeGnuKenny120hy12049h014' + cors-properties: + allowed-origins: 'localhost:3000,http://localhost,http://localhost:3000' + allowed-methods: 'GET,POST,PUT,DELETE,OPTIONS' allowed-headers: '*' max-age: 3600 oAuth2Properties: From 59aa0017f5f4e49eddfab7869413c13721c7da5c Mon Sep 17 00:00:00 2001 From: 0BVer Date: Wed, 4 May 2022 19:01:13 +0900 Subject: [PATCH 46/46] =?UTF-8?q?feat=20:=20application.yml=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EB=B6=84=EB=A6=AC=20=EB=B0=8F=20git.ignore=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/.gitignore | 3 + .../resources/application-auth.yml.template | 39 ++++++++++++ .../resources/application-db.yml.template | 25 ++++++++ .../resources/application-email.yml.template | 12 ++++ backend/src/main/resources/application.yml | 63 +------------------ 5 files changed, 82 insertions(+), 60 deletions(-) create mode 100644 backend/src/main/resources/application-auth.yml.template create mode 100644 backend/src/main/resources/application-db.yml.template create mode 100644 backend/src/main/resources/application-email.yml.template diff --git a/backend/.gitignore b/backend/.gitignore index 2a17aab..4e98f71 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -62,3 +62,6 @@ hs_err_pid* /src/main/resources/application-aws.yml /src/main/resources/application-credentials.yml +/src/main/resources/application-auth.yml +/src/main/resources/application-db.yml +/src/main/resources/application-email.yml diff --git a/backend/src/main/resources/application-auth.yml.template b/backend/src/main/resources/application-auth.yml.template new file mode 100644 index 0000000..aa37662 --- /dev/null +++ b/backend/src/main/resources/application-auth.yml.template @@ -0,0 +1,39 @@ +spring: + # oauth 설정 + security: + oauth2.client: + registration: + kakao: + clientId: + clientSecret: + clientAuthenticationMethod: + authorizationGrantType: + redirectUri: + scope: + - profile_nickname + - profile_image + - account_email + clientName: + provider: + kakao: + authorizationUri: + tokenUri: + userInfoUri: + userNameAttribute: + +auth-properties: + token-properties: + token-secret-key: + token-expire-date: + refresh-token-expiry: + jwt-properties: + secret-key: + cors-properties: + allowed-origins: + allowed-methods: + allowed-headers: + max-age: + oAuth2Properties: + redirectUris: + - + - \ No newline at end of file diff --git a/backend/src/main/resources/application-db.yml.template b/backend/src/main/resources/application-db.yml.template new file mode 100644 index 0000000..4c72e8f --- /dev/null +++ b/backend/src/main/resources/application-db.yml.template @@ -0,0 +1,25 @@ +spring: + datasource: + driver-class-name: + url: + username: + password: + + jpa: + database: + show-sql: + hibernate: + ddl-auto: + properties: + hibernate: + format_sql: true + generate-ddl: true + + flyway: + enabled: false + url: + user: + password: + baseline-on-migrate: true + ignore-ignored-migrations: true + clean-on-validation-error: true \ No newline at end of file diff --git a/backend/src/main/resources/application-email.yml.template b/backend/src/main/resources/application-email.yml.template new file mode 100644 index 0000000..024e521 --- /dev/null +++ b/backend/src/main/resources/application-email.yml.template @@ -0,0 +1,12 @@ +spring: + mail: + host: + port: + username: + password: + properties: + mail: + smtp: + auth: true + starttls: + enable: true \ No newline at end of file diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 18c32cd..ff38443 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -3,27 +3,16 @@ spring: name: "backend" profiles: include: + - db + - auth + - email - aws - credentials - datasource: - driver-class-name: "com.mysql.cj.jdbc.Driver" - url: "jdbc:mysql://localhost:3306/test_db?useSSL=false&useLegacyDatetimeCode=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul&characterEncoding=UTF-8&autoReconnect=true&createDatabaseIfNotExist=true" - username: "root" - password: "0000" redis: host: bauction-redis port: 6379 - jpa: - database: "mysql" - show-sql: "true" - hibernate: - ddl-auto: "update" - properties: - hibernate: - format_sql: true - generate-ddl: true #----- for swagger UI # mvc: # pathmatch: @@ -34,55 +23,9 @@ spring: # schema-locations: classpath:scheme.sql # data-locations: classpath:data.sql # mode: always - flyway: - enabled: false - url: jdbc:mysql://localhost:3306/test_db - user: root - password: 0000 - baseline-on-migrate: true - ignore-ignored-migrations: true - clean-on-validation-error: true - - # oauth 설정 - security: - oauth2.client: - registration: - kakao: - clientId: '2de38f203dbe5dc3a59740cb5f8438a3' - clientSecret: 'U5Pq6S2H2A52ANmKwn5fxoF5mYL3cTFU' - clientAuthenticationMethod: post - authorizationGrantType: authorization_code - redirectUri: "http://localhost:8080/login/oauth2/code/kakao" - scope: - - profile_nickname - - profile_image - - account_email - clientName: Kakao - provider: - kakao: - authorizationUri: https://kauth.kakao.com/oauth/authorize - tokenUri: https://kauth.kakao.com/oauth/token - userInfoUri: https://kapi.kakao.com/v2/user/me - userNameAttribute: id servlet: multipart: max-file-size: 50MB max-request-size: 50MB -auth-properties: - token-properties: - token-secret-key: 'asodfhwoeihro1i34u1097r09u13rqfasc12' - token-expire-date: 1800000 - refresh-token-expiry: 604800000 - jwt-properties: - secret-key: 'HJJangHandsomeGnuKenny120hy12049h014' - cors-properties: - allowed-origins: 'localhost:3000,http://localhost,http://localhost:3000' - allowed-methods: 'GET,POST,PUT,DELETE,OPTIONS' - allowed-headers: '*' - max-age: 3600 - oAuth2Properties: - redirectUris: - - 'http://localhost:3000/oauth/redirect' - - 'https://getpostman.com/oauth2/redirect' \ No newline at end of file