From d6b401f03f67ff687fa23ce5b7afc124d665f293 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Thu, 5 Oct 2023 02:48:36 +0900 Subject: [PATCH 01/31] =?UTF-8?q?fix=20:=20ddl-auto=20create=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 25 ------------------- .../resources/application-local-mysql.yml | 3 +-- 2 files changed, 1 insertion(+), 27 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 7fc8d0c..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Build and Deploy to EC2 - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - - name: Grant execute permission for gradlew - run: chmod +x ./gradlew - shell: bash - - - name: Build and Test - run: ./gradlew build test diff --git a/be/overflow/src/main/resources/application-local-mysql.yml b/be/overflow/src/main/resources/application-local-mysql.yml index e550c6a..cd775ba 100644 --- a/be/overflow/src/main/resources/application-local-mysql.yml +++ b/be/overflow/src/main/resources/application-local-mysql.yml @@ -9,11 +9,10 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: - ddl-auto: update + ddl-auto: create properties: hibernate: format_sql: true - url: logging: level: From 5222248921b39bd9a86663855fc59dd3fa3b3399 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Thu, 5 Oct 2023 02:50:33 +0900 Subject: [PATCH 02/31] =?UTF-8?q?feat=20:=20develop=20db=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mysql-init.d/00_init.sql | 13 +++++++++++ .../mysql-init.d/01_create_table.sql | 23 +++++++++++++++++++ .../main/resources/application-dev-mysql.yml | 20 ++++++++++++++++ .../resources/application-dev-security.yml | 9 ++++++++ .../src/main/resources/application.yml | 4 +++- 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100755 be/overflow/resources/develop-environment/mysql-init.d/00_init.sql create mode 100644 be/overflow/resources/develop-environment/mysql-init.d/01_create_table.sql create mode 100644 be/overflow/src/main/resources/application-dev-mysql.yml create mode 100644 be/overflow/src/main/resources/application-dev-security.yml diff --git a/be/overflow/resources/develop-environment/mysql-init.d/00_init.sql b/be/overflow/resources/develop-environment/mysql-init.d/00_init.sql new file mode 100755 index 0000000..c0889b6 --- /dev/null +++ b/be/overflow/resources/develop-environment/mysql-init.d/00_init.sql @@ -0,0 +1,13 @@ +CREATE + USER 'overflow-local'@'localhost' IDENTIFIED BY 'root'; +CREATE + USER 'overflow-local'@'%' IDENTIFIED BY 'root'; + +GRANT ALL PRIVILEGES ON *.* TO + 'overflow-local'@'localhost'; +GRANT ALL PRIVILEGES ON *.* TO + 'overflow-local'@'%'; + +CREATE + DATABASE overflow DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + diff --git a/be/overflow/resources/develop-environment/mysql-init.d/01_create_table.sql b/be/overflow/resources/develop-environment/mysql-init.d/01_create_table.sql new file mode 100644 index 0000000..ebe2378 --- /dev/null +++ b/be/overflow/resources/develop-environment/mysql-init.d/01_create_table.sql @@ -0,0 +1,23 @@ +create table auth_info_tb +( + auth_info_id BIGINT not null auto_increment, + user_id BIGINT not null, + auth_info_type varchar(255) not null, + auth_info_token varchar(255) not null, + created_date datetime not null, + deleted bit not null, + updated_date datetime not null, + primary key (auth_info_id) +) ENGINE = InnoDB; + +create table user_tb +( + user_id BIGINT not null auto_increment, + user_email varchar(255) not null, + user_nickname varchar(255) not null, + user_password varchar(255) not null, + created_date datetime not null, + deleted bit not null, + updated_date datetime not null, + primary key (user_id) +) ENGINE = InnoDB; \ No newline at end of file diff --git a/be/overflow/src/main/resources/application-dev-mysql.yml b/be/overflow/src/main/resources/application-dev-mysql.yml new file mode 100644 index 0000000..45324f2 --- /dev/null +++ b/be/overflow/src/main/resources/application-dev-mysql.yml @@ -0,0 +1,20 @@ +spring: + config: + activate: + on-profile: dev-mysql + datasource: + url: ${DB_CONNECTION_URL} + username: ${DB_USER} + password: ${DB_PASSWORD} + driver-class-name: com.mysql.cj.jdbc.Driver + jpa: + hibernate: + ddl-auto: create + properties: + hibernate: + format_sql: true + database-platform: org.hibernate.dialect.MySQL8Dialect + +logging: + level: + sql: debug \ No newline at end of file diff --git a/be/overflow/src/main/resources/application-dev-security.yml b/be/overflow/src/main/resources/application-dev-security.yml new file mode 100644 index 0000000..8fac7d9 --- /dev/null +++ b/be/overflow/src/main/resources/application-dev-security.yml @@ -0,0 +1,9 @@ +security: + jwt: + token: + access: + secretKey: asccesssecretkeyoverflowsecrekey + validTime: 18000 + refresh: + secretKey: refreshsecretkeyoverflowsecrekey + validTime: 604800 \ No newline at end of file diff --git a/be/overflow/src/main/resources/application.yml b/be/overflow/src/main/resources/application.yml index 9c6d7ea..ab7a867 100644 --- a/be/overflow/src/main/resources/application.yml +++ b/be/overflow/src/main/resources/application.yml @@ -4,5 +4,7 @@ spring: local: - local-mysql - local-security - + dev: + - dev-mysql + - dev-security active: local \ No newline at end of file From 4c709ca1e79bc174440263cf165be32839ec4155 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Thu, 5 Oct 2023 02:51:15 +0900 Subject: [PATCH 03/31] =?UTF-8?q?feat=20:=20docker=20file=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/overflow/Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 be/overflow/Dockerfile diff --git a/be/overflow/Dockerfile b/be/overflow/Dockerfile new file mode 100644 index 0000000..a22b500 --- /dev/null +++ b/be/overflow/Dockerfile @@ -0,0 +1,4 @@ +FROM openjdk:17-oracle +ARG JAR_FILE=/build/libs/overflow-0.0.1-SNAPSHOT.jar +COPY ${JAR_FILE} app.jar +ENTRYPOINT ["java", "-jar", "/app.jar"] \ No newline at end of file From 311b07c1b04b3f6d9e045266fad1ec6161395c43 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Thu, 5 Oct 2023 02:51:32 +0900 Subject: [PATCH 04/31] =?UTF-8?q?feat=20:=20docker-compose=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/overflow/docker-compose.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 be/overflow/docker-compose.yml diff --git a/be/overflow/docker-compose.yml b/be/overflow/docker-compose.yml new file mode 100644 index 0000000..c366680 --- /dev/null +++ b/be/overflow/docker-compose.yml @@ -0,0 +1,33 @@ +version: '3.1' +services: + mysql: + container_name: overflow-mysql-dev + image: mysql/mysql-server:8.0.27 + environment: + - MYSQL_DATABASE=overflow + - MYSQL_ROOT_HOST=% + - MYSQL_ROOT_PASSWORD=root + command: [ "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci", "--lower_case_table_names=1", "--max_connections=2048", "--wait_timeout=3600" ] + ports: + - "13307:3306" + volumes: #볼륨 지정 + - ./resources/develop-environment/mysql-init.d:/docker-entrypoint-initdb.d + networks: #사용할 네트워크 지정 + - overflow-network + backend: + build: + context: . + dockerfile: Dockerfile + container_name: overflow-app-dev + depends_on: + - mysql + restart: always + environment: + SPRING_DATASOURCE_URL: jdbc:mysql://overflow-mysql-dev:3306/overflow?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false&allowPublicKeyRetrieval=true + SPRING_DATASOURCE_USERNAME: root + SPRING_DATASOURCE_PASSWORD: root + SPRING_PROFILES_ACTIVE: dev + networks: #사용할 네트워크 지정 + - overflow-network +networks: + overflow-network: From 6e6710e98180eb5cc404d14f315febcee653ba54 Mon Sep 17 00:00:00 2001 From: capDoYeonLee Date: Thu, 5 Oct 2023 03:48:07 +0900 Subject: [PATCH 05/31] =?UTF-8?q?fix=20:=20create=20database=20sql?= =?UTF-8?q?=EB=AC=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/develop-environment/mysql-init.d/00_init.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/be/overflow/resources/develop-environment/mysql-init.d/00_init.sql b/be/overflow/resources/develop-environment/mysql-init.d/00_init.sql index c0889b6..bb4146a 100755 --- a/be/overflow/resources/develop-environment/mysql-init.d/00_init.sql +++ b/be/overflow/resources/develop-environment/mysql-init.d/00_init.sql @@ -8,6 +8,6 @@ GRANT ALL PRIVILEGES ON *.* TO GRANT ALL PRIVILEGES ON *.* TO 'overflow-local'@'%'; -CREATE - DATABASE overflow DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +-- CREATE +-- DATABASE overflow DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; From 90528d2f71778a648a88686cf42e9bddc2deedbc Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Thu, 5 Oct 2023 17:20:29 +0900 Subject: [PATCH 06/31] =?UTF-8?q?fix=20:=20active=20on=20profile=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev-security.yml | 7 ++++++- .../src/main/resources/application-local-security.yml | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/be/overflow/src/main/resources/application-dev-security.yml b/be/overflow/src/main/resources/application-dev-security.yml index 8fac7d9..1de79de 100644 --- a/be/overflow/src/main/resources/application-dev-security.yml +++ b/be/overflow/src/main/resources/application-dev-security.yml @@ -1,3 +1,8 @@ +spring: + config: + activate: + on-profile: dev-security + security: jwt: token: @@ -6,4 +11,4 @@ security: validTime: 18000 refresh: secretKey: refreshsecretkeyoverflowsecrekey - validTime: 604800 \ No newline at end of file + validTime: 604800 diff --git a/be/overflow/src/main/resources/application-local-security.yml b/be/overflow/src/main/resources/application-local-security.yml index a966ab8..69d5eff 100644 --- a/be/overflow/src/main/resources/application-local-security.yml +++ b/be/overflow/src/main/resources/application-local-security.yml @@ -1,3 +1,8 @@ +spring: + config: + activate: + on-profile: local-security + security: jwt: token: From a355277bd6ae11cef82c33e5d4392201c398dc4a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 6 Oct 2023 01:21:19 +0000 Subject: [PATCH 07/31] =?UTF-8?q?fix=20:=20docker-compose.yml=20=ED=8F=AC?= =?UTF-8?q?=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/overflow/docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/be/overflow/docker-compose.yml b/be/overflow/docker-compose.yml index c366680..0b2d321 100644 --- a/be/overflow/docker-compose.yml +++ b/be/overflow/docker-compose.yml @@ -19,6 +19,8 @@ services: context: . dockerfile: Dockerfile container_name: overflow-app-dev + ports: + - "8080:8080" depends_on: - mysql restart: always From ab0b48d66e37f91df74f40008dac97fdb79e6ef7 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 16:24:54 +0900 Subject: [PATCH 08/31] =?UTF-8?q?fix=20:=20dev,=20local=EC=8B=9C=20validTi?= =?UTF-8?q?me=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20refreshtoken=20secretkey?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev-security.yml | 8 ++++---- .../src/main/resources/application-local-security.yml | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/be/overflow/src/main/resources/application-dev-security.yml b/be/overflow/src/main/resources/application-dev-security.yml index 1de79de..84dbfe7 100644 --- a/be/overflow/src/main/resources/application-dev-security.yml +++ b/be/overflow/src/main/resources/application-dev-security.yml @@ -6,9 +6,9 @@ spring: security: jwt: token: + secretKey: asccesssecretkeyoverflowsecrekey access: - secretKey: asccesssecretkeyoverflowsecrekey - validTime: 18000 + validTime: 180 refresh: - secretKey: refreshsecretkeyoverflowsecrekey - validTime: 604800 + validTime : 360 + diff --git a/be/overflow/src/main/resources/application-local-security.yml b/be/overflow/src/main/resources/application-local-security.yml index 69d5eff..74b6dfd 100644 --- a/be/overflow/src/main/resources/application-local-security.yml +++ b/be/overflow/src/main/resources/application-local-security.yml @@ -6,9 +6,8 @@ spring: security: jwt: token: + secretKey: asccesssecretkeyoverflowsecrekey access: - secretKey: asccesssecretkeyoverflowsecrekey validTime: 1800000 refresh: - secretKey: refreshsecretkeyoverflowsecrekey - validTime: 604800000 \ No newline at end of file + validTime: 3600000 \ No newline at end of file From bafb410028a464890a83cf21f758b59287d3316e Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 16:28:09 +0900 Subject: [PATCH 09/31] =?UTF-8?q?fix=20:=20table=EB=AA=85=20=EB=B3=84?= =?UTF-8?q?=EB=8F=84=EB=A1=9C=20=EC=A7=80=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/entity/AuthInfoEntity.java | 32 ++++++++++--------- .../auth/persistence/entity/UserEntity.java | 2 ++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/AuthInfoEntity.java b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/AuthInfoEntity.java index 58f5abe..779a29d 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/AuthInfoEntity.java +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/AuthInfoEntity.java @@ -2,7 +2,6 @@ import static com.econovation.overflow.auth.persistence.entity.AuthInfoEntity.ENTITY_PREFIX; -import com.econovation.overflow.common.BaseEntity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -10,6 +9,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -24,23 +25,24 @@ @ToString @SuperBuilder(toBuilder = true) @Entity(name = ENTITY_PREFIX + "_entity") -public class AuthInfoEntity extends BaseEntity { +@Table(name = ENTITY_PREFIX + "tb") +public class AuthInfoEntity { - public static final String ENTITY_PREFIX = "auth_info"; + public static final String ENTITY_PREFIX = "auth_info"; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = ENTITY_PREFIX + "_id", nullable = false) - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = ENTITY_PREFIX + "_id", nullable = false) + private Long id; - @Builder.Default - @Enumerated(EnumType.STRING) - @Column(name = ENTITY_PREFIX + "_type", nullable = false) - private LoginType type = LoginType.SERVICE; + @Builder.Default + @Enumerated(EnumType.STRING) + @Column(name = ENTITY_PREFIX + "_type", nullable = false) + private LoginType type = LoginType.SERVICE; - @Column(name = "user_id", nullable = false) - private Long userId; + @Column(name = "user_id", nullable = false) + private Long userId; - @Column(name = ENTITY_PREFIX + "_token", nullable = false) - private String token; + @Column(name = ENTITY_PREFIX + "_token", nullable = false) + private String token; } diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java index f657e75..9e8a643 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java @@ -8,6 +8,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; @@ -21,6 +22,7 @@ @ToString @SuperBuilder(toBuilder = true) @Entity(name = ENTITY_PREFIX + "_entity") +@Table(name=ENTITY_PREFIX+"tb") public class UserEntity extends BaseEntity { public static final String ENTITY_PREFIX = "user"; From 5d166788d82de72f65807add75780842b9ef1789 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 16:31:26 +0900 Subject: [PATCH 10/31] =?UTF-8?q?feat=20:=20nickname,=20email=20unique=20i?= =?UTF-8?q?ndex=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../overflow/auth/persistence/entity/UserEntity.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java index 9e8a643..d8cab0c 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java @@ -8,6 +8,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Index; import javax.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -22,7 +23,10 @@ @ToString @SuperBuilder(toBuilder = true) @Entity(name = ENTITY_PREFIX + "_entity") -@Table(name=ENTITY_PREFIX+"tb") +@Table(name = ENTITY_PREFIX + "tb", indexes = { + @Index(name="idx_nickname", columnList = "nickname", unique = true), + @Index(name="idx_email", columnList = "email", unique = true) +}) public class UserEntity extends BaseEntity { public static final String ENTITY_PREFIX = "user"; From d23b1eb67cfc1fad9ffc061d8576cb0dd2142303 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 16:49:34 +0900 Subject: [PATCH 11/31] =?UTF-8?q?fix=20:=20usercontroller=20->=20authcontr?= =?UTF-8?q?oller=EB=A1=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...oginController.java => AuthController.java} | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) rename be/overflow/src/main/java/com/econovation/overflow/auth/web/controller/{LoginController.java => AuthController.java} (72%) diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/web/controller/LoginController.java b/be/overflow/src/main/java/com/econovation/overflow/auth/web/controller/AuthController.java similarity index 72% rename from be/overflow/src/main/java/com/econovation/overflow/auth/web/controller/LoginController.java rename to be/overflow/src/main/java/com/econovation/overflow/auth/web/controller/AuthController.java index bb6c8a5..3e7dcb0 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/auth/web/controller/LoginController.java +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/web/controller/AuthController.java @@ -3,10 +3,13 @@ import com.econovation.overflow.auth.domain.dto.request.LoginUserRequest; import com.econovation.overflow.auth.domain.dto.response.TokenResponse; import com.econovation.overflow.auth.domain.usecase.LoginUserUseCase; +import com.econovation.overflow.auth.domain.usecase.ReissueUseCase; +import com.econovation.overflow.auth.web.support.CookieExtractor; import com.econovation.overflow.common.support.respnose.ApiResponse; import com.econovation.overflow.common.support.respnose.ApiResponseBody.SuccessBody; import com.econovation.overflow.common.support.respnose.ApiResponseGenerator; import com.econovation.overflow.common.support.respnose.MessageCode; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -19,10 +22,12 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/auth") -public class LoginController { +public class AuthController { private static final String REFRESH_TOKEN = "refreshToken"; private static final int REFRESH_TOKEN_EXPIRATION = 7 * 24 * 60 * 60; private final LoginUserUseCase loginUserUseCase; + private final ReissueUseCase reissueUseCase; + private final CookieExtractor cookieExtractor; @PostMapping("/login") public ApiResponse> signIn( @@ -33,6 +38,17 @@ public ApiResponse> signIn( tokenResponse, HttpStatus.OK, MessageCode.CREATE, cookie.toString()); } + @PostMapping("/reissue") + public ApiResponse> reissue(HttpServletRequest request) { + + final String token = cookieExtractor.extract(request); + final TokenResponse tokenResponse = reissueUseCase.execute(token); + final ResponseCookie cookie = putTokenInCookie(tokenResponse); + + return ApiResponseGenerator.success( + tokenResponse, HttpStatus.OK, MessageCode.CREATE, cookie.toString()); + } + private ResponseCookie putTokenInCookie(final TokenResponse tokenResponse) { return ResponseCookie.from(REFRESH_TOKEN, tokenResponse.getRefreshToken()) .maxAge(REFRESH_TOKEN_EXPIRATION) From 4f89d4b9c1a8ca0d1cdffdc59b220a1327cd5dc0 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 16:50:04 +0900 Subject: [PATCH 12/31] =?UTF-8?q?feat=20:=20email,=20nickname=EC=97=90=20i?= =?UTF-8?q?ndex=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../overflow/auth/persistence/entity/UserEntity.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java index d8cab0c..50415f6 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java @@ -23,10 +23,12 @@ @ToString @SuperBuilder(toBuilder = true) @Entity(name = ENTITY_PREFIX + "_entity") -@Table(name = ENTITY_PREFIX + "tb", indexes = { - @Index(name="idx_nickname", columnList = "nickname", unique = true), - @Index(name="idx_email", columnList = "email", unique = true) -}) +@Table( + name = ENTITY_PREFIX + "tb", + indexes = { + @Index(name = "idx_nickname", columnList = "nickname", unique = true), + @Index(name = "idx_email", columnList = "email", unique = true) + }) public class UserEntity extends BaseEntity { public static final String ENTITY_PREFIX = "user"; From b5b9125cfaa9075467634ecfb458124f8ee91ed1 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 16:51:19 +0900 Subject: [PATCH 13/31] =?UTF-8?q?fix=20:=20refreshtoken=EC=8B=9C=20userrol?= =?UTF-8?q?e=20=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20refreshtoken,=20accessToke?= =?UTF-8?q?n=20secretkey=20=EB=8F=99=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/token/TokenProvider.java | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenProvider.java b/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenProvider.java index 5223ddf..064c549 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenProvider.java +++ b/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenProvider.java @@ -14,31 +14,20 @@ @Component public class TokenProvider { - private static final String USER_ID_CLAIM_KEY = "memberId"; + private static final String USER_ID_CLAIM_KEY = "userId"; private static final String USER_ROLE_CLAIM_KEY = "memberRole"; - private final SecretKey accessSecretKey; + private final SecretKey secretKey; - private final long accessValidTime; - private final SecretKey refreshSecretKey; - - private final long refreshValidTime; + private final long validTime; public TokenProvider( - @Value("${security.jwt.token.access.secretKey}") String accessSecretKey, - @Value("${security.jwt.token.access.validTime}") long accessValidTime, - @Value("${security.jwt.token.refresh.secretKey}") String refreshSecretKey, - @Value("${security.jwt.token.refresh.validTime}") long refreshValidTime) { - this.accessSecretKey = Keys.hmacShaKeyFor(accessSecretKey.getBytes(StandardCharsets.UTF_8)); - this.accessValidTime = accessValidTime; - this.refreshSecretKey = Keys.hmacShaKeyFor(refreshSecretKey.getBytes(StandardCharsets.UTF_8)); - this.refreshValidTime = refreshValidTime; + @Value("${security.jwt.token.secretKey}") String secretKey, + @Value("${security.jwt.token.validTime}") long validTime) { + this.secretKey = Keys.hmacShaKeyFor(secretKey.getBytes(StandardCharsets.UTF_8)); + this.validTime = validTime; } - private String createToken( - final Long userId, - final List userRoles, - final SecretKey secretKey, - final long validTime) { + public String createAccessToken(final Long userId, final List userRoles) { final Date now = new Date(); return Jwts.builder() @@ -51,11 +40,15 @@ private String createToken( .compact(); } - public String createAccessToken(final Long userId, final List userRoles) { - return createToken(userId, userRoles, accessSecretKey, accessValidTime); - } + public String createRefreshToken(final Long userId) { + final Date now = new Date(); - public String createRefreshToken(final Long userId, final List userRoles) { - return createToken(userId, userRoles, refreshSecretKey, refreshValidTime); + return Jwts.builder() + .setHeaderParam(Header.TYPE, Header.JWT_TYPE) + .claim(USER_ID_CLAIM_KEY, userId) + .setIssuedAt(now) + .setExpiration(new Date(now.getTime() + validTime)) + .signWith(secretKey) + .compact(); } } From 8c8422f3fbe0074b8fb7674b9a33cd3589335afb Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 20:27:38 +0900 Subject: [PATCH 14/31] =?UTF-8?q?fix=20:=20access,=20refresh=20token=20val?= =?UTF-8?q?idTime=20=EB=B3=84=EB=8F=84=EB=A1=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../overflow/security/token/TokenProvider.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenProvider.java b/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenProvider.java index 064c549..9f9a469 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenProvider.java +++ b/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenProvider.java @@ -18,24 +18,26 @@ public class TokenProvider { private static final String USER_ROLE_CLAIM_KEY = "memberRole"; private final SecretKey secretKey; - private final long validTime; + private final long accessValidTime; + private final long refreshValidTime; public TokenProvider( @Value("${security.jwt.token.secretKey}") String secretKey, - @Value("${security.jwt.token.validTime}") long validTime) { + @Value("${security.jwt.token.access.validTime}") long accessValidTime, + @Value("${security.jwt.token.refresh.validTime}") long refreshValidTime) { this.secretKey = Keys.hmacShaKeyFor(secretKey.getBytes(StandardCharsets.UTF_8)); - this.validTime = validTime; + this.accessValidTime = accessValidTime; + this.refreshValidTime = refreshValidTime; } public String createAccessToken(final Long userId, final List userRoles) { - final Date now = new Date(); - + Date now = new Date(); return Jwts.builder() .setHeaderParam(Header.TYPE, Header.JWT_TYPE) .claim(USER_ID_CLAIM_KEY, userId) .claim(USER_ROLE_CLAIM_KEY, userRoles.toString()) .setIssuedAt(now) - .setExpiration(new Date(now.getTime() + validTime)) + .setExpiration(new Date(now.getTime() + accessValidTime)) .signWith(secretKey) .compact(); } @@ -47,7 +49,7 @@ public String createRefreshToken(final Long userId) { .setHeaderParam(Header.TYPE, Header.JWT_TYPE) .claim(USER_ID_CLAIM_KEY, userId) .setIssuedAt(now) - .setExpiration(new Date(now.getTime() + validTime)) + .setExpiration(new Date(now.getTime() + refreshValidTime)) .signWith(secretKey) .compact(); } From 95fc9ae27eb177aff4f2f666f788651c34e89472 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 20:28:29 +0900 Subject: [PATCH 15/31] =?UTF-8?q?feat=20:=20=ED=86=A0=ED=81=B0=20=EB=A7=8C?= =?UTF-8?q?=EB=A3=8C=EC=8B=9C=EA=B0=84=EC=9D=B4=20=EC=A7=80=EB=82=AC?= =?UTF-8?q?=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/token/TokenResolver.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenResolver.java b/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenResolver.java index 0853313..94f184f 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenResolver.java +++ b/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenResolver.java @@ -2,10 +2,12 @@ import com.econovation.overflow.security.exception.NotValidToken; import io.jsonwebtoken.Claims; +import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.security.Keys; import java.nio.charset.StandardCharsets; import java.util.Date; +import java.util.Objects; import javax.crypto.SecretKey; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -13,31 +15,29 @@ @Component public class TokenResolver { - private static final String USER_ID_CLAIM_KEY = "memberId"; - private static final String USER_ROLE_CLAIM_KEY = "memberRole"; - private final SecretKey accessSecretKey; - private final SecretKey refreshSecretKey; + private static final String USER_ID_CLAIM_KEY = "userId"; + private final SecretKey secretKey; - public TokenResolver( - @Value("${security.jwt.token.access.secretKey}") String accessSecretKey, - @Value("${security.jwt.token.refresh.secretKey}") String refreshSecretKey) { - this.accessSecretKey = Keys.hmacShaKeyFor(accessSecretKey.getBytes(StandardCharsets.UTF_8)); - this.refreshSecretKey = Keys.hmacShaKeyFor(refreshSecretKey.getBytes(StandardCharsets.UTF_8)); + public TokenResolver(@Value("${security.jwt.token.secretKey}") String accessSecretKey) { + this.secretKey = Keys.hmacShaKeyFor(accessSecretKey.getBytes(StandardCharsets.UTF_8)); } private Claims getClaims(final String token) { try { - return Jwts.parserBuilder() - .setSigningKey(accessSecretKey) - .build() - .parseClaimsJws(token) - .getBody(); - } catch (Exception e) { - throw new NotValidToken("유효하지 않은 토큰입니다."); + return Jwts.parserBuilder().setSigningKey(secretKey).build().parseClaimsJws(token).getBody(); + } catch (ExpiredJwtException e) { + throw new NotValidToken("만료된 토큰입니다"); } } public Date getExpiredDate(final String token) { + Objects.requireNonNull(token); return getClaims(token).getExpiration(); } + + public Long getUserInfo(final String token) { + Objects.requireNonNull(token); + + return Long.valueOf(String.valueOf(getClaims(token).get(USER_ID_CLAIM_KEY))); + } } From 9c6916029340c2f335f924484e500990313e19f1 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 20:30:16 +0900 Subject: [PATCH 16/31] =?UTF-8?q?feat=20:=20=ED=86=A0=ED=81=B0=EC=9D=B4=20?= =?UTF-8?q?=EB=A7=8C=EB=A3=8C=EB=90=98=EC=97=88=EB=8A=94=EC=A7=80=20valida?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/token/TokenValidator.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenValidator.java b/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenValidator.java index b89a422..ebcbeae 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenValidator.java +++ b/be/overflow/src/main/java/com/econovation/overflow/security/token/TokenValidator.java @@ -1,11 +1,21 @@ package com.econovation.overflow.security.token; -public class TokenValidator {} - -/** - * Date tokenExpirationDate = claims.getBody().getExpiration(); - * validateTokenExpiration(tokenExpirationDate); - * - *

private void validateTokenExpiration(Date tokenExpirationDate) { if - * (tokenExpirationDate.before(new Date())) { throw new TokenExpirationException(); }* } - */ +import com.econovation.overflow.auth.domain.exception.AuthorizationException; +import java.util.Date; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class TokenValidator { + private final TokenResolver tokenResolver; + + public boolean isExpiredDate(String token) { + Date expiredDate = tokenResolver.getExpiredDate(token); + + if (expiredDate.before(new Date())) { + throw new AuthorizationException("토큰이 만료되었습니다"); + } + return false; + } +} From f349cd04650d8610e37ecd7caff8578a631f9b64 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 20:30:45 +0900 Subject: [PATCH 17/31] =?UTF-8?q?test=20:=20=ED=86=A0=ED=81=B0=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/token/TokenProviderTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 be/overflow/src/test/java/com/econovation/overflow/security/token/TokenProviderTest.java diff --git a/be/overflow/src/test/java/com/econovation/overflow/security/token/TokenProviderTest.java b/be/overflow/src/test/java/com/econovation/overflow/security/token/TokenProviderTest.java new file mode 100644 index 0000000..a551d72 --- /dev/null +++ b/be/overflow/src/test/java/com/econovation/overflow/security/token/TokenProviderTest.java @@ -0,0 +1,41 @@ +package com.econovation.overflow.security.token; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Collections; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class TokenProviderTest { + private static final String JWT_SECRET_KEY = "A".repeat(32); + private static final int ACCESS_EXPIRED_TIME = 3600; + private static final int REFRESH_EXPIRED_TIME = 3600; + private final TokenProvider tokenProvider = + new TokenProvider(JWT_SECRET_KEY, ACCESS_EXPIRED_TIME, REFRESH_EXPIRED_TIME); + + @Test + @DisplayName("엑세스 토큰을 생성한다.") + void create_accessToken() { + // given + Long userId = 1L; + + // when + String token = tokenProvider.createAccessToken(userId, Collections.emptyList()); + + // then + assertThat(token.split("\\.")).hasSize(3); + } + + @Test + @DisplayName("리프레시 토큰을 생성한다.") + void create_refreshToken() { + // given + Long userId = 1L; + + // when + String token = tokenProvider.createRefreshToken(userId); + + // then + assertThat(token.split("\\.")).hasSize(3); + } +} From 628e040bf0292080edeff687fadf3b620aad4921 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 20:31:04 +0900 Subject: [PATCH 18/31] =?UTF-8?q?test=20:=20=ED=86=A0=ED=81=B0=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/token/TokenResolverTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 be/overflow/src/test/java/com/econovation/overflow/security/token/TokenResolverTest.java diff --git a/be/overflow/src/test/java/com/econovation/overflow/security/token/TokenResolverTest.java b/be/overflow/src/test/java/com/econovation/overflow/security/token/TokenResolverTest.java new file mode 100644 index 0000000..d9c31f5 --- /dev/null +++ b/be/overflow/src/test/java/com/econovation/overflow/security/token/TokenResolverTest.java @@ -0,0 +1,56 @@ +package com.econovation.overflow.security.token; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.econovation.overflow.security.exception.NotValidToken; +import java.util.Collections; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class TokenResolverTest { + private static final String JWT_SECRET_KEY = "A".repeat(32); + private static final int ACCESS_EXPIRED_TIME = 3600; + private static final int REFRESH_EXPIRED_TIME = 3600; + private final TokenProvider tokenProvider = + new TokenProvider(JWT_SECRET_KEY, ACCESS_EXPIRED_TIME, REFRESH_EXPIRED_TIME); + private final TokenResolver tokenResolver = new TokenResolver(JWT_SECRET_KEY); + + @Test + @DisplayName("토큰이 만료되지 않았을 경우 유저 정보를 가져온다") + void get_userInfo() { + // given + Long userId = 1L; + String token = tokenProvider.createAccessToken(userId, Collections.emptyList()); + + // when + Long userInfo = tokenResolver.getUserInfo(token); + + // then + assertThat(userInfo).isEqualTo(userId); + } + + @Test + @DisplayName("엑세스 토큰이 만료되면 예외를 터트린다.") + void get_userInfo_by_access_exception() { + // given + TokenProvider expiredTokenProvider = new TokenProvider(JWT_SECRET_KEY, 0, 0); + Long userId = 1L; + String token = expiredTokenProvider.createAccessToken(userId, Collections.emptyList()); + + // when & then + assertThatThrownBy(() -> tokenResolver.getUserInfo(token)).isInstanceOf(NotValidToken.class); + } + + @Test + @DisplayName("리프레시 토큰이 만료되면 예외를 터트린다.") + void get_userInfo_by_refresh_exception() { + // given + TokenProvider expiredTokenProvider = new TokenProvider(JWT_SECRET_KEY, 0, 0); + Long userId = 1L; + String token = expiredTokenProvider.createRefreshToken(userId); + + // when & then + assertThatThrownBy(() -> tokenResolver.getUserInfo(token)).isInstanceOf(NotValidToken.class); + } +} From 47d47d394a11e655af92426cf3e0e5d5eeec4fa9 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 20:57:15 +0900 Subject: [PATCH 19/31] =?UTF-8?q?feat=20:=20cookie=20=EC=97=90=EC=84=9C=20?= =?UTF-8?q?refresh=20token=20=EC=B6=94=EC=B6=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/web/support/CookieExtractor.java | 29 +++++++++++++++++++ .../auth/web/support/TokenExtractor.java | 7 +++++ 2 files changed, 36 insertions(+) create mode 100644 be/overflow/src/main/java/com/econovation/overflow/auth/web/support/CookieExtractor.java create mode 100644 be/overflow/src/main/java/com/econovation/overflow/auth/web/support/TokenExtractor.java diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/web/support/CookieExtractor.java b/be/overflow/src/main/java/com/econovation/overflow/auth/web/support/CookieExtractor.java new file mode 100644 index 0000000..007ea17 --- /dev/null +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/web/support/CookieExtractor.java @@ -0,0 +1,29 @@ +package com.econovation.overflow.auth.web.support; + +import com.econovation.overflow.auth.domain.exception.AuthorizationException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import org.springframework.stereotype.Component; + +@Component +public class CookieExtractor implements TokenExtractor { + + @Override + public String extract(HttpServletRequest request) { + Cookie[] cookies = request.getCookies(); + for (Cookie cookie : cookies) { + if (cookie.getName().equals("refreshToken")) { + String token = cookie.getValue(); + validNullToken(token); + return token; + } + } + throw new AuthorizationException("토큰이 존재하지 않습니다."); + } + + private void validNullToken(String token) { + if (token == null) { + throw new AuthorizationException("토큰이 존재하지 않습니다"); + } + } +} diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/web/support/TokenExtractor.java b/be/overflow/src/main/java/com/econovation/overflow/auth/web/support/TokenExtractor.java new file mode 100644 index 0000000..e023d63 --- /dev/null +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/web/support/TokenExtractor.java @@ -0,0 +1,7 @@ +package com.econovation.overflow.auth.web.support; + +import javax.servlet.http.HttpServletRequest; + +public interface TokenExtractor { + String extract(HttpServletRequest request); +} From 54e2c3c611299744e451b5e055e1c6bc0441d11e Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 21:19:55 +0900 Subject: [PATCH 20/31] =?UTF-8?q?test=20:=20cookie=20extractor=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/web/support/CookieExtractorTest.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java diff --git a/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java b/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java new file mode 100644 index 0000000..e813cc7 --- /dev/null +++ b/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java @@ -0,0 +1,48 @@ +package com.econovation.overflow.auth.web.support; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.*; + +import com.econovation.overflow.auth.domain.exception.AuthorizationException; +import javax.servlet.http.Cookie; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; +import org.springframework.mock.web.MockHttpServletRequest; + +@Import(CookieExtractor.class) +class CookieExtractorTest { + private static final String REFRESH_TOKEN_KEY = "refreshToken"; + private static final String JWT_TOKEN = "A".repeat(32); + + private final CookieExtractor cookieExtractor = new CookieExtractor(); + + @Test + @DisplayName("쿠키 key값이 존재할 경우 쿠키를 추출할 수 있다.") + void extract_cookie() { + // given + MockHttpServletRequest request = new MockHttpServletRequest(); + Cookie cookie = new Cookie(REFRESH_TOKEN_KEY, JWT_TOKEN); + request.setCookies(cookie); + + // when + String value = cookieExtractor.extract(request); + + // then + assertThat(value).isEqualTo(JWT_TOKEN); + } + + @Test + @DisplayName("쿠키 key에 value가 없을 경우 예외가 발생한다.") + void extract_cookie_exception() { + // given + MockHttpServletRequest request = new MockHttpServletRequest(); + Cookie cookie = new Cookie(REFRESH_TOKEN_KEY, null); + request.setCookies(cookie); + + // when & then + assertThatThrownBy(() -> cookieExtractor.extract(request)) + .isInstanceOf(AuthorizationException.class); + } +} From d7884cf2ea23d5a63368f52b99b14cf607a47886 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 21:21:27 +0900 Subject: [PATCH 21/31] =?UTF-8?q?fix=20:=20request=20header=EC=97=90=20coo?= =?UTF-8?q?kie=EC=9E=90=EC=B2=B4=EA=B0=80=20=EC=A1=B4=EC=9E=AC=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=9D=84=20=EB=95=8C=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/web/support/CookieExtractor.java | 30 ++++++++++++++----- .../auth/web/support/CookieExtractorTest.java | 11 +++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/web/support/CookieExtractor.java b/be/overflow/src/main/java/com/econovation/overflow/auth/web/support/CookieExtractor.java index 007ea17..5ee87ab 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/auth/web/support/CookieExtractor.java +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/web/support/CookieExtractor.java @@ -1,24 +1,40 @@ package com.econovation.overflow.auth.web.support; import com.econovation.overflow.auth.domain.exception.AuthorizationException; +import java.util.Arrays; +import java.util.Optional; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Component; @Component public class CookieExtractor implements TokenExtractor { + private static final String REFRESH_KEY = "refreshToken"; @Override public String extract(HttpServletRequest request) { + Cookie[] cookies = getCookies(request); + Optional tokenCookie = + Arrays.stream(cookies).filter(cookie -> cookie.getName().equals(REFRESH_KEY)).findAny(); + + Cookie refreshCookie = + tokenCookie.orElseThrow(() -> new AuthorizationException("토큰이 존재하지 않습니다.")); + + return getValue(refreshCookie); + } + + private Cookie[] getCookies(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); - for (Cookie cookie : cookies) { - if (cookie.getName().equals("refreshToken")) { - String token = cookie.getValue(); - validNullToken(token); - return token; - } + if (cookies == null) { + throw new AuthorizationException("토큰이 존재하지 않습니다"); } - throw new AuthorizationException("토큰이 존재하지 않습니다."); + return cookies; + } + + private String getValue(Cookie cookie) { + String token = cookie.getValue(); + validNullToken(token); + return token; } private void validNullToken(String token) { diff --git a/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java b/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java index e813cc7..f0febac 100644 --- a/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java +++ b/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java @@ -45,4 +45,15 @@ void extract_cookie_exception() { assertThatThrownBy(() -> cookieExtractor.extract(request)) .isInstanceOf(AuthorizationException.class); } + + @Test + @DisplayName("refresh token cookie가 존재하지 않을 경우 예외가 발생한다.") + void extract_cookie_not_found() { + // given + MockHttpServletRequest request = new MockHttpServletRequest(); + + // when & then + assertThatThrownBy(() -> cookieExtractor.extract(request)) + .isInstanceOf(AuthorizationException.class); + } } From af2d5e733d9e8f2dfb6e0fb6b9f30762d8bf9500 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 21:22:49 +0900 Subject: [PATCH 22/31] =?UTF-8?q?test/fix=20:=20header=EC=97=90=20cookie?= =?UTF-8?q?=EA=B0=80=20=EC=A1=B4=EC=9E=AC=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20=EC=98=88=EC=99=B8=EB=B0=9C=EC=83=9D?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20name=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../overflow/auth/web/support/CookieExtractorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java b/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java index f0febac..0da78cd 100644 --- a/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java +++ b/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java @@ -47,7 +47,7 @@ void extract_cookie_exception() { } @Test - @DisplayName("refresh token cookie가 존재하지 않을 경우 예외가 발생한다.") + @DisplayName("request에 cookie가 존재하지 않을 경우 예외가 발생한다.") void extract_cookie_not_found() { // given MockHttpServletRequest request = new MockHttpServletRequest(); From ede4c5ecaa101acd6c975c24e0e18a5882e9e194 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 21:25:12 +0900 Subject: [PATCH 23/31] =?UTF-8?q?test/feat=20:=20refresh=20token=20cookie?= =?UTF-8?q?=EA=B0=80=20=EC=A1=B4=EC=9E=AC=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/web/support/CookieExtractorTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java b/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java index 0da78cd..30602ff 100644 --- a/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java +++ b/be/overflow/src/test/java/com/econovation/overflow/auth/web/support/CookieExtractorTest.java @@ -56,4 +56,20 @@ void extract_cookie_not_found() { assertThatThrownBy(() -> cookieExtractor.extract(request)) .isInstanceOf(AuthorizationException.class); } + + @Test + @DisplayName("refresh token cookie가 존재하지 않을 경우 예외가 발생한다.") + void extract_refresh_cookie_not_found() { + // given + String key = "key"; + String value = "value"; + + MockHttpServletRequest request = new MockHttpServletRequest(); + Cookie cookie = new Cookie(key, value); + request.setCookies(cookie); + + // when & then + assertThatThrownBy(() -> cookieExtractor.extract(request)) + .isInstanceOf(AuthorizationException.class); + } } From 345ef66ca054f07bbb6b1ac15429912f46290ac0 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 22:20:59 +0900 Subject: [PATCH 24/31] =?UTF-8?q?feat=20:=20userid,=20token=EC=97=90=20?= =?UTF-8?q?=ED=95=B4=EB=8B=B9=ED=95=98=EB=8A=94=20entity=EA=B0=80=EC=A0=B8?= =?UTF-8?q?=EC=98=A4=EA=B8=B0=20repository=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/persistence/repository/AuthInfoRepository.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/repository/AuthInfoRepository.java b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/repository/AuthInfoRepository.java index 36defcf..055abc5 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/repository/AuthInfoRepository.java +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/repository/AuthInfoRepository.java @@ -1,6 +1,9 @@ package com.econovation.overflow.auth.persistence.repository; import com.econovation.overflow.auth.persistence.entity.AuthInfoEntity; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -public interface AuthInfoRepository extends JpaRepository {} +public interface AuthInfoRepository extends JpaRepository { + Optional findByUserIdAndToken(Long userId, String token); +} From 8e20c5c7dc5aa4b5aecf77007005625227e65a00 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 22:55:32 +0900 Subject: [PATCH 25/31] =?UTF-8?q?fix=20:=20table=20=EB=AA=85=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 --- .../persistence/entity/AuthInfoEntity.java | 29 +++++++++---------- .../auth/persistence/entity/UserEntity.java | 6 ++-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/AuthInfoEntity.java b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/AuthInfoEntity.java index 779a29d..871f268 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/AuthInfoEntity.java +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/AuthInfoEntity.java @@ -9,7 +9,6 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; -import javax.persistence.Index; import javax.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -25,24 +24,24 @@ @ToString @SuperBuilder(toBuilder = true) @Entity(name = ENTITY_PREFIX + "_entity") -@Table(name = ENTITY_PREFIX + "tb") +@Table(name = ENTITY_PREFIX + "_tb") public class AuthInfoEntity { - public static final String ENTITY_PREFIX = "auth_info"; + public static final String ENTITY_PREFIX = "auth_info"; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = ENTITY_PREFIX + "_id", nullable = false) - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = ENTITY_PREFIX + "_id", nullable = false) + private Long id; - @Builder.Default - @Enumerated(EnumType.STRING) - @Column(name = ENTITY_PREFIX + "_type", nullable = false) - private LoginType type = LoginType.SERVICE; + @Builder.Default + @Enumerated(EnumType.STRING) + @Column(name = ENTITY_PREFIX + "_type", nullable = false) + private LoginType type = LoginType.SERVICE; - @Column(name = "user_id", nullable = false) - private Long userId; + @Column(name = "user_id", nullable = false) + private Long userId; - @Column(name = ENTITY_PREFIX + "_token", nullable = false) - private String token; + @Column(name = ENTITY_PREFIX + "_token", nullable = false) + private String token; } diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java index 50415f6..beb0cca 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/persistence/entity/UserEntity.java @@ -24,10 +24,10 @@ @SuperBuilder(toBuilder = true) @Entity(name = ENTITY_PREFIX + "_entity") @Table( - name = ENTITY_PREFIX + "tb", + name = ENTITY_PREFIX + "_tb", indexes = { - @Index(name = "idx_nickname", columnList = "nickname", unique = true), - @Index(name = "idx_email", columnList = "email", unique = true) + @Index(name = "idx_nickname", columnList = ENTITY_PREFIX + "_nickname", unique = true), + @Index(name = "idx_email", columnList = ENTITY_PREFIX + "_email", unique = true) }) public class UserEntity extends BaseEntity { From 1374f34cc4a70b2407e3cd34ab90499ef1979400 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 23:25:39 +0900 Subject: [PATCH 26/31] =?UTF-8?q?feat=20:=20token=20=EC=83=9D=EC=84=B1=20s?= =?UTF-8?q?ervice=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/service/CreateTokenService.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 be/overflow/src/main/java/com/econovation/overflow/auth/domain/service/CreateTokenService.java diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/domain/service/CreateTokenService.java b/be/overflow/src/main/java/com/econovation/overflow/auth/domain/service/CreateTokenService.java new file mode 100644 index 0000000..9dc6bf8 --- /dev/null +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/domain/service/CreateTokenService.java @@ -0,0 +1,42 @@ +package com.econovation.overflow.auth.domain.service; + +import com.econovation.overflow.auth.domain.dto.converter.TokenConverter; +import com.econovation.overflow.auth.domain.dto.response.TokenResponse; +import com.econovation.overflow.auth.persistence.converter.AuthInfoEntityConverter; +import com.econovation.overflow.auth.persistence.entity.AuthInfoEntity; +import com.econovation.overflow.auth.persistence.repository.AuthInfoRepository; +import com.econovation.overflow.security.authority.UserRole; +import com.econovation.overflow.security.token.TokenProvider; +import com.econovation.overflow.security.token.TokenResolver; +import java.util.Collections; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class CreateTokenService { + private final TokenProvider tokenProvider; + private final TokenConverter tokenConverter; + private final TokenResolver tokenResolver; + private final AuthInfoRepository authInfoRepository; + private final AuthInfoEntityConverter authInfoEntityConverter; + + @Transactional + public TokenResponse execute(final Long userId) { + String accessToken = + tokenProvider.createAccessToken(userId, Collections.singletonList(UserRole.USER)); + String refreshToken = tokenProvider.createRefreshToken(userId); + + saveToken(userId, refreshToken); + + return tokenConverter.from( + accessToken, tokenResolver.getExpiredDate(accessToken), refreshToken); + } + + private void saveToken(Long userId, String token) { + AuthInfoEntity authInfoEntity = authInfoEntityConverter.from(userId, token); + authInfoRepository.save(authInfoEntity); + } +} From 8e3fe6443acaaa607afd3adc592fcf9540cec26c Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 23:26:11 +0900 Subject: [PATCH 27/31] =?UTF-8?q?feat=20:=20authorization=20exception=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/domain/exception/AuthorizationException.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 be/overflow/src/main/java/com/econovation/overflow/auth/domain/exception/AuthorizationException.java diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/domain/exception/AuthorizationException.java b/be/overflow/src/main/java/com/econovation/overflow/auth/domain/exception/AuthorizationException.java new file mode 100644 index 0000000..05a0ace --- /dev/null +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/domain/exception/AuthorizationException.java @@ -0,0 +1,11 @@ +package com.econovation.overflow.auth.domain.exception; + +import com.econovation.overflow.common.exception.BusinessException; +import org.springframework.http.HttpStatus; + +public class AuthorizationException extends BusinessException { + + public AuthorizationException(String message) { + super(message, HttpStatus.NOT_FOUND); + } +} From 45b373a78a3a291ea223f15bbbf09a70b1ada0e9 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 23:26:49 +0900 Subject: [PATCH 28/31] =?UTF-8?q?fix=20:=20createTokenService=EB=A1=9C=20t?= =?UTF-8?q?oken=20=EC=83=9D=EC=84=B1=20=EC=B1=85=EC=9E=84=20=ED=95=A0?= =?UTF-8?q?=EB=8B=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/domain/usecase/LoginUserUseCase.java | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/LoginUserUseCase.java b/be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/LoginUserUseCase.java index 932163f..a9db96c 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/LoginUserUseCase.java +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/LoginUserUseCase.java @@ -1,17 +1,12 @@ package com.econovation.overflow.auth.domain.usecase; -import com.econovation.overflow.auth.domain.dto.converter.TokenConverter; import com.econovation.overflow.auth.domain.dto.request.LoginUserRequest; import com.econovation.overflow.auth.domain.dto.response.TokenResponse; import com.econovation.overflow.auth.domain.exception.NotFoundEmailException; import com.econovation.overflow.auth.domain.exception.NotFoundPasswordException; -import com.econovation.overflow.auth.domain.service.SaveTokenService; +import com.econovation.overflow.auth.domain.service.CreateTokenService; import com.econovation.overflow.auth.persistence.entity.UserEntity; import com.econovation.overflow.auth.persistence.repository.UserRepository; -import com.econovation.overflow.security.authority.UserRole; -import com.econovation.overflow.security.token.TokenProvider; -import com.econovation.overflow.security.token.TokenResolver; -import java.util.Collections; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; @@ -22,12 +17,9 @@ @Transactional(readOnly = true) public class LoginUserUseCase { - private final TokenProvider tokenProvider; private final UserRepository userRepository; private final PasswordEncoder passwordEncoder; - private final TokenConverter tokenConverter; - private final TokenResolver tokenResolver; - private final SaveTokenService saveTokenService; + private final CreateTokenService createTokenService; @Transactional public TokenResponse execute(final LoginUserRequest request) { @@ -38,17 +30,7 @@ public TokenResponse execute(final LoginUserRequest request) { validPassword(request.getPassword(), userEntity); - String accessToken = - tokenProvider.createAccessToken( - userEntity.getId(), Collections.singletonList(UserRole.USER)); - String refreshToken = - tokenProvider.createRefreshToken( - userEntity.getId(), Collections.singletonList(UserRole.USER)); - - saveTokenService.execute(userEntity.getId(), refreshToken); - - return tokenConverter.from( - accessToken, tokenResolver.getExpiredDate(accessToken), refreshToken); + return createTokenService.execute(userEntity.getId()); } private void validPassword(final String requestPassword, final UserEntity userEntity) { From 22d69d35509265ab5290e2252abbeb6a20adc18e Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Fri, 6 Oct 2023 23:27:31 +0900 Subject: [PATCH 29/31] =?UTF-8?q?feat=20:=20token,=20user=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=9D=BC=EC=B9=98=20=EC=8B=9C=20=EC=83=88=EB=A1=9C?= =?UTF-8?q?=EC=9A=B4=20token=20=EB=B0=9C=EA=B8=89=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/domain/usecase/ReissueUseCase.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCase.java diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCase.java b/be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCase.java new file mode 100644 index 0000000..1023f29 --- /dev/null +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCase.java @@ -0,0 +1,32 @@ +package com.econovation.overflow.auth.domain.usecase; + +import com.econovation.overflow.auth.domain.dto.response.TokenResponse; +import com.econovation.overflow.auth.domain.exception.AuthorizationException; +import com.econovation.overflow.auth.domain.service.CreateTokenService; +import com.econovation.overflow.auth.persistence.repository.AuthInfoRepository; +import com.econovation.overflow.security.token.TokenResolver; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +@Slf4j +public class ReissueUseCase { + private final CreateTokenService createTokenService; + private final TokenResolver tokenResolver; + private final AuthInfoRepository authInfoRepository; + + @Transactional + public TokenResponse execute(final String token) { + Long userId = tokenResolver.getUserInfo(token); + + authInfoRepository + .findByUserIdAndToken(userId, token) + .orElseThrow(() -> new AuthorizationException("잘못된 토큰 입니다")); + + return createTokenService.execute(userId); + } +} From 0ec36d59839919ead20c643003fdce034032742c Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Sat, 7 Oct 2023 00:03:11 +0900 Subject: [PATCH 30/31] =?UTF-8?q?fix=20:=20token=20=EC=9E=AC=EB=B0=9C?= =?UTF-8?q?=EA=B8=89=20=EC=8B=9C=20=EA=B8=B0=EC=A1=B4=20=ED=86=A0=ED=81=B0?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../overflow/auth/domain/usecase/ReissueUseCase.java | 4 +++- .../overflow/auth/domain/usecase/ReissueUseCaseTest.java | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 be/overflow/src/test/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCaseTest.java diff --git a/be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCase.java b/be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCase.java index 1023f29..2ce601c 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCase.java +++ b/be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCase.java @@ -3,6 +3,7 @@ import com.econovation.overflow.auth.domain.dto.response.TokenResponse; import com.econovation.overflow.auth.domain.exception.AuthorizationException; import com.econovation.overflow.auth.domain.service.CreateTokenService; +import com.econovation.overflow.auth.persistence.entity.AuthInfoEntity; import com.econovation.overflow.auth.persistence.repository.AuthInfoRepository; import com.econovation.overflow.security.token.TokenResolver; import lombok.RequiredArgsConstructor; @@ -23,10 +24,11 @@ public class ReissueUseCase { public TokenResponse execute(final String token) { Long userId = tokenResolver.getUserInfo(token); - authInfoRepository + AuthInfoEntity authInfoEntity = authInfoRepository .findByUserIdAndToken(userId, token) .orElseThrow(() -> new AuthorizationException("잘못된 토큰 입니다")); + authInfoRepository.delete(authInfoEntity); return createTokenService.execute(userId); } } diff --git a/be/overflow/src/test/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCaseTest.java b/be/overflow/src/test/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCaseTest.java new file mode 100644 index 0000000..5ded638 --- /dev/null +++ b/be/overflow/src/test/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCaseTest.java @@ -0,0 +1,6 @@ +package com.econovation.overflow.auth.domain.usecase; + +import static org.junit.jupiter.api.Assertions.*; +class ReissueUseCaseTest { + +} \ No newline at end of file From ea3f1251d7a485f600da7313e5b69a16b5402ea4 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Sat, 7 Oct 2023 00:14:12 +0900 Subject: [PATCH 31/31] =?UTF-8?q?fix=20:=20security=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=EC=97=90=20cors=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/econovation/overflow/security/SecurityConfig.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/be/overflow/src/main/java/com/econovation/overflow/security/SecurityConfig.java b/be/overflow/src/main/java/com/econovation/overflow/security/SecurityConfig.java index ee91a15..6d5e6af 100644 --- a/be/overflow/src/main/java/com/econovation/overflow/security/SecurityConfig.java +++ b/be/overflow/src/main/java/com/econovation/overflow/security/SecurityConfig.java @@ -38,14 +38,14 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.csrf().disable(); http.formLogin().disable(); http.httpBasic().disable(); - http.cors(); + http.cors().configurationSource(corsConfigurationSource()); http.authorizeRequests().antMatchers(HttpMethod.POST, "/users/auth/**").permitAll(); http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); return http.build(); } - private CorsConfigurationSource configurationSource() { + private CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); configuration.addAllowedMethod("*"); configuration.addAllowedHeader("*"); @@ -53,6 +53,7 @@ private CorsConfigurationSource configurationSource() { configuration.setAllowCredentials(true); configuration.addExposedHeader("Authorization"); + configuration.addExposedHeader("Set-Cookie"); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration);