Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : BasicInfo CRUD api 구현 #11

Merged
merged 23 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6ddb721
refactor: 키보드 포커스 잃을 때 이메일 중복체크하기 위해 로직분리
KimChanJin97 Mar 25, 2024
221893d
refactor: name 필드 제거
KimChanJin97 Mar 25, 2024
ad3714c
feat: 멤버 기본정보 CRUD 기능 구현
KimChanJin97 Mar 25, 2024
6351103
feat: 기본정보 기능 구현
KimChanJin97 Apr 1, 2024
ab80d31
feat: HeightGroup 열거형의 value 수정
KimChanJin97 Apr 1, 2024
a418030
feat: FaceInfo 엔티티 및 리포지토리 생성 & Member 엔티티 수정
KimChanJin97 Apr 10, 2024
6c22661
fix: 인터셉터 체인걸어두지 않아서 작동되지 않았던 버그 해결
KimChanJin97 Apr 10, 2024
75a91fa
refactor: 본인인증을 순수 인터셉터 방식으로 구현하기 위한 코드 수정
KimChanJin97 Apr 10, 2024
17e61ee
fix: Member 엔티티의 nickname 필드를 BasicInfo 엔티티로 이동
KimChanJin97 Apr 10, 2024
17faacc
fix: 빌드되지 않는 버그 해결
KimChanJin97 Apr 10, 2024
81585b8
fix: 액세스 토큰 만료기한을 3시간으로 수정
KimChanJin97 Apr 10, 2024
cd2d78e
fix: oauth2 인증방식 제거로 인해 컨트롤러 호출 url 수정
KimChanJin97 Apr 10, 2024
3631971
fix: oauth2 인증방식 제거로 인해 컨트롤러 호출 url 수정2
KimChanJin97 Apr 10, 2024
3273d6e
fix: 액세스 토큰이 블랙리스트 처리가 되지 않았음에도 불구하고 블랙리스트 인터셉터에 잡히는 버그 해결
KimChanJin97 Apr 10, 2024
e612eaa
feat: MultipartFile 커스텀 클래스 구현
KimChanJin97 Apr 10, 2024
3998346
feat: S3 연동을 위한 BucketConfig 구현
KimChanJin97 Apr 10, 2024
a0ae6bf
feat: FaceInfo 기능 구현에 사용될 DTO 생성
KimChanJin97 Apr 10, 2024
1b6f4b9
feat: 회원가입 직후 S3에 업로드되어 있는 기본프로필로 Member 의 FaceInfo 필드 초기화
KimChanJin97 Apr 10, 2024
b88db0f
feat: S3 연동을 위한 BucketService 구현
KimChanJin97 Apr 10, 2024
85629c7
faet: FaceInfo 객체 CRUD 기능 및 S3 연동
KimChanJin97 Apr 10, 2024
77563cc
feat: FaceInfo 객체 CRUD 컨트롤러 구현
KimChanJin97 Apr 10, 2024
6251827
chore: s3 의존성 추가
KimChanJin97 Apr 10, 2024
80b16b3
feat: 회원탈퇴 기능 구현
KimChanJin97 Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'

annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-test'

// postgresql
implementation 'org.postgresql:postgresql'
Expand All @@ -48,6 +48,8 @@ dependencies {
// 메일 인증
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '3.0.5'

// AWS S3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
}

tasks.named('test') {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/capstone/facefriend/FacefriendApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

@EnableJpaAuditing
@SpringBootApplication
public class FaceFriendApplication {

public class FacefriendApplication {
static {
System.setProperty("com.amazonaws.sdk.disableEc2Metadata", "true");
}
public static void main(String[] args) {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
SpringApplication.run(FaceFriendApplication.class, args);
SpringApplication.run(FacefriendApplication.class, args);
}

}
32 changes: 23 additions & 9 deletions src/main/java/capstone/facefriend/auth/config/AuthConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,55 @@ private HandlerInterceptor loginCheckInterceptor() {
return new PathMatchInterceptor(loginCheckInterceptor)
.addExcludePathPattern("/**", OPTIONS)

.addIncludePathPattern("/signout", DELETE)
.addIncludePathPattern("/test", GET)
.addIncludePathPattern("/auth/reset-password", POST)
.addIncludePathPattern("/auth/signout", DELETE)
.addIncludePathPattern("/auth/exit", DELETE)
.addIncludePathPattern("/basic-info", ANY)
.addIncludePathPattern("/face-info", ANY)

.addExcludePathPattern("/reissue", POST); // 토큰 만료 시에는 해당 요청을 가로채지 않아야 합니다.
.addExcludePathPattern("/auth/reissue", POST); // 토큰 만료 시에는 해당 요청을 가로채지 않아야 합니다.
}

private HandlerInterceptor loginInterceptor() {
return new PathMatchInterceptor(loginInterceptor)
.addExcludePathPattern("/**", OPTIONS)

.addIncludePathPattern("/signout", DELETE)
.addIncludePathPattern("/test", GET)
.addIncludePathPattern("/auth/reset-password", POST)
.addIncludePathPattern("/auth/signout", DELETE)
.addIncludePathPattern("/auth/exit", DELETE)
.addIncludePathPattern("/basic-info", ANY)
.addIncludePathPattern("/face-info", ANY)

.addExcludePathPattern("/reissue", POST); // 토큰 만료 시에는 해당 요청을 가로채지 않아야 합니다.
.addExcludePathPattern("/auth/reissue", POST); // 토큰 만료 시에는 해당 요청을 가로채지 않아야 합니다.
}

private HandlerInterceptor tokenReissueInterceptor() {
return new PathMatchInterceptor(tokenReissueInterceptor)
.addExcludePathPattern("/**", OPTIONS)

.addIncludePathPattern("/reissue", POST); // 토큰 만료 시에는 해당 요청을 가로채야 합니다.
.addIncludePathPattern("/auth/reissue", POST); // 토큰 재발급 시에는 해당 요청을 가로채야 합니다.
}

private HandlerInterceptor tokenBlackListInterceptor() {
return new PathMatchInterceptor(tokenBlackListInterceptor)
.addExcludePathPattern("/**", OPTIONS)

.addIncludePathPattern("/test", GET);
.addIncludePathPattern("/auth/signout", DELETE)
.addIncludePathPattern("/auth/exit", DELETE)
.addIncludePathPattern("/auth/reset-password", POST)
.addIncludePathPattern("/basic-info", ANY)
.addIncludePathPattern("/face-info", ANY);
}

private HandlerInterceptor verificationInterceptor() {
return new PathMatchInterceptor(verificationInterceptor)
.addExcludePathPattern("/**", OPTIONS)

.addIncludePathPattern("/test", GET);
.addIncludePathPattern("/auth/signout", DELETE)
.addIncludePathPattern("/auth/exit", DELETE)
.addIncludePathPattern("/auth/reset-password", POST)
.addIncludePathPattern("/basic-info", ANY)
.addIncludePathPattern("/face-info", ANY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package capstone.facefriend.auth.controller.interceptor;

import capstone.facefriend.auth.controller.support.AuthenticationExtractor;
import capstone.facefriend.email.controller.interceptor.VerificationInterceptor;
import capstone.facefriend.redis.RedisDao;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand All @@ -16,15 +17,16 @@
public class TokenBlackListInterceptor implements HandlerInterceptor {

private final RedisDao redisDao;
private final static String SIGN_OUT_VALUE = "SIGN_OUT_VALUE";

private final VerificationInterceptor verificationInterceptor;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
String accessToken = AuthenticationExtractor.extractAccessToken(request).get();

if (accessToken != null && accessToken.equals(SIGN_OUT_VALUE)) {
return !redisDao.isKeyOfAccessTokenInBlackList(accessToken); // 액세스 토큰이 블랙리스트에 등록되었다면 false 반환해야 합니다.
if (accessToken != null) {
return redisDao.isKeyOfAccessTokenInBlackList(accessToken); // 액세스 토큰이 블랙리스트에 등록되었다면 false 반환해야 합니다.
}
return true;
return verificationInterceptor.preHandle(request, response, handler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TokenReissueInterceptor implements HandlerInterceptor {

private final TokenProvider tokenProvider;
private final AuthenticationContext authenticationContext;
private final VerificationInterceptor verificationInterceptor;
private final TokenBlackListInterceptor tokenBlackListInterceptor;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
Expand All @@ -28,6 +28,6 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
Long memberId = tokenProvider.extractIdIgnoringExpiration(accessToken);
authenticationContext.setAuthentication(memberId);

return verificationInterceptor.preHandle(request, response, handler);
return tokenBlackListInterceptor.preHandle(request, response, handler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum AuthExceptionType implements ExceptionType {
UNSUPPORTED_TOKEN(Status.BAD_REQUEST, 2005, "지원되지 않는 토큰입니다."),
INVALID_TOKEN(Status.BAD_REQUEST, 2006, "토큰이 유효하지 않습니다."),
BAD_REQUEST_TO_PROVIDER(Status.BAD_REQUEST, 2007, "토큰이 유효하지 않습니다."),
UNAUTHORIZED(Status.UNAUTHORIZED, 2008, "로그인한 정보가 없습니다."),
UNAUTHORIZED(Status.UNAUTHORIZED, 2008, "로그인한 정보가 없습니다. 로그인하시기 바랍니다."),
;

private final Status status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class JwtProvider implements TokenProvider {

private final RedisDao redisDao;

private static final long ACCESS_TOKEN_EXPIRATION_TIME = 60 * 5L; // 5분 // 1000 * 60 * 60 * 3L; // 3시간
private static final long ACCESS_TOKEN_EXPIRATION_TIME = 60 * 60 * 3L; // 3시간
private static final long REFRESH_TOKEN_EXPIRATION_TIME = 60 * 60 * 24 * 7L; // 7일

@PostConstruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public String loginUri(String redirectUri, String provider) {
public TokenResponse generateTokens(OAuthMember oAuthMember) {
Member newMember = Member.builder()
.email(oAuthMember.email())
.name(oAuthMember.nickname())
.password(TEMPORARY_GOOGLE_PASSWORD)
.imageUrl(oAuthMember.imageUrl())
.isVerified(true)
.role(USER)
.build();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import capstone.facefriend.auth.domain.TokenProvider;
import capstone.facefriend.auth.exception.AuthException;
import capstone.facefriend.email.exception.VerificationException;
import capstone.facefriend.email.support.VerificationContext;
import capstone.facefriend.member.domain.Member;
import capstone.facefriend.member.domain.MemberRepository;
import capstone.facefriend.member.exception.MemberException;
Expand All @@ -16,7 +15,7 @@
import org.springframework.web.servlet.HandlerInterceptor;

import static capstone.facefriend.auth.exception.AuthExceptionType.UNAUTHORIZED;
import static capstone.facefriend.email.exception.VerificationExceptionType.*;
import static capstone.facefriend.email.exception.VerificationExceptionType.NOT_VERIFIED;
import static capstone.facefriend.member.exception.MemberExceptionType.NOT_FOUND;


Expand All @@ -26,7 +25,6 @@
public class VerificationInterceptor implements HandlerInterceptor {

private final TokenProvider tokenProvider;
private final VerificationContext verificationContext;
private final MemberRepository memberRepository;

@Override
Expand All @@ -42,8 +40,6 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
boolean isVerified = member.isVerified();
if (!isVerified) throw new VerificationException(NOT_VERIFIED);

verificationContext.setIsVerified(true); // 예외를 통과했다면 무조건 true 입니다.

return true;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package capstone.facefriend.member.bucketConfig;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
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 BucketConfig {

@Value("${cloud.aws.credentials.accessKey}")
private String accessKey;

@Value("${cloud.aws.credentials.secretKey}")
private String secretKey;

@Value("${cloud.aws.region.static}")
private String region;

@Bean
public AmazonS3 amazonS3() {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

return AmazonS3ClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(region)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package capstone.facefriend.member.controller;


import capstone.facefriend.auth.controller.support.AuthMember;
import capstone.facefriend.member.service.BasicInfoService;
import capstone.facefriend.member.service.dto.BasicInfoRequest;
import capstone.facefriend.member.service.dto.BasicInfoResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequiredArgsConstructor
public class BasicInfoController {

private final BasicInfoService basicInfoService;

@GetMapping("/basic-info")
public ResponseEntity<BasicInfoResponse> getBasicInfo(
@AuthMember Long memberId
) {
return ResponseEntity.ok(basicInfoService.getBasicInfo(memberId));
}

@PutMapping("/basic-info")
public ResponseEntity<BasicInfoResponse> putBasicInfo(
@AuthMember Long memberId,
@RequestBody BasicInfoRequest request
) {
return ResponseEntity.ok(basicInfoService.putBasicInfo(memberId, request));
}
}
Loading