Skip to content

Commit

Permalink
Merge pull request #11 from kookmin-sw/feat/image
Browse files Browse the repository at this point in the history
merge : BasicInfo, FaceInfo 기능 구현 (be <- feat/image)
  • Loading branch information
KimChanJin97 authored Apr 10, 2024
2 parents c3b34d9 + 80b16b3 commit f9778bf
Show file tree
Hide file tree
Showing 34 changed files with 885 additions and 196 deletions.
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

0 comments on commit f9778bf

Please sign in to comment.