From 43d7937ea4985f8499ccb12c4610466a5fe2e275 Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Wed, 6 Dec 2023 09:24:14 +0900 Subject: [PATCH] =?UTF-8?q?[#89]=20fix:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0=20=EB=B0=8F?= =?UTF-8?q?=20jwt=20=EA=B4=80=EB=A0=A8=20=EC=84=B8=ED=8C=85=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jwt/JwtAuthenticationEntryPoint.java | 8 +- .../common/config/jwt/JwtTokenProvider.java | 7 +- .../makers/crew/main/entity/user/User.java | 190 +++++++++--------- main/src/main/resources/application-dev.yml | 2 +- 4 files changed, 100 insertions(+), 107 deletions(-) diff --git a/main/src/main/java/org/sopt/makers/crew/main/common/config/jwt/JwtAuthenticationEntryPoint.java b/main/src/main/java/org/sopt/makers/crew/main/common/config/jwt/JwtAuthenticationEntryPoint.java index aae9b01b..fdbb56c8 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/common/config/jwt/JwtAuthenticationEntryPoint.java +++ b/main/src/main/java/org/sopt/makers/crew/main/common/config/jwt/JwtAuthenticationEntryPoint.java @@ -1,10 +1,8 @@ package org.sopt.makers.crew.main.common.config.jwt; -import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; -import org.sopt.makers.crew.main.common.response.ErrorStatus; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; @@ -12,16 +10,14 @@ @Component public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { - private final ObjectMapper mapper = new ObjectMapper(); - @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { - setResponse(response, ErrorStatus.UNAUTHORIZED_TOKEN); + setResponse(response); } - public void setResponse(HttpServletResponse response, ErrorStatus status) throws IOException { + public void setResponse(HttpServletResponse response) throws IOException { response.setContentType("application/json;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } diff --git a/main/src/main/java/org/sopt/makers/crew/main/common/config/jwt/JwtTokenProvider.java b/main/src/main/java/org/sopt/makers/crew/main/common/config/jwt/JwtTokenProvider.java index 76274161..837fe9ad 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/common/config/jwt/JwtTokenProvider.java +++ b/main/src/main/java/org/sopt/makers/crew/main/common/config/jwt/JwtTokenProvider.java @@ -14,7 +14,6 @@ import javax.crypto.spec.SecretKeySpec; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.sopt.makers.crew.main.entity.user.UserRepository; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Component; @@ -24,12 +23,10 @@ @RequiredArgsConstructor public class JwtTokenProvider { - private final UserRepository userRepository; - - @Value("${JWT_SECRET}") + @Value("${jwt.secret}") private String secretKey; - @Value("${ACCESS_TOKEN_EXPIRED_TIME}") + @Value("${jwt.access-token.expire-length}") private Long accessTokenExpireLength; private static final String AUTHORIZATION_HEADER = "Authorization"; diff --git a/main/src/main/java/org/sopt/makers/crew/main/entity/user/User.java b/main/src/main/java/org/sopt/makers/crew/main/entity/user/User.java index c1bb8805..da6e2530 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/entity/user/User.java +++ b/main/src/main/java/org/sopt/makers/crew/main/entity/user/User.java @@ -28,101 +28,101 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -@Table(name = "user", schema = "web_dev") +@Table(name = "user") public class User { - /** - * Primary Key - */ - @Id - @Column(name = "id") - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - /** - * 사용자 이름 - */ - @Column(name = "name", nullable = false) - private String name; - - /** - * sopt org unique id - */ - @Column(name = "orgId", nullable = false) - private Integer orgId; - - /** - * 활동 목록 - */ - @Column(name = "activities") - @Type(JsonBinaryType.class) - private List activities; - - /** - * 프로필 이미지 - */ - @Column(name = "profileImage") - private String profileImage; - - /** - * 핸드폰 번호 - */ - @Column(name = "phone") - private String phone; - - /** - * 내가 생성한 모임 - */ - @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) - private Set meetings = new HashSet<>(); - - /** - * 내가 지원한 내역 - */ - @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) - private List applies = new ArrayList<>(); - - /** - * 작성한 게시글 - */ - @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) - private List posts = new ArrayList<>(); - - /** - * 좋아요 - */ - @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) - private List likes = new ArrayList<>(); - - /** - * 신고 내역 - */ - @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) - private List reports = new ArrayList<>(); - - @Builder - public User(String name, int orgId, List activities, String profileImage, - String phone) { - this.name = name; - this.orgId = orgId; - this.activities = activities; - this.profileImage = profileImage; - this.phone = phone; - } - - public void addMeeting(Meeting meeting) { - this.meetings.add(meeting); - } - - public void addApply(Apply apply) { - this.applies.add(apply); - } - - public void addLike(Like like) { - this.likes.add(like); - } - - public void addReport(Report report) { - this.reports.add(report); - } + /** + * Primary Key + */ + @Id + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + /** + * 사용자 이름 + */ + @Column(name = "name", nullable = false) + private String name; + + /** + * sopt org unique id + */ + @Column(name = "orgId", nullable = false) + private Integer orgId; + + /** + * 활동 목록 + */ + @Column(name = "activities") + @Type(JsonBinaryType.class) + private List activities; + + /** + * 프로필 이미지 + */ + @Column(name = "profileImage") + private String profileImage; + + /** + * 핸드폰 번호 + */ + @Column(name = "phone") + private String phone; + + /** + * 내가 생성한 모임 + */ + @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) + private Set meetings = new HashSet<>(); + + /** + * 내가 지원한 내역 + */ + @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) + private List applies = new ArrayList<>(); + + /** + * 작성한 게시글 + */ + @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) + private List posts = new ArrayList<>(); + + /** + * 좋아요 + */ + @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) + private List likes = new ArrayList<>(); + + /** + * 신고 내역 + */ + @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) + private List reports = new ArrayList<>(); + + @Builder + public User(String name, int orgId, List activities, String profileImage, + String phone) { + this.name = name; + this.orgId = orgId; + this.activities = activities; + this.profileImage = profileImage; + this.phone = phone; + } + + public void addMeeting(Meeting meeting) { + this.meetings.add(meeting); + } + + public void addApply(Apply apply) { + this.applies.add(apply); + } + + public void addLike(Like like) { + this.likes.add(like); + } + + public void addReport(Report report) { + this.reports.add(report); + } } diff --git a/main/src/main/resources/application-dev.yml b/main/src/main/resources/application-dev.yml index 2b279c58..536aa6f5 100644 --- a/main/src/main/resources/application-dev.yml +++ b/main/src/main/resources/application-dev.yml @@ -25,7 +25,7 @@ spring: jwt: header: Authorization - secret: ${JWT_SECRET} + secret: ${DEV_JWT_SECRET} access-token: expire-length: ${ACCESS_TOKEN_EXPIRED_TIME} # 10분