-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MATE-78 : [FIX] JWT 토큰 생성 및 테스트 코드 검증 (#72)
* MATE-78 : [FEAT] 네이버 로그인 서비스 기존 회원 검증 여부 추가 * MATE-78 : [FEAT] 자체 회원가입 DTO 수정 * MATE-78 : [FEAT] 자체 로그인 기능 서비스 구현 * MATE-78 : [FEAT] 자체 로그인 기능 컨트롤러 구현 * MATE-61 : [FEAT] @AuthenticationPrincipal 객체 AuthMember 추가
- Loading branch information
Showing
12 changed files
with
135 additions
and
54 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/mate/common/security/auth/AuthMember.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.example.mate.common.security.auth; | ||
|
||
import com.example.mate.common.error.CustomException; | ||
import com.example.mate.common.error.ErrorCode; | ||
import com.example.mate.domain.member.entity.Member; | ||
import com.example.mate.domain.member.repository.MemberRepository; | ||
import java.security.Principal; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class AuthMember implements Principal { | ||
|
||
private final String userId; | ||
|
||
@Getter | ||
private final Long memberId; // memberId 반환 | ||
|
||
// 사용자 ID 반환 | ||
@Override | ||
public String getName() { | ||
return this.userId; | ||
} | ||
|
||
public Member validateAuthMember(MemberRepository memberRepository) { | ||
return memberRepository.findById(memberId) | ||
.orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND_BY_ID)); | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
src/main/java/com/example/mate/common/security/auth/CustomUserPrincipal.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package com.example.mate.domain.member.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.Max; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
@@ -10,15 +12,29 @@ | |
@Builder | ||
public class JoinRequest { | ||
|
||
@Schema(description = "사용자 이름", example = "홍길동") | ||
@NotBlank(message = "이름은 필수 항목입니다.") | ||
@Size(max = 10, message = "이름은 최대 10자까지 입력 가능합니다.") | ||
private String name; | ||
|
||
@Schema(description = "사용자 이메일", example = "[email protected]") | ||
@NotBlank(message = "이메일은 필수 항목입니다.") | ||
@Size(max = 40, message = "이메일은 최대 40자까지 입력 가능합니다.") | ||
private String email; | ||
|
||
@Schema(description = "사용자 성별", example = "M") | ||
private String gender; | ||
|
||
@Schema(description = "사용자 출생연도", example = "2000") | ||
private String birthyear; | ||
|
||
@Schema(description = "선택한 마이팀 ID", example = "1") | ||
@Min(value = 0, message = "teamId는 0 이상이어야 합니다.") | ||
@Max(value = 10, message = "teamId는 10 이하이어야 합니다.") | ||
private Long teamId; | ||
|
||
@Schema(description = "사용자 닉네임", example = "tester") | ||
@NotBlank(message = "이메일은 필수 항목입니다.") | ||
@Size(max = 20, message = "nickname은 최대 20자까지 입력할 수 있습니다.") | ||
private String nickname; | ||
} |
13 changes: 9 additions & 4 deletions
13
src/main/java/com/example/mate/domain/member/dto/request/MemberLoginRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
package com.example.mate.domain.member.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.AllArgsConstructor; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class MemberLoginRequest { | ||
|
||
@Schema(description = "사용자 이메일", example = "[email protected]") | ||
@NotBlank(message = "이메일은 필수 항목입니다.") | ||
@Size(max = 40, message = "이메일은 최대 40자까지 입력 가능합니다.") | ||
private String email; | ||
|
||
@JsonCreator | ||
public MemberLoginRequest(@JsonProperty("email") String email) { | ||
this.email = email; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/example/mate/domain/member/dto/response/MemberLoginResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.example.mate.domain.member.dto.response; | ||
|
||
import com.example.mate.domain.member.entity.Member; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class MemberLoginResponse { | ||
|
||
private final Long memberId; | ||
private final String grantType; | ||
private final String accessToken; | ||
private final String refreshToken; | ||
|
||
// TODO : 파라미터로 JwtToken 추가 및 토큰 매핑 | ||
public static MemberLoginResponse from(Member member) { | ||
return MemberLoginResponse.builder() | ||
.memberId(member.getId()) | ||
.grantType("Bearer") | ||
.accessToken("accessToken") | ||
.refreshToken("refreshToken") | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters