Skip to content

Commit

Permalink
[#89] fix: 불필요한 코드 제거 및 jwt 관련 세팅 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 authored and rdd9223 committed Dec 9, 2023
1 parent 05cbef4 commit 7eed4c0
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
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;

@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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down
190 changes: 95 additions & 95 deletions main/src/main/java/org/sopt/makers/crew/main/entity/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserActivityVO> activities;

/**
* 프로필 이미지
*/
@Column(name = "profileImage")
private String profileImage;

/**
* 핸드폰 번호
*/
@Column(name = "phone")
private String phone;

/**
* 내가 생성한 모임
*/
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
private Set<Meeting> meetings = new HashSet<>();

/**
* 내가 지원한 내역
*/
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
private List<Apply> applies = new ArrayList<>();

/**
* 작성한 게시글
*/
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
private List<Post> posts = new ArrayList<>();

/**
* 좋아요
*/
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
private List<Like> likes = new ArrayList<>();

/**
* 신고 내역
*/
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
private List<Report> reports = new ArrayList<>();

@Builder
public User(String name, int orgId, List<UserActivityVO> 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<UserActivityVO> activities;

/**
* 프로필 이미지
*/
@Column(name = "profileImage")
private String profileImage;

/**
* 핸드폰 번호
*/
@Column(name = "phone")
private String phone;

/**
* 내가 생성한 모임
*/
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
private Set<Meeting> meetings = new HashSet<>();

/**
* 내가 지원한 내역
*/
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
private List<Apply> applies = new ArrayList<>();

/**
* 작성한 게시글
*/
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
private List<Post> posts = new ArrayList<>();

/**
* 좋아요
*/
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
private List<Like> likes = new ArrayList<>();

/**
* 신고 내역
*/
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
private List<Report> reports = new ArrayList<>();

@Builder
public User(String name, int orgId, List<UserActivityVO> 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);
}
}
2 changes: 1 addition & 1 deletion main/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spring:

jwt:
header: Authorization
secret: ${JWT_SECRET}
secret: ${DEV_JWT_SECRET}
access-token:
expire-length: ${ACCESS_TOKEN_EXPIRED_TIME} # 10분

Expand Down

0 comments on commit 7eed4c0

Please sign in to comment.