From f302c64b53e71f60ccc24c6023dd28bd5d9eafa0 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 17:59:31 +0900 Subject: [PATCH 01/57] style: rename --- .../com/hjjang/backend/global/response/code/SuccessCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java b/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java index f045aae..3f22430 100644 --- a/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java +++ b/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java @@ -8,7 +8,7 @@ public enum SuccessCode { //User - USERPROFILE_SUCCESS(200, "U001", "프로필 조회 완료."),; + USER_PROFILE_SUCCESS(200, "U001", "프로필 조회 완료."),; private final int status; private final String code; From 1b3ccab5aca0a6f058f18ba5fcb0e5a1e3a6d5b5 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 18:01:27 +0900 Subject: [PATCH 02/57] style: sebatch package importing --- .../OAuth2AuthenticationFailureHandler.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationFailureHandler.java b/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationFailureHandler.java index 43f0aae..b710dc4 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationFailureHandler.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationFailureHandler.java @@ -1,23 +1,20 @@ package com.hjjang.backend.global.config.security.handler; -import static com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.*; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository; +import com.hjjang.backend.global.util.CookieUtil; +import lombok.RequiredArgsConstructor; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; import org.springframework.stereotype.Component; import org.springframework.web.util.UriComponentsBuilder; -import com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository; -import com.hjjang.backend.global.util.CookieUtil; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; -import lombok.RequiredArgsConstructor; +import static com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.REDIRECT_URI_PARAM_COOKIE_NAME; @Component @RequiredArgsConstructor From 97e4822593642e195f25ffbcca938246bf51e173 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 18:01:47 +0900 Subject: [PATCH 03/57] fix: fix package directory --- backend/src/main/resources/log4j2.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/backend/src/main/resources/log4j2.xml b/backend/src/main/resources/log4j2.xml index 85b2612..d1d1de7 100644 --- a/backend/src/main/resources/log4j2.xml +++ b/backend/src/main/resources/log4j2.xml @@ -34,12 +34,9 @@ - + - - - \ No newline at end of file From 64b1361b15caf1e1976274713b823e1a39a39305 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 18:03:20 +0900 Subject: [PATCH 04/57] fix: fix return value to ResponseEntity --- .../domain/user/controller/UserController.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java index 3c3d1c0..91b92c8 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java @@ -1,14 +1,14 @@ package com.hjjang.backend.domain.user.controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - import com.hjjang.backend.domain.user.dto.UserProfileDTO; import com.hjjang.backend.domain.user.service.UserProfileService; -import com.hjjang.backend.global.dto.ApiResponse; - +import com.hjjang.backend.global.response.code.SuccessCode; +import com.hjjang.backend.global.response.response.SuccessResponse; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/api/v1/users") @@ -18,8 +18,8 @@ public class UserController { private final UserProfileService userProfileService; @GetMapping("/profile") - public ApiResponse getProfile() { + public ResponseEntity getProfile() { UserProfileDTO userProfile = userProfileService.getUserProfile(); - return ApiResponse.success("userProfile", userProfile); + return ResponseEntity.ok(SuccessResponse.of(SuccessCode.USER_PROFILE_SUCCESS, userProfile)); } } From 93ce685edea96afed299aef5cc506a4fa2ff1fe8 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 18:23:52 +0900 Subject: [PATCH 05/57] style: move directory --- .../properties/AuthProperties.java | 9 ++-- .../security/AuthProviderConfig.java | 6 +-- .../RestAuthenticationEntryPoint.java | 2 +- .../exception/TokenValidFailedException.java | 2 +- .../filter/TokenAuthenticationFilter.java | 6 +-- .../OAuth2AuthenticationFailureHandler.java | 8 ++-- .../OAuth2AuthenticationSuccessHandler.java | 18 ++++---- .../handler/TokenAccessDeniedHandler.java | 2 +- .../KakaoParsingParsingUserContext.java | 4 +- .../security/parser/ParsingUserContext.java | 2 +- .../parser/ParsingUserContextFactory.java | 6 +-- .../security/principal/UserPrincipal.java | 2 +- ...izationRequestBasedOnCookieRepository.java | 2 +- .../service/CustomOAuth2UserService.java | 8 ++-- .../security/token/AuthToken.java | 42 +++++++++---------- .../security/token/AuthTokenProvider.java | 4 +- 16 files changed, 60 insertions(+), 63 deletions(-) rename backend/src/main/java/com/hjjang/backend/global/config/{ => security}/properties/AuthProperties.java (96%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/AuthProviderConfig.java (69%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/exception/RestAuthenticationEntryPoint.java (93%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/exception/TokenValidFailedException.java (80%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/filter/TokenAuthenticationFilter.java (86%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/handler/OAuth2AuthenticationFailureHandler.java (77%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/handler/OAuth2AuthenticationSuccessHandler.java (88%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/handler/TokenAccessDeniedHandler.java (94%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/parser/KakaoParsingParsingUserContext.java (89%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/parser/ParsingUserContext.java (88%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/parser/ParsingUserContextFactory.java (88%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/principal/UserPrincipal.java (97%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/repository/OAuth2AuthorizationRequestBasedOnCookieRepository.java (97%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/service/CustomOAuth2UserService.java (89%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/token/AuthToken.java (74%) rename backend/src/main/java/com/hjjang/backend/global/{config => }/security/token/AuthTokenProvider.java (93%) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/properties/AuthProperties.java b/backend/src/main/java/com/hjjang/backend/global/config/security/properties/AuthProperties.java similarity index 96% rename from backend/src/main/java/com/hjjang/backend/global/config/properties/AuthProperties.java rename to backend/src/main/java/com/hjjang/backend/global/config/security/properties/AuthProperties.java index 8a7afa5..5129c32 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/properties/AuthProperties.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/properties/AuthProperties.java @@ -1,13 +1,12 @@ -package com.hjjang.backend.global.config.properties; - -import java.util.ArrayList; -import java.util.List; +package com.hjjang.backend.global.config.security.properties; +import lombok.Data; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; -import lombok.Data; +import java.util.ArrayList; +import java.util.List; @Data @Configuration diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/AuthProviderConfig.java b/backend/src/main/java/com/hjjang/backend/global/security/AuthProviderConfig.java similarity index 69% rename from backend/src/main/java/com/hjjang/backend/global/config/security/AuthProviderConfig.java rename to backend/src/main/java/com/hjjang/backend/global/security/AuthProviderConfig.java index 73af0d7..0b8f23c 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/AuthProviderConfig.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/AuthProviderConfig.java @@ -1,7 +1,7 @@ -package com.hjjang.backend.global.config.security; +package com.hjjang.backend.global.security; -import com.hjjang.backend.global.config.properties.AuthProperties; -import com.hjjang.backend.global.config.security.token.AuthTokenProvider; +import com.hjjang.backend.global.config.security.properties.AuthProperties; +import com.hjjang.backend.global.security.token.AuthTokenProvider; import lombok.RequiredArgsConstructor; diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/exception/RestAuthenticationEntryPoint.java b/backend/src/main/java/com/hjjang/backend/global/security/exception/RestAuthenticationEntryPoint.java similarity index 93% rename from backend/src/main/java/com/hjjang/backend/global/config/security/exception/RestAuthenticationEntryPoint.java rename to backend/src/main/java/com/hjjang/backend/global/security/exception/RestAuthenticationEntryPoint.java index 61db8bc..cfe5bba 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/exception/RestAuthenticationEntryPoint.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/exception/RestAuthenticationEntryPoint.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.global.config.security.exception; +package com.hjjang.backend.global.security.exception; import java.io.IOException; diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/exception/TokenValidFailedException.java b/backend/src/main/java/com/hjjang/backend/global/security/exception/TokenValidFailedException.java similarity index 80% rename from backend/src/main/java/com/hjjang/backend/global/config/security/exception/TokenValidFailedException.java rename to backend/src/main/java/com/hjjang/backend/global/security/exception/TokenValidFailedException.java index 4b44d26..fc36540 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/exception/TokenValidFailedException.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/exception/TokenValidFailedException.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.global.config.security.exception; +package com.hjjang.backend.global.security.exception; public class TokenValidFailedException extends RuntimeException { diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/filter/TokenAuthenticationFilter.java b/backend/src/main/java/com/hjjang/backend/global/security/filter/TokenAuthenticationFilter.java similarity index 86% rename from backend/src/main/java/com/hjjang/backend/global/config/security/filter/TokenAuthenticationFilter.java rename to backend/src/main/java/com/hjjang/backend/global/security/filter/TokenAuthenticationFilter.java index dae1dea..1a0dbf1 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/filter/TokenAuthenticationFilter.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/filter/TokenAuthenticationFilter.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.global.config.security.filter; +package com.hjjang.backend.global.security.filter; import java.io.IOException; @@ -11,8 +11,8 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.filter.OncePerRequestFilter; -import com.hjjang.backend.global.config.security.token.AuthToken; -import com.hjjang.backend.global.config.security.token.AuthTokenProvider; +import com.hjjang.backend.global.security.token.AuthToken; +import com.hjjang.backend.global.security.token.AuthTokenProvider; import com.hjjang.backend.global.util.HeaderUtil; import lombok.RequiredArgsConstructor; diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationFailureHandler.java b/backend/src/main/java/com/hjjang/backend/global/security/handler/OAuth2AuthenticationFailureHandler.java similarity index 77% rename from backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationFailureHandler.java rename to backend/src/main/java/com/hjjang/backend/global/security/handler/OAuth2AuthenticationFailureHandler.java index b710dc4..93dbb72 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationFailureHandler.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/handler/OAuth2AuthenticationFailureHandler.java @@ -1,6 +1,6 @@ -package com.hjjang.backend.global.config.security.handler; +package com.hjjang.backend.global.security.handler; -import com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository; +import com.hjjang.backend.global.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository; import com.hjjang.backend.global.util.CookieUtil; import lombok.RequiredArgsConstructor; import org.springframework.security.core.AuthenticationException; @@ -14,8 +14,6 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import static com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.REDIRECT_URI_PARAM_COOKIE_NAME; - @Component @RequiredArgsConstructor public class OAuth2AuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { @@ -25,7 +23,7 @@ public class OAuth2AuthenticationFailureHandler extends SimpleUrlAuthenticationF @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { - String targetUrl = CookieUtil.getCookie(request, REDIRECT_URI_PARAM_COOKIE_NAME) + String targetUrl = CookieUtil.getCookie(request, OAuth2AuthorizationRequestBasedOnCookieRepository.REDIRECT_URI_PARAM_COOKIE_NAME) .map(Cookie::getValue) .orElse(("/")); diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationSuccessHandler.java b/backend/src/main/java/com/hjjang/backend/global/security/handler/OAuth2AuthenticationSuccessHandler.java similarity index 88% rename from backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationSuccessHandler.java rename to backend/src/main/java/com/hjjang/backend/global/security/handler/OAuth2AuthenticationSuccessHandler.java index 2ae9bdf..3e821ae 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/OAuth2AuthenticationSuccessHandler.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/handler/OAuth2AuthenticationSuccessHandler.java @@ -1,15 +1,15 @@ -package com.hjjang.backend.global.config.security.handler; +package com.hjjang.backend.global.security.handler; import com.hjjang.backend.domain.user.entity.ProviderType; import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.entity.UserRefreshToken; import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; -import com.hjjang.backend.global.config.properties.AuthProperties; -import com.hjjang.backend.global.config.security.parser.ParsingUserContext; -import com.hjjang.backend.global.config.security.parser.ParsingUserContextFactory; -import com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository; -import com.hjjang.backend.global.config.security.token.AuthToken; -import com.hjjang.backend.global.config.security.token.AuthTokenProvider; +import com.hjjang.backend.global.config.security.properties.AuthProperties; +import com.hjjang.backend.global.security.parser.ParsingUserContext; +import com.hjjang.backend.global.security.parser.ParsingUserContextFactory; +import com.hjjang.backend.global.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository; +import com.hjjang.backend.global.security.token.AuthToken; +import com.hjjang.backend.global.security.token.AuthTokenProvider; import com.hjjang.backend.global.util.CookieUtil; import lombok.RequiredArgsConstructor; import org.springframework.security.core.Authentication; @@ -30,8 +30,8 @@ import java.util.Date; import java.util.Optional; -import static com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.REDIRECT_URI_PARAM_COOKIE_NAME; -import static com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.REFRESH_TOKEN; +import static com.hjjang.backend.global.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.REDIRECT_URI_PARAM_COOKIE_NAME; +import static com.hjjang.backend.global.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.REFRESH_TOKEN; @Component @RequiredArgsConstructor diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/TokenAccessDeniedHandler.java b/backend/src/main/java/com/hjjang/backend/global/security/handler/TokenAccessDeniedHandler.java similarity index 94% rename from backend/src/main/java/com/hjjang/backend/global/config/security/handler/TokenAccessDeniedHandler.java rename to backend/src/main/java/com/hjjang/backend/global/security/handler/TokenAccessDeniedHandler.java index f974a06..5374e7c 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/handler/TokenAccessDeniedHandler.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/handler/TokenAccessDeniedHandler.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.global.config.security.handler; +package com.hjjang.backend.global.security.handler; import java.io.IOException; import javax.servlet.http.HttpServletRequest; diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/parser/KakaoParsingParsingUserContext.java b/backend/src/main/java/com/hjjang/backend/global/security/parser/KakaoParsingParsingUserContext.java similarity index 89% rename from backend/src/main/java/com/hjjang/backend/global/config/security/parser/KakaoParsingParsingUserContext.java rename to backend/src/main/java/com/hjjang/backend/global/security/parser/KakaoParsingParsingUserContext.java index 292e710..583bace 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/parser/KakaoParsingParsingUserContext.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/parser/KakaoParsingParsingUserContext.java @@ -1,6 +1,6 @@ -package com.hjjang.backend.global.config.security.parser; +package com.hjjang.backend.global.security.parser; -import static com.hjjang.backend.global.config.security.parser.KakaoParsingParsingUserContext.KakaoInfoProperties.*; +import static com.hjjang.backend.global.security.parser.KakaoParsingParsingUserContext.KakaoInfoProperties.*; import java.util.Map; diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/parser/ParsingUserContext.java b/backend/src/main/java/com/hjjang/backend/global/security/parser/ParsingUserContext.java similarity index 88% rename from backend/src/main/java/com/hjjang/backend/global/config/security/parser/ParsingUserContext.java rename to backend/src/main/java/com/hjjang/backend/global/security/parser/ParsingUserContext.java index e3392a6..f3198a3 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/parser/ParsingUserContext.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/parser/ParsingUserContext.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.global.config.security.parser; +package com.hjjang.backend.global.security.parser; import java.util.Map; diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/parser/ParsingUserContextFactory.java b/backend/src/main/java/com/hjjang/backend/global/security/parser/ParsingUserContextFactory.java similarity index 88% rename from backend/src/main/java/com/hjjang/backend/global/config/security/parser/ParsingUserContextFactory.java rename to backend/src/main/java/com/hjjang/backend/global/security/parser/ParsingUserContextFactory.java index 660a8dc..dac3639 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/parser/ParsingUserContextFactory.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/parser/ParsingUserContextFactory.java @@ -1,9 +1,9 @@ -package com.hjjang.backend.global.config.security.parser; - -import java.util.Map; +package com.hjjang.backend.global.security.parser; import com.hjjang.backend.domain.user.entity.ProviderType; +import java.util.Map; + public class ParsingUserContextFactory { public static ParsingUserContext getParsingParsingUserContext(ProviderType providerType, Map attributes) { diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/principal/UserPrincipal.java b/backend/src/main/java/com/hjjang/backend/global/security/principal/UserPrincipal.java similarity index 97% rename from backend/src/main/java/com/hjjang/backend/global/config/security/principal/UserPrincipal.java rename to backend/src/main/java/com/hjjang/backend/global/security/principal/UserPrincipal.java index cbae845..b34f7dc 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/principal/UserPrincipal.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/principal/UserPrincipal.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.global.config.security.principal; +package com.hjjang.backend.global.security.principal; import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.entity.User; diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/repository/OAuth2AuthorizationRequestBasedOnCookieRepository.java b/backend/src/main/java/com/hjjang/backend/global/security/repository/OAuth2AuthorizationRequestBasedOnCookieRepository.java similarity index 97% rename from backend/src/main/java/com/hjjang/backend/global/config/security/repository/OAuth2AuthorizationRequestBasedOnCookieRepository.java rename to backend/src/main/java/com/hjjang/backend/global/security/repository/OAuth2AuthorizationRequestBasedOnCookieRepository.java index dc4e802..b08fc15 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/repository/OAuth2AuthorizationRequestBasedOnCookieRepository.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/repository/OAuth2AuthorizationRequestBasedOnCookieRepository.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.global.config.security.repository; +package com.hjjang.backend.global.security.repository; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java b/backend/src/main/java/com/hjjang/backend/global/security/service/CustomOAuth2UserService.java similarity index 89% rename from backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java rename to backend/src/main/java/com/hjjang/backend/global/security/service/CustomOAuth2UserService.java index 1224372..c7efb1b 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/service/CustomOAuth2UserService.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/service/CustomOAuth2UserService.java @@ -1,12 +1,12 @@ -package com.hjjang.backend.global.config.security.service; +package com.hjjang.backend.global.security.service; import com.hjjang.backend.domain.user.entity.Agreement; import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.entity.User; import com.hjjang.backend.domain.user.repository.UserRepository; -import com.hjjang.backend.global.config.security.parser.KakaoParsingParsingUserContext; -import com.hjjang.backend.global.config.security.parser.ParsingUserContext; -import com.hjjang.backend.global.config.security.principal.UserPrincipal; +import com.hjjang.backend.global.security.parser.KakaoParsingParsingUserContext; +import com.hjjang.backend.global.security.parser.ParsingUserContext; +import com.hjjang.backend.global.security.principal.UserPrincipal; import lombok.RequiredArgsConstructor; import org.springframework.security.authentication.InternalAuthenticationServiceException; import org.springframework.security.core.AuthenticationException; diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/token/AuthToken.java b/backend/src/main/java/com/hjjang/backend/global/security/token/AuthToken.java similarity index 74% rename from backend/src/main/java/com/hjjang/backend/global/config/security/token/AuthToken.java rename to backend/src/main/java/com/hjjang/backend/global/security/token/AuthToken.java index 1a333e2..d9619da 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/token/AuthToken.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/token/AuthToken.java @@ -1,7 +1,4 @@ -package com.hjjang.backend.global.config.security.token; - -import java.security.Key; -import java.util.Date; +package com.hjjang.backend.global.security.token; import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; @@ -13,6 +10,9 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import java.security.Key; +import java.util.Date; + @Slf4j @RequiredArgsConstructor public class AuthToken { @@ -35,19 +35,19 @@ public class AuthToken { private String createAuthToken(String id, Date expiry) { return Jwts.builder() - .setSubject(id) - .signWith(key, SignatureAlgorithm.HS256) - .setExpiration(expiry) - .compact(); + .setSubject(id) + .signWith(key, SignatureAlgorithm.HS256) + .setExpiration(expiry) + .compact(); } private String createAuthToken(String id, String role, Date expiry) { return Jwts.builder() - .setSubject(id) - .claim(AUTHORITIES_KEY, role) - .signWith(key, SignatureAlgorithm.HS256) - .setExpiration(expiry) - .compact(); + .setSubject(id) + .claim(AUTHORITIES_KEY, role) + .signWith(key, SignatureAlgorithm.HS256) + .setExpiration(expiry) + .compact(); } public boolean validate() { @@ -57,10 +57,10 @@ public boolean validate() { public Claims getTokenClaims() { try { return Jwts.parserBuilder() - .setSigningKey(key) - .build() - .parseClaimsJws(token) - .getBody(); + .setSigningKey(key) + .build() + .parseClaimsJws(token) + .getBody(); } catch (SecurityException e) { log.info("Invalid JWT signature."); } catch (MalformedJwtException e) { @@ -78,10 +78,10 @@ public Claims getTokenClaims() { public Claims getExpiredTokenClaims() { try { Jwts.parserBuilder() - .setSigningKey(key) - .build() - .parseClaimsJws(token) - .getBody(); + .setSigningKey(key) + .build() + .parseClaimsJws(token) + .getBody(); } catch (ExpiredJwtException e) { log.info("Expired JWT token."); return e.getClaims(); diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/token/AuthTokenProvider.java b/backend/src/main/java/com/hjjang/backend/global/security/token/AuthTokenProvider.java similarity index 93% rename from backend/src/main/java/com/hjjang/backend/global/config/security/token/AuthTokenProvider.java rename to backend/src/main/java/com/hjjang/backend/global/security/token/AuthTokenProvider.java index 84d4f0e..27c30c4 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/token/AuthTokenProvider.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/token/AuthTokenProvider.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.global.config.security.token; +package com.hjjang.backend.global.security.token; import java.security.Key; import java.util.Arrays; @@ -12,7 +12,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.User; -import com.hjjang.backend.global.config.security.exception.TokenValidFailedException; +import com.hjjang.backend.global.security.exception.TokenValidFailedException; import io.jsonwebtoken.Claims; import io.jsonwebtoken.security.Keys; From 296435454ca439dc3fe8e9396ae220ec4e18b48c Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 18:24:12 +0900 Subject: [PATCH 06/57] style: move directory --- .../config/security/SecurityConfig.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java index 63860b0..1adaf9b 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java @@ -1,7 +1,16 @@ package com.hjjang.backend.global.config.security; -import java.util.Arrays; - +import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; +import com.hjjang.backend.global.config.security.properties.AuthProperties; +import com.hjjang.backend.global.security.exception.RestAuthenticationEntryPoint; +import com.hjjang.backend.global.security.filter.TokenAuthenticationFilter; +import com.hjjang.backend.global.security.handler.OAuth2AuthenticationFailureHandler; +import com.hjjang.backend.global.security.handler.OAuth2AuthenticationSuccessHandler; +import com.hjjang.backend.global.security.handler.TokenAccessDeniedHandler; +import com.hjjang.backend.global.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository; +import com.hjjang.backend.global.security.service.CustomOAuth2UserService; +import com.hjjang.backend.global.security.token.AuthTokenProvider; +import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; @@ -17,18 +26,7 @@ import org.springframework.web.cors.CorsUtils; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; -import com.hjjang.backend.global.config.properties.AuthProperties; -import com.hjjang.backend.global.config.security.exception.RestAuthenticationEntryPoint; -import com.hjjang.backend.global.config.security.filter.TokenAuthenticationFilter; -import com.hjjang.backend.global.config.security.handler.OAuth2AuthenticationFailureHandler; -import com.hjjang.backend.global.config.security.handler.OAuth2AuthenticationSuccessHandler; -import com.hjjang.backend.global.config.security.handler.TokenAccessDeniedHandler; -import com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository; -import com.hjjang.backend.global.config.security.service.CustomOAuth2UserService; -import com.hjjang.backend.global.config.security.token.AuthTokenProvider; - -import lombok.RequiredArgsConstructor; +import java.util.Arrays; @Configuration @EnableWebSecurity From 7f67b3f5945ebc23810615750551b20fe3638f47 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 23:17:08 +0900 Subject: [PATCH 07/57] =?UTF-8?q?fix:=20=EB=A1=9C=EA=B7=B8=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=EB=A1=9C=20=EC=95=88=EB=82=98=EC=98=A4=EA=B2=8C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/log4j2.xml | 6 ++--- backend/src/test/resources/log4j2-test.xml | 29 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 backend/src/test/resources/log4j2-test.xml diff --git a/backend/src/main/resources/log4j2.xml b/backend/src/main/resources/log4j2.xml index d1d1de7..81b43b7 100644 --- a/backend/src/main/resources/log4j2.xml +++ b/backend/src/main/resources/log4j2.xml @@ -25,18 +25,18 @@ - + - + - + \ No newline at end of file diff --git a/backend/src/test/resources/log4j2-test.xml b/backend/src/test/resources/log4j2-test.xml new file mode 100644 index 0000000..ffa424d --- /dev/null +++ b/backend/src/test/resources/log4j2-test.xml @@ -0,0 +1,29 @@ + + + + + Default-Setting + %style{%d{yyyy/MM/dd HH:mm:ss,SSS}}{cyan} %highlight{[%-5p]}{FATAL=bg_red, ERROR=red, INFO=green, DEBUG=blue} [%C] %style{[%t]}{yellow}- %m%n - + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 93c86ad9c90e974b29318d27a413bada8bde64fc Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 23:17:25 +0900 Subject: [PATCH 08/57] =?UTF-8?q?fix:=20lombok=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/lombok.config | 1 + 1 file changed, 1 insertion(+) create mode 100644 backend/lombok.config diff --git a/backend/lombok.config b/backend/lombok.config new file mode 100644 index 0000000..8f7e8aa --- /dev/null +++ b/backend/lombok.config @@ -0,0 +1 @@ +lombok.addLombokGeneratedAnnotation = true \ No newline at end of file From ad0410ea296f81c994d74db7efc40dc4d38c8ce6 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 23:18:59 +0900 Subject: [PATCH 09/57] style: move security directory --- .../user/controller/UserAuthController.java | 6 ++--- .../domain/user/service/UserAuthService.java | 25 ++++++++----------- .../RestAuthenticationEntryPoint.java | 10 +++----- .../filter/TokenAuthenticationFilter.java | 21 +++++++--------- .../global/security/token/AuthToken.java | 7 +----- .../security/token/AuthTokenProvider.java | 20 +++++++-------- 6 files changed, 37 insertions(+), 52 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java index 1cc3f30..695fc01 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java @@ -4,9 +4,9 @@ import com.hjjang.backend.domain.user.entity.UserRefreshToken; import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; import com.hjjang.backend.domain.user.service.UserAuthService; -import com.hjjang.backend.global.config.properties.AuthProperties; -import com.hjjang.backend.global.config.security.token.AuthToken; -import com.hjjang.backend.global.config.security.token.AuthTokenProvider; +import com.hjjang.backend.global.config.security.properties.AuthProperties; +import com.hjjang.backend.global.security.token.AuthToken; +import com.hjjang.backend.global.security.token.AuthTokenProvider; import com.hjjang.backend.global.dto.ApiResponse; import com.hjjang.backend.global.util.CookieUtil; import com.hjjang.backend.global.util.HeaderUtil; diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java index 29ec82c..d0171f5 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java @@ -1,23 +1,20 @@ package com.hjjang.backend.domain.user.service; -import static com.hjjang.backend.global.config.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.*; - -import java.util.Date; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.stereotype.Service; - import com.hjjang.backend.domain.user.entity.UserRefreshToken; import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; -import com.hjjang.backend.global.config.properties.AuthProperties; -import com.hjjang.backend.global.config.security.token.AuthToken; -import com.hjjang.backend.global.config.security.token.AuthTokenProvider; +import com.hjjang.backend.global.config.security.properties.AuthProperties; +import com.hjjang.backend.global.security.token.AuthToken; +import com.hjjang.backend.global.security.token.AuthTokenProvider; import com.hjjang.backend.global.util.CookieUtil; - import lombok.RequiredArgsConstructor; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Date; + +import static com.hjjang.backend.global.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.REFRESH_TOKEN; @RequiredArgsConstructor @Service diff --git a/backend/src/main/java/com/hjjang/backend/global/security/exception/RestAuthenticationEntryPoint.java b/backend/src/main/java/com/hjjang/backend/global/security/exception/RestAuthenticationEntryPoint.java index cfe5bba..28b47c1 100644 --- a/backend/src/main/java/com/hjjang/backend/global/security/exception/RestAuthenticationEntryPoint.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/exception/RestAuthenticationEntryPoint.java @@ -1,15 +1,13 @@ package com.hjjang.backend.global.security.exception; -import java.io.IOException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.AuthenticationEntryPoint; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - -import org.springframework.security.core.AuthenticationException; -import org.springframework.security.web.AuthenticationEntryPoint; - -import lombok.extern.slf4j.Slf4j; +import java.io.IOException; @Slf4j public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint { diff --git a/backend/src/main/java/com/hjjang/backend/global/security/filter/TokenAuthenticationFilter.java b/backend/src/main/java/com/hjjang/backend/global/security/filter/TokenAuthenticationFilter.java index 1a0dbf1..1cedb98 100644 --- a/backend/src/main/java/com/hjjang/backend/global/security/filter/TokenAuthenticationFilter.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/filter/TokenAuthenticationFilter.java @@ -1,22 +1,19 @@ package com.hjjang.backend.global.security.filter; -import java.io.IOException; - -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.web.filter.OncePerRequestFilter; - import com.hjjang.backend.global.security.token.AuthToken; import com.hjjang.backend.global.security.token.AuthTokenProvider; import com.hjjang.backend.global.util.HeaderUtil; - import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; @Slf4j @RequiredArgsConstructor diff --git a/backend/src/main/java/com/hjjang/backend/global/security/token/AuthToken.java b/backend/src/main/java/com/hjjang/backend/global/security/token/AuthToken.java index d9619da..a212b26 100644 --- a/backend/src/main/java/com/hjjang/backend/global/security/token/AuthToken.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/token/AuthToken.java @@ -1,11 +1,6 @@ package com.hjjang.backend.global.security.token; -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.ExpiredJwtException; -import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.MalformedJwtException; -import io.jsonwebtoken.SignatureAlgorithm; -import io.jsonwebtoken.UnsupportedJwtException; +import io.jsonwebtoken.*; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/backend/src/main/java/com/hjjang/backend/global/security/token/AuthTokenProvider.java b/backend/src/main/java/com/hjjang/backend/global/security/token/AuthTokenProvider.java index 27c30c4..912c135 100644 --- a/backend/src/main/java/com/hjjang/backend/global/security/token/AuthTokenProvider.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/token/AuthTokenProvider.java @@ -1,22 +1,20 @@ package com.hjjang.backend.global.security.token; -import java.security.Key; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.stream.Collectors; - +import com.hjjang.backend.global.security.exception.TokenValidFailedException; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.security.Keys; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.User; -import com.hjjang.backend.global.security.exception.TokenValidFailedException; - -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.security.Keys; -import lombok.extern.slf4j.Slf4j; +import java.security.Key; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.stream.Collectors; @Slf4j public class AuthTokenProvider { From 91f04d9399813ab6426b2ffccd44689b37b20185 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 23:20:24 +0900 Subject: [PATCH 10/57] =?UTF-8?q?feat:=20add=20User=20=EB=AC=B8=EC=84=9C?= =?UTF-8?q?=ED=99=94=20handler=20UserRestDocument.java=20=EC=A0=9C?= =?UTF-8?q?=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/api/docs/UserRestDocument.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 backend/src/test/java/com/hjjang/backend/api/docs/UserRestDocument.java diff --git a/backend/src/test/java/com/hjjang/backend/api/docs/UserRestDocument.java b/backend/src/test/java/com/hjjang/backend/api/docs/UserRestDocument.java new file mode 100644 index 0000000..66f5354 --- /dev/null +++ b/backend/src/test/java/com/hjjang/backend/api/docs/UserRestDocument.java @@ -0,0 +1,29 @@ +package com.hjjang.backend.api.docs; + +import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; +import org.springframework.restdocs.payload.JsonFieldType; + +import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; + +public class UserRestDocument { + public static RestDocumentationResultHandler getProfile() { + return document("v1/users/profile", + requestHeaders( + headerWithName("authorization").description("Bearer 토큰")), + responseFields( + fieldWithPath("status").type(JsonFieldType.NUMBER).description("status code"), + fieldWithPath("code").type(JsonFieldType.STRING).description("Business code"), + fieldWithPath("message").type(JsonFieldType.STRING).description("response message"), + fieldWithPath("data.userNickname").type(JsonFieldType.STRING).description("user 닉네임"), + fieldWithPath("data.userImageUrl").type(JsonFieldType.STRING).description("user 프로필 사진"), + fieldWithPath("data.userEmail").type(JsonFieldType.STRING).description("user 이메일"), + fieldWithPath("data.userMannerTemperature").type(JsonFieldType.NUMBER).description("user 매너 온도"), + fieldWithPath("data.userUnivName").type(JsonFieldType.STRING).description("user 대학 이름") + ) + ); + } +} From 3c764dd783f14ecaa23f9b6fd08f22d7accd105e Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 23:21:22 +0900 Subject: [PATCH 11/57] feat: add user repository test --- .../user/repository/UserRepositoryTest.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 backend/src/test/java/com/hjjang/backend/user/repository/UserRepositoryTest.java diff --git a/backend/src/test/java/com/hjjang/backend/user/repository/UserRepositoryTest.java b/backend/src/test/java/com/hjjang/backend/user/repository/UserRepositoryTest.java new file mode 100644 index 0000000..fb59316 --- /dev/null +++ b/backend/src/test/java/com/hjjang/backend/user/repository/UserRepositoryTest.java @@ -0,0 +1,66 @@ +package com.hjjang.backend.user.repository; + +import com.hjjang.backend.domain.user.entity.Agreement; +import com.hjjang.backend.domain.user.entity.RoleType; +import com.hjjang.backend.domain.user.entity.User; +import com.hjjang.backend.domain.user.repository.UserRepository; +import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +import javax.persistence.EntityExistsException; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@DataJpaTest +public class UserRepositoryTest { + + @Autowired + private UserRepository userRepository; + + private User givenUser; + private User newUser; + + @BeforeEach + void setUp() { + givenUser = User.builder() + .email("tester@tukorea.ac.kr") + .imageUrl("이미지 url") + .isPushAgree(Agreement.AGREE) + .mannerTemperature(36L) + .nickName("kevinkim") + .providerId("123412512") + .role(RoleType.USER) + .univId(null) + .build(); + + newUser = userRepository.save(givenUser); + } + + @DisplayName("userId로 사용자 조회") + @Test + public void findUserById_test() { + System.out.println(newUser.getProviderId()); + User foundUser = userRepository.findUserById(newUser.getId()).orElseThrow(EntityExistsException::new); + + assertAll( + () -> assertEquals(foundUser, newUser) + ); + } + + @DisplayName("providerId로 사용자 조회") + @Test + public void findUserByProviderId_test() { + + User foundUser = userRepository.findUserByProviderId(newUser.getProviderId()) + .orElseThrow(EntityExistsException::new); + + assertAll( + () -> assertEquals(foundUser, newUser) + ); + } + +} From d5d740b5f1c5adfb8108c5a5165e264b9c63da44 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 23:22:02 +0900 Subject: [PATCH 12/57] fix: fix dependency --- backend/build.gradle | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/build.gradle b/backend/build.gradle index 77479cc..5c8b8e1 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -14,6 +14,9 @@ configurations { compileOnly { extendsFrom annotationProcessor } + all { + exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' + } } repositories { @@ -43,7 +46,9 @@ dependencies { runtimeOnly 'mysql:mysql-connector-java' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation('org.springframework.boot:spring-boot-starter-test') { + exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' //junit 4 하위 호환을 위한 라이브러리 제거 + } testImplementation 'org.springframework.batch:spring-batch-test' testImplementation 'org.springframework.kafka:spring-kafka-test' testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' @@ -53,14 +58,11 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-api:0.11.2' runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2' - implementation 'org.springframework.boot:spring-boot-starter-log4j2' - + implementation "org.springframework.boot:spring-boot-starter-log4j2" + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' } -configurations { - all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' - all*.exclude group: 'org.springframework.boot', module: 'logback-classic' -} tasks.named('compileJava') { inputs.files(tasks.named('processResources')) From 46f46f320b8ea5d7edab78856825456327f26558 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 3 May 2022 23:22:26 +0900 Subject: [PATCH 13/57] feat: add user controller test --- .../backend/api/UserControllerTest.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 backend/src/test/java/com/hjjang/backend/api/UserControllerTest.java diff --git a/backend/src/test/java/com/hjjang/backend/api/UserControllerTest.java b/backend/src/test/java/com/hjjang/backend/api/UserControllerTest.java new file mode 100644 index 0000000..4e11d2a --- /dev/null +++ b/backend/src/test/java/com/hjjang/backend/api/UserControllerTest.java @@ -0,0 +1,90 @@ +package com.hjjang.backend.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.hjjang.backend.api.docs.UserRestDocument; +import com.hjjang.backend.domain.user.controller.UserController; +import com.hjjang.backend.domain.user.dto.UserProfileDTO; +import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; +import com.hjjang.backend.domain.user.repository.UserRepository; +import com.hjjang.backend.domain.user.service.UserProfileService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.http.MediaType; +import org.springframework.restdocs.RestDocumentationContextProvider; +import org.springframework.restdocs.RestDocumentationExtension; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.filter.CharacterEncodingFilter; + +import java.nio.charset.StandardCharsets; + +import static org.mockito.Mockito.when; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@ComponentScan(basePackages = "com.hjjang.backend.global.config.security") +@ComponentScan(basePackages = "com.hjjang.backend.global.security") +@ExtendWith(RestDocumentationExtension.class) +@WebMvcTest(controllers = UserController.class) +class UserControllerTest { + + @MockBean + protected UserRepository userRepository; + + @MockBean + protected UserRefreshTokenRepository userRefreshTokenRepository; + + @InjectMocks + private UserController userController; + + @MockBean + private UserProfileService userProfileService; + + private ObjectMapper objectMapper; + + private MockMvc mockMvc; + + @BeforeEach + void setUp(WebApplicationContext webApplicationContext, RestDocumentationContextProvider restDocumentationContextProvider) { + objectMapper = new ObjectMapper(); + + mockMvc = MockMvcBuilders + .webAppContextSetup(webApplicationContext) + .addFilter(new CharacterEncodingFilter(StandardCharsets.UTF_8.name(), true)) + .apply(documentationConfiguration(restDocumentationContextProvider)) + .apply(springSecurity()) + .build(); + + } + + @Test + @DisplayName("유저 프로필 정보 조회") + void get_user_profile_success() throws Exception { + UserProfileDTO userProfileDTO = UserProfileDTO.builder() + .userEmail("tester@tukorea.ac.kr") + .userImageUrl("이미지 url입니다") + .userNickname("내 닉네임은 테스타") + .userMannerTemperature(36L) + .userUnivName("한국공학대") + .build(); + when(userProfileService.getUserProfile()).thenReturn(userProfileDTO); + + mockMvc.perform(get("/api/v1/users/profile") + .header("authorization", "Bearer USER_TOKEN") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andDo(print()) + .andDo(UserRestDocument.getProfile()); + } + +} \ No newline at end of file From 2b86ce8201ff2b16b2b6009db9a151c7765b6ef6 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Fri, 6 May 2022 14:43:22 +0900 Subject: [PATCH 14/57] =?UTF-8?q?feat:=20BaseTimeEntity=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=EC=97=90=20=EB=93=A4=EC=96=B4=EA=B0=80?= =?UTF-8?q?=EB=8A=94=20=EA=B3=B5=ED=86=B5=20=EC=83=9D=EC=84=B1=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=88=98=EC=A0=95=EC=8B=9C=EA=B0=84=20=EA=B8=B0?= =?UTF-8?q?=EB=A1=9D=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/user/entity/User.java | 16 +++++--------- .../global/config/JpaAuditingConfig.java | 9 -------- .../backend/global/domain/BaseTimeEntity.java | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+), 20 deletions(-) delete mode 100644 backend/src/main/java/com/hjjang/backend/global/config/JpaAuditingConfig.java create mode 100644 backend/src/main/java/com/hjjang/backend/global/domain/BaseTimeEntity.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java index 9b2af8d..fd0cafd 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java @@ -1,14 +1,12 @@ package com.hjjang.backend.domain.user.entity; +import com.hjjang.backend.global.domain.BaseTimeEntity; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; -import java.time.LocalDateTime; import static javax.persistence.EnumType.STRING; import static javax.persistence.GenerationType.IDENTITY; @@ -16,11 +14,10 @@ @Getter @AllArgsConstructor -@EntityListeners(AuditingEntityListener.class) @Entity @NoArgsConstructor(access = PROTECTED) @Table(name = "user") -public class User { +public class User extends BaseTimeEntity { @Id @GeneratedValue(strategy = IDENTITY) @@ -42,10 +39,6 @@ public class User { @Column(name = "image_url", nullable = true, length = 50) private String imageUrl; - @CreatedDate - @Column(name = "created_at", nullable = false) - private LocalDateTime createdAt; - @Enumerated(STRING) @Column(name = "is_push_agree", nullable = false, length = 10) private Agreement isPushAgree; @@ -53,12 +46,13 @@ public class User { @Column(name = "univ_id") private Long univId; - @Column(name = "role",length = 20) + @Column(name = "role", length = 20) @Enumerated(STRING) private RoleType role; @Builder - public User(String providerId, String nickName, String email, Long mannerTemperature, String imageUrl, Agreement isPushAgree, Long univId, RoleType role) { + public User(String providerId, String nickName, String email, Long mannerTemperature, + String imageUrl, Agreement isPushAgree, Long univId, RoleType role) { this.providerId = providerId; this.nickName = nickName; this.email = email; diff --git a/backend/src/main/java/com/hjjang/backend/global/config/JpaAuditingConfig.java b/backend/src/main/java/com/hjjang/backend/global/config/JpaAuditingConfig.java deleted file mode 100644 index f7916b1..0000000 --- a/backend/src/main/java/com/hjjang/backend/global/config/JpaAuditingConfig.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.hjjang.backend.global.config; - -import org.springframework.context.annotation.Configuration; -import org.springframework.data.jpa.repository.config.EnableJpaAuditing; - -@Configuration -@EnableJpaAuditing -public class JpaAuditingConfig { -} \ No newline at end of file diff --git a/backend/src/main/java/com/hjjang/backend/global/domain/BaseTimeEntity.java b/backend/src/main/java/com/hjjang/backend/global/domain/BaseTimeEntity.java new file mode 100644 index 0000000..fddf0d6 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/global/domain/BaseTimeEntity.java @@ -0,0 +1,21 @@ +package com.hjjang.backend.global.domain; + +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.EntityListeners; +import javax.persistence.MappedSuperclass; +import java.time.LocalDateTime; + +@Getter +@EntityListeners(value = {AuditingEntityListener.class}) +@MappedSuperclass +public abstract class BaseTimeEntity { + @CreatedDate + private LocalDateTime createdDate; + + @LastModifiedDate + private LocalDateTime updatedDate; +} \ No newline at end of file From 841032a9408831b59d5d77f8fb9f89d0dcb872bc Mon Sep 17 00:00:00 2001 From: kim1387 Date: Fri, 6 May 2022 14:46:26 +0900 Subject: [PATCH 15/57] =?UTF-8?q?feat:=20repository=20test=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20h2=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 57 +++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/backend/build.gradle b/backend/build.gradle index 5c8b8e1..2610980 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.springframework.boot' version '2.6.6' + id 'org.springframework.boot' version '2.6.4' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'org.asciidoctor.convert' version '1.5.8' id 'java' @@ -14,9 +14,6 @@ configurations { compileOnly { extendsFrom annotationProcessor } - all { - exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' - } } repositories { @@ -28,39 +25,65 @@ ext { } dependencies { + + // 모니터링 관련 의존성 implementation 'org.springframework.boot:spring-boot-starter-actuator' + runtimeOnly 'io.micrometer:micrometer-registry-prometheus' + implementation 'org.springframework.boot:spring-boot-starter-batch' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-redis' implementation 'org.springframework.boot:spring-boot-starter-mail' - implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' - implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-websocket' implementation 'org.flywaydb:flyway-core' implementation 'org.springframework.kafka:spring-kafka' + + // 롬복 관련 의존성 compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + developmentOnly 'org.springframework.boot:spring-boot-devtools' - runtimeOnly 'io.micrometer:micrometer-registry-prometheus' + runtimeOnly 'mysql:mysql-connector-java' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' - annotationProcessor 'org.projectlombok:lombok' - testImplementation('org.springframework.boot:spring-boot-starter-test') { - exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' //junit 4 하위 호환을 위한 라이브러리 제거 - } - testImplementation 'org.springframework.batch:spring-batch-test' - testImplementation 'org.springframework.kafka:spring-kafka-test' - testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' - testImplementation 'org.springframework.security:spring-security-test' - implementation 'org.springdoc:springdoc-openapi-ui:1.6.6' + testAnnotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' + //swagger-ui + implementation 'org.springdoc:springdoc-openapi-ui:1.6.8' //jwt 관련 의존성 implementation 'io.jsonwebtoken:jjwt-api:0.11.2' runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2' - implementation "org.springframework.boot:spring-boot-starter-log4j2" + + // oauth 관련 의존성 + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + implementation 'org.springframework.boot:spring-boot-starter-security' + + implementation 'com.google.guava:guava:31.1-jre' + + // test를 위한 의존성 + testImplementation 'org.springframework.batch:spring-batch-test' + testImplementation 'org.springframework.kafka:spring-kafka-test' + testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + testImplementation 'org.springframework.security:spring-security-test' + testImplementation('org.springframework.boot:spring-boot-starter-test') { + exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' //junit 4 하위 호환을 위한 라이브러리 제거 + } testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' + runtimeOnly 'com.h2database:h2' + + 로깅 관련 의존성 + implementation "org.springframework.boot:spring-boot-starter-log4j2" + testImplementation 'org.springframework.boot:spring-boot-starter-log4j2' + modules { + module("org.springframework.boot:spring-boot-starter-logging") { + replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback") + } + } + implementation 'org.apache.logging.log4j:log4j-web:2.17.2' } From 54f54ae8c83090d1902d66f20a86acea0351d52d Mon Sep 17 00:00:00 2001 From: kim1387 Date: Fri, 6 May 2022 14:46:41 +0900 Subject: [PATCH 16/57] =?UTF-8?q?feat:=20add=20log4j=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/log4j2.xml | 15 ++------------- backend/src/test/resources/log4j2-test.xml | 2 ++ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/backend/src/main/resources/log4j2.xml b/backend/src/main/resources/log4j2.xml index 81b43b7..d490d33 100644 --- a/backend/src/main/resources/log4j2.xml +++ b/backend/src/main/resources/log4j2.xml @@ -1,5 +1,5 @@ - + Default-Setting @@ -11,14 +11,7 @@ - - - - - - - - + @@ -34,9 +27,5 @@ - - - - \ No newline at end of file diff --git a/backend/src/test/resources/log4j2-test.xml b/backend/src/test/resources/log4j2-test.xml index ffa424d..621bd5e 100644 --- a/backend/src/test/resources/log4j2-test.xml +++ b/backend/src/test/resources/log4j2-test.xml @@ -11,6 +11,7 @@ + @@ -25,5 +26,6 @@ + \ No newline at end of file From 2eecfc2b7132d954d5bc13132c22b15a50f9ffde Mon Sep 17 00:00:00 2001 From: kim1387 Date: Fri, 6 May 2022 14:47:00 +0900 Subject: [PATCH 17/57] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EB=93=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserAuthController.java | 81 ------------------- .../backend/domain/user/dto/LoginRequest.java | 15 ---- .../domain/user/service/UserAuthService.java | 52 ------------ 3 files changed, 148 deletions(-) delete mode 100644 backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java delete mode 100644 backend/src/main/java/com/hjjang/backend/domain/user/dto/LoginRequest.java delete mode 100644 backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java deleted file mode 100644 index 695fc01..0000000 --- a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserAuthController.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.hjjang.backend.domain.user.controller; - -import com.hjjang.backend.domain.user.entity.RoleType; -import com.hjjang.backend.domain.user.entity.UserRefreshToken; -import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; -import com.hjjang.backend.domain.user.service.UserAuthService; -import com.hjjang.backend.global.config.security.properties.AuthProperties; -import com.hjjang.backend.global.security.token.AuthToken; -import com.hjjang.backend.global.security.token.AuthTokenProvider; -import com.hjjang.backend.global.dto.ApiResponse; -import com.hjjang.backend.global.util.CookieUtil; -import com.hjjang.backend.global.util.HeaderUtil; -import io.jsonwebtoken.Claims; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.Date; - -@RestController -@RequestMapping("/api/v1/auth") -@RequiredArgsConstructor -public class UserAuthController { - - private final AuthProperties authProperties; - private final AuthTokenProvider tokenProvider; - private final UserRefreshTokenRepository userRefreshTokenRepository; - private final UserAuthService userAuthService; - - private static final long THREE_DAYS_MSEC = 259200000; - private static final String REFRESH_TOKEN = "refresh_token"; - - @GetMapping("/refresh") - public ApiResponse refreshToken(HttpServletRequest request, HttpServletResponse response) { - // access token 확인 - String accessToken = HeaderUtil.getAccessToken(request); - AuthToken authToken = tokenProvider.convertAuthToken(accessToken); - if (!authToken.validate()) { - return ApiResponse.invalidAccessToken(); - } - - // 만료된 access token 인지 확인 - Claims claims = authToken.getExpiredTokenClaims(); - if (claims == null) { - return ApiResponse.notExpiredTokenYet(); - } - String providerId = claims.getSubject(); - RoleType roleType = RoleType.of(claims.get("role", String.class)); - - // refresh token - String refreshToken = CookieUtil.getCookie(request, REFRESH_TOKEN) - .map(Cookie::getValue) - .orElse((null)); - AuthToken authRefreshToken = tokenProvider.convertAuthToken(refreshToken); - - if (authRefreshToken.validate()) { - return ApiResponse.invalidRefreshToken(); - } - - // providerId, refresh token 으로 DB 확인 - UserRefreshToken userRefreshToken = userRefreshTokenRepository.findByProviderIdAndRefreshToken(providerId, - refreshToken); - if (userRefreshToken == null) { - return ApiResponse.invalidRefreshToken(); - } - - Date now = new Date(); - AuthToken newAccessToken = tokenProvider.createAuthToken( - providerId, roleType.getCode(), - new Date(now.getTime() + authProperties.getTokenProperties().getTokenExpireDate()) - ); - userAuthService.reissueRefreshTokenIfValidTimeleft3days(request, response, userRefreshToken, authRefreshToken, - now); - - return ApiResponse.success("token", newAccessToken.getToken()); - } -} diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/dto/LoginRequest.java b/backend/src/main/java/com/hjjang/backend/domain/user/dto/LoginRequest.java deleted file mode 100644 index 85b3357..0000000 --- a/backend/src/main/java/com/hjjang/backend/domain/user/dto/LoginRequest.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hjjang.backend.domain.user.dto; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -public class LoginRequest { - private String id; - private String password; -} diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java deleted file mode 100644 index d0171f5..0000000 --- a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserAuthService.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.hjjang.backend.domain.user.service; - -import com.hjjang.backend.domain.user.entity.UserRefreshToken; -import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; -import com.hjjang.backend.global.config.security.properties.AuthProperties; -import com.hjjang.backend.global.security.token.AuthToken; -import com.hjjang.backend.global.security.token.AuthTokenProvider; -import com.hjjang.backend.global.util.CookieUtil; -import lombok.RequiredArgsConstructor; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.stereotype.Service; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.Date; - -import static com.hjjang.backend.global.security.repository.OAuth2AuthorizationRequestBasedOnCookieRepository.REFRESH_TOKEN; - -@RequiredArgsConstructor -@Service -public class UserAuthService { - - private final AuthProperties authProperties; - private final AuthTokenProvider tokenProvider; - private final AuthenticationManager authenticationManager; - private final UserRefreshTokenRepository userRefreshTokenRepository; - private final static long THREE_DAYS_MSEC = 259200000; - - public void reissueRefreshTokenIfValidTimeleft3days(HttpServletRequest request, HttpServletResponse response, - UserRefreshToken userRefreshToken, AuthToken authRefreshToken, Date now) { - long validTime = authRefreshToken.getTokenClaims().getExpiration().getTime() - now.getTime(); - - // refresh 토큰 기간이 3일 이하로 남은 경우, refresh 토큰 갱신 - if (validTime <= THREE_DAYS_MSEC) { - // refresh 토큰 설정 - long refreshTokenExpiry = authProperties.getTokenProperties().getRefreshTokenExpiry(); - - authRefreshToken = tokenProvider.createAuthToken( - authProperties.getTokenProperties().getTokenSecretKey(), - new Date(now.getTime() + refreshTokenExpiry) - ); - - // DB에 refresh 토큰 업데이트 - userRefreshToken.reissueRefreshToken(authRefreshToken.getToken()); - - int cookieMaxAge = (int)refreshTokenExpiry / 60; - CookieUtil.deleteCookie(request, response, REFRESH_TOKEN); - CookieUtil.addCookie(response, REFRESH_TOKEN, authRefreshToken.getToken(), cookieMaxAge); - } - } - -} From befa1f9a2e234335cc7cc0e99391ff74eb9decd4 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Fri, 6 May 2022 14:47:24 +0900 Subject: [PATCH 18/57] =?UTF-8?q?fix:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EC=A3=BC=EC=84=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/build.gradle b/backend/build.gradle index 2610980..90388b4 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -75,7 +75,7 @@ dependencies { testAnnotationProcessor 'org.projectlombok:lombok' runtimeOnly 'com.h2database:h2' - 로깅 관련 의존성 +// 로깅 관련 의존성 implementation "org.springframework.boot:spring-boot-starter-log4j2" testImplementation 'org.springframework.boot:spring-boot-starter-log4j2' modules { From 4065261f7b3ea69f4729c715929d4db075741eee Mon Sep 17 00:00:00 2001 From: kim1387 Date: Fri, 6 May 2022 14:48:10 +0900 Subject: [PATCH 19/57] =?UTF-8?q?feat:=20h2-console=20security=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=EC=95=88=ED=95=98=EA=B2=8C=20=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/config/security/SecurityConfig.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java index 1adaf9b..d82824c 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java @@ -39,6 +39,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { private final TokenAccessDeniedHandler tokenAccessDeniedHandler; private final UserRefreshTokenRepository userRefreshTokenRepository; + @SuppressWarnings("checkstyle:WhitespaceAfter") @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers("/static/css/**", "/static/js/**", "*.ico"); // 나중에 수정 @@ -46,7 +47,7 @@ public void configure(WebSecurity web) throws Exception { // swagger web.ignoring().antMatchers( "/v2/api-docs", "/configuration/ui", "/swagger-resources", - "/configuration/security", "/swagger-ui.html", "/webjars/**", "/swagger/**"); + "/configuration/security", "/swagger-ui.html", "/webjars/**", "/swagger/**", "/h2-console/**"); } @@ -73,7 +74,7 @@ protected void configure(HttpSecurity http) throws Exception { .accessDeniedHandler(tokenAccessDeniedHandler) // 로그인 거부 예외 .and() .authorizeRequests() - .antMatchers("/login", "/accounts", "/swagger-resources/**", "/swagger-ui/**").permitAll() + .antMatchers("/login", "/accounts", "/swagger-resources/**", "/swagger-ui/**", "/h2-console/**").permitAll() .antMatchers("/oauth2/authorization/**", "**/oauth2/code/*").permitAll() .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() //cors를 검증 하는 option 함수의 경우 별도의 filter 없이 허용 // .antMatchers("/api/**").hasAnyAuthority(RoleType.USER.getCode()) From 51ea6bad25b9318c7e68f4c407d4b5c5606924ff Mon Sep 17 00:00:00 2001 From: kim1387 Date: Fri, 6 May 2022 14:50:08 +0900 Subject: [PATCH 20/57] =?UTF-8?q?fix:=20=EC=9A=B4=EC=98=81=20compose=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=97=90=EC=84=9C=20=EC=A0=81=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index ddab888..779076c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,7 +23,7 @@ services: backend: container_name: bauction-backend build: ./backend - restart: on-failure +# restart: on-failure depends_on: - mysqldb ports: From b87669132dce3a0ed7be1649ee785b33365572f2 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Fri, 6 May 2022 14:52:07 +0900 Subject: [PATCH 21/57] =?UTF-8?q?fix:=20@Test=20junit=204=20=EB=A7=90?= =?UTF-8?q?=EA=B3=A0=205=EB=A1=9C=20=EC=A0=81=EC=9A=A9=ED=95=98=EA=B8=B0?= =?UTF-8?q?=20=EB=A9=94=EC=86=8C=EB=93=9C=20private=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit junit 5에서는 public일 필요가 없음 --- .../backend/user/repository/UserRepositoryTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/test/java/com/hjjang/backend/user/repository/UserRepositoryTest.java b/backend/src/test/java/com/hjjang/backend/user/repository/UserRepositoryTest.java index fb59316..415f756 100644 --- a/backend/src/test/java/com/hjjang/backend/user/repository/UserRepositoryTest.java +++ b/backend/src/test/java/com/hjjang/backend/user/repository/UserRepositoryTest.java @@ -4,9 +4,9 @@ import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.entity.User; import com.hjjang.backend.domain.user.repository.UserRepository; -import org.junit.Test; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @@ -16,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @DataJpaTest -public class UserRepositoryTest { +class UserRepositoryTest { @Autowired private UserRepository userRepository; @@ -42,7 +42,7 @@ void setUp() { @DisplayName("userId로 사용자 조회") @Test - public void findUserById_test() { + void findUserById_test() { System.out.println(newUser.getProviderId()); User foundUser = userRepository.findUserById(newUser.getId()).orElseThrow(EntityExistsException::new); @@ -53,7 +53,7 @@ public void findUserById_test() { @DisplayName("providerId로 사용자 조회") @Test - public void findUserByProviderId_test() { + void findUserByProviderId_test() { User foundUser = userRepository.findUserByProviderId(newUser.getProviderId()) .orElseThrow(EntityExistsException::new); From ca285ce71fc0e173ff81da1558425ca462733def Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 9 May 2022 16:32:47 +0900 Subject: [PATCH 22/57] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=9D=80=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/dto/ApiResponse.java | 48 ------------------- .../backend/global/dto/ApiResponseHeader.java | 13 ----- 2 files changed, 61 deletions(-) delete mode 100644 backend/src/main/java/com/hjjang/backend/global/dto/ApiResponse.java delete mode 100644 backend/src/main/java/com/hjjang/backend/global/dto/ApiResponseHeader.java diff --git a/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponse.java b/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponse.java deleted file mode 100644 index b6154a1..0000000 --- a/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponse.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.hjjang.backend.global.dto; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.HashMap; -import java.util.Map; - -@Getter -@RequiredArgsConstructor -public class ApiResponse { - - private final static int SUCCESS = 200; - private final static int NOT_FOUND = 400; - private final static int FAILED = 500; - private final static String SUCCESS_MESSAGE = "SUCCESS"; - private final static String NOT_FOUND_MESSAGE = "NOT FOUND"; - private final static String FAILED_MESSAGE = "서버에서 오류가 발생하였습니다."; - private final static String INVALID_ACCESS_TOKEN = "Invalid access token."; - private final static String INVALID_REFRESH_TOKEN = "Invalid refresh token."; - private final static String NOT_EXPIRED_TOKEN_YET = "Not expired token yet."; - - private final ApiResponseHeader header; - private final Map body; - - public static ApiResponse success(String name, T body) { - Map map = new HashMap<>(); - map.put(name, body); - - return new ApiResponse(new ApiResponseHeader(SUCCESS, SUCCESS_MESSAGE), map); - } - - public static ApiResponse fail() { - return new ApiResponse(new ApiResponseHeader(FAILED, FAILED_MESSAGE), null); - } - - public static ApiResponse invalidAccessToken() { - return new ApiResponse(new ApiResponseHeader(FAILED, INVALID_ACCESS_TOKEN), null); - } - - public static ApiResponse invalidRefreshToken() { - return new ApiResponse(new ApiResponseHeader(FAILED, INVALID_REFRESH_TOKEN), null); - } - - public static ApiResponse notExpiredTokenYet() { - return new ApiResponse(new ApiResponseHeader(FAILED, NOT_EXPIRED_TOKEN_YET), null); - } -} diff --git a/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponseHeader.java b/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponseHeader.java deleted file mode 100644 index dfe1d38..0000000 --- a/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponseHeader.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.hjjang.backend.global.dto; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@Setter -@Getter -@AllArgsConstructor -public class ApiResponseHeader { - private int code; - private String message; -} From 101a8ba63e1421b59c765f5a908538f9b790c678 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 9 May 2022 17:29:10 +0900 Subject: [PATCH 23/57] chore: add test/application.yml at .ignore --- backend/.gitignore | 1 + .../{ => domain}/user/repository/UserRepositoryTest.java | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) rename backend/src/test/java/com/hjjang/backend/{ => domain}/user/repository/UserRepositoryTest.java (94%) diff --git a/backend/.gitignore b/backend/.gitignore index 4e98f71..d698e1a 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -65,3 +65,4 @@ hs_err_pid* /src/main/resources/application-auth.yml /src/main/resources/application-db.yml /src/main/resources/application-email.yml +/src/test/resources/application.yml diff --git a/backend/src/test/java/com/hjjang/backend/user/repository/UserRepositoryTest.java b/backend/src/test/java/com/hjjang/backend/domain/user/repository/UserRepositoryTest.java similarity index 94% rename from backend/src/test/java/com/hjjang/backend/user/repository/UserRepositoryTest.java rename to backend/src/test/java/com/hjjang/backend/domain/user/repository/UserRepositoryTest.java index 415f756..02e8e9a 100644 --- a/backend/src/test/java/com/hjjang/backend/user/repository/UserRepositoryTest.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/repository/UserRepositoryTest.java @@ -1,9 +1,8 @@ -package com.hjjang.backend.user.repository; +package com.hjjang.backend.domain.user.repository; import com.hjjang.backend.domain.user.entity.Agreement; import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.entity.User; -import com.hjjang.backend.domain.user.repository.UserRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From 3582bb2d1de6e521e3cfece7a0a15a9ac505b163 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 9 May 2022 17:30:23 +0900 Subject: [PATCH 24/57] chore: fix version and add log4j web dependency --- backend/build.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/build.gradle b/backend/build.gradle index 6f24049..3acb04a 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -14,6 +14,7 @@ configurations { compileOnly { extendsFrom annotationProcessor } + } repositories { @@ -54,9 +55,9 @@ dependencies { //swagger-ui implementation 'org.springdoc:springdoc-openapi-ui:1.6.8' //jwt 관련 의존성 - implementation 'io.jsonwebtoken:jjwt-api:0.11.2' - runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2' - runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2' + implementation 'io.jsonwebtoken:jjwt-api:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' // oauth 관련 의존성 implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' @@ -78,13 +79,12 @@ dependencies { // 로깅 관련 의존성 implementation "org.springframework.boot:spring-boot-starter-log4j2" - testImplementation 'org.springframework.boot:spring-boot-starter-log4j2' modules { module("org.springframework.boot:spring-boot-starter-logging") { replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback") } } - implementation 'org.apache.logging.log4j:log4j-web:2.17.2' + implementation 'org.apache.logging.log4j:log4j-web' } From 0a511b8b9d6db8d348f4e03247fa200144defcbc Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 9 May 2022 17:32:01 +0900 Subject: [PATCH 25/57] fix: fix for log4j.. it works.. but... why?? --- .../hjjang/backend/global/config/security/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java index d82824c..4d830d5 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java @@ -127,7 +127,7 @@ public UrlBasedCorsConfigurationSource corsConfigurationSource() { @Override @Bean(BeanIds.AUTHENTICATION_MANAGER) protected AuthenticationManager authenticationManager() throws Exception { - return super.authenticationManager(); + return super.authenticationManagerBean(); } /* From bc8960063174f64b7bb1260263c3c4db50261a07 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Mon, 9 May 2022 17:32:51 +0900 Subject: [PATCH 26/57] style: move directory --- .../{api => domain/user/controller}/UserControllerTest.java | 5 ++--- .../user/controller}/docs/UserRestDocument.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) rename backend/src/test/java/com/hjjang/backend/{api => domain/user/controller}/UserControllerTest.java (96%) rename backend/src/test/java/com/hjjang/backend/{api => domain/user/controller}/docs/UserRestDocument.java (97%) diff --git a/backend/src/test/java/com/hjjang/backend/api/UserControllerTest.java b/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java similarity index 96% rename from backend/src/test/java/com/hjjang/backend/api/UserControllerTest.java rename to backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java index 4e11d2a..1a59144 100644 --- a/backend/src/test/java/com/hjjang/backend/api/UserControllerTest.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java @@ -1,8 +1,7 @@ -package com.hjjang.backend.api; +package com.hjjang.backend.domain.user.controller; import com.fasterxml.jackson.databind.ObjectMapper; -import com.hjjang.backend.api.docs.UserRestDocument; -import com.hjjang.backend.domain.user.controller.UserController; +import com.hjjang.backend.domain.user.controller.docs.UserRestDocument; import com.hjjang.backend.domain.user.dto.UserProfileDTO; import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; import com.hjjang.backend.domain.user.repository.UserRepository; diff --git a/backend/src/test/java/com/hjjang/backend/api/docs/UserRestDocument.java b/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java similarity index 97% rename from backend/src/test/java/com/hjjang/backend/api/docs/UserRestDocument.java rename to backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java index 66f5354..8bb2108 100644 --- a/backend/src/test/java/com/hjjang/backend/api/docs/UserRestDocument.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.api.docs; +package com.hjjang.backend.domain.user.controller.docs; import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; import org.springframework.restdocs.payload.JsonFieldType; From d7c16212fc6bfac92cdfc6a9ab5f85a0720e43be Mon Sep 17 00:00:00 2001 From: Young-Jun Kim Date: Wed, 11 May 2022 16:21:23 +0900 Subject: [PATCH 27/57] =?UTF-8?q?chore=20:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20else=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hjjang/backend/domain/post/service/PostServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/service/PostServiceImpl.java b/backend/src/main/java/com/hjjang/backend/domain/post/service/PostServiceImpl.java index caa6911..1ce00d9 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/service/PostServiceImpl.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/service/PostServiceImpl.java @@ -33,7 +33,7 @@ public Post findOneById(Long id) { public Post updateOneById(Long id, PostRequestDto postRequestDto, User user) { Post foundPost = findOneById(id); if (user == foundPost.getUser()) return save(foundPost.update(postRequestDto)); - else throw new UserNotMatchException("사용자 정보가 일치하지 않습니다.", ErrorCode.NO_AUTHORITY); + throw new UserNotMatchException("사용자 정보가 일치하지 않습니다.", ErrorCode.NO_AUTHORITY); } public void deleteOneById(Long id) { From 36adfef5297472e244e4eab30e0feec070bf1c0e Mon Sep 17 00:00:00 2001 From: kim1387 Date: Thu, 12 May 2022 18:28:09 +0900 Subject: [PATCH 28/57] feat: add Api templtate legacy --- .../backend/global/dto/ApiResponse.java | 48 +++++++++++++++++++ .../backend/global/dto/ApiResponseHeader.java | 13 +++++ 2 files changed, 61 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/global/dto/ApiResponse.java create mode 100644 backend/src/main/java/com/hjjang/backend/global/dto/ApiResponseHeader.java diff --git a/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponse.java b/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponse.java new file mode 100644 index 0000000..b6154a1 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponse.java @@ -0,0 +1,48 @@ +package com.hjjang.backend.global.dto; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.HashMap; +import java.util.Map; + +@Getter +@RequiredArgsConstructor +public class ApiResponse { + + private final static int SUCCESS = 200; + private final static int NOT_FOUND = 400; + private final static int FAILED = 500; + private final static String SUCCESS_MESSAGE = "SUCCESS"; + private final static String NOT_FOUND_MESSAGE = "NOT FOUND"; + private final static String FAILED_MESSAGE = "서버에서 오류가 발생하였습니다."; + private final static String INVALID_ACCESS_TOKEN = "Invalid access token."; + private final static String INVALID_REFRESH_TOKEN = "Invalid refresh token."; + private final static String NOT_EXPIRED_TOKEN_YET = "Not expired token yet."; + + private final ApiResponseHeader header; + private final Map body; + + public static ApiResponse success(String name, T body) { + Map map = new HashMap<>(); + map.put(name, body); + + return new ApiResponse(new ApiResponseHeader(SUCCESS, SUCCESS_MESSAGE), map); + } + + public static ApiResponse fail() { + return new ApiResponse(new ApiResponseHeader(FAILED, FAILED_MESSAGE), null); + } + + public static ApiResponse invalidAccessToken() { + return new ApiResponse(new ApiResponseHeader(FAILED, INVALID_ACCESS_TOKEN), null); + } + + public static ApiResponse invalidRefreshToken() { + return new ApiResponse(new ApiResponseHeader(FAILED, INVALID_REFRESH_TOKEN), null); + } + + public static ApiResponse notExpiredTokenYet() { + return new ApiResponse(new ApiResponseHeader(FAILED, NOT_EXPIRED_TOKEN_YET), null); + } +} diff --git a/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponseHeader.java b/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponseHeader.java new file mode 100644 index 0000000..dfe1d38 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/global/dto/ApiResponseHeader.java @@ -0,0 +1,13 @@ +package com.hjjang.backend.global.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +@AllArgsConstructor +public class ApiResponseHeader { + private int code; + private String message; +} From 04a48dd28e5369b07340a9f2704b20047a07c947 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Thu, 12 May 2022 18:28:28 +0900 Subject: [PATCH 29/57] feat: add log4j2 config file --- backend/src/test/resources/log4j2-test.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/test/resources/log4j2-test.xml b/backend/src/test/resources/log4j2-test.xml index 621bd5e..bc07f2f 100644 --- a/backend/src/test/resources/log4j2-test.xml +++ b/backend/src/test/resources/log4j2-test.xml @@ -1,5 +1,5 @@ - + Default-Setting From 01d5b3451bbd757aa99131911f63d98a5add0b8c Mon Sep 17 00:00:00 2001 From: kim1387 Date: Thu, 12 May 2022 18:29:31 +0900 Subject: [PATCH 30/57] =?UTF-8?q?feat:=20add=20=EA=B6=8C=ED=95=9C=EA=B2=80?= =?UTF-8?q?=EC=A6=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hjjang/backend/global/config/security/SecurityConfig.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java index 4d830d5..7f6fa4b 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/security/SecurityConfig.java @@ -28,6 +28,8 @@ import java.util.Arrays; +import static com.hjjang.backend.domain.user.entity.RoleType.USER; + @Configuration @EnableWebSecurity @RequiredArgsConstructor @@ -39,7 +41,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { private final TokenAccessDeniedHandler tokenAccessDeniedHandler; private final UserRefreshTokenRepository userRefreshTokenRepository; - @SuppressWarnings("checkstyle:WhitespaceAfter") @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers("/static/css/**", "/static/js/**", "*.ico"); // 나중에 수정 @@ -78,6 +79,7 @@ protected void configure(HttpSecurity http) throws Exception { .antMatchers("/oauth2/authorization/**", "**/oauth2/code/*").permitAll() .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() //cors를 검증 하는 option 함수의 경우 별도의 filter 없이 허용 // .antMatchers("/api/**").hasAnyAuthority(RoleType.USER.getCode()) + .antMatchers("/api/v1/users/**").hasAnyAuthority(USER.getCode()) .anyRequest().permitAll(); http From 7af95015289e215b31cf7905af831ecde9d846f8 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Thu, 12 May 2022 18:30:04 +0900 Subject: [PATCH 31/57] =?UTF-8?q?feat:=20token=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EB=8A=94=20=EA=B1=B0=20controller=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/controller/UserController.java | 5 ++++- .../domain/user/service/UserProfileService.java | 12 ++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java index 91b92c8..37c8d71 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/controller/UserController.java @@ -4,6 +4,7 @@ import com.hjjang.backend.domain.user.service.UserProfileService; import com.hjjang.backend.global.response.code.SuccessCode; import com.hjjang.backend.global.response.response.SuccessResponse; +import com.hjjang.backend.global.util.UserUtil; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -19,7 +20,9 @@ public class UserController { @GetMapping("/profile") public ResponseEntity getProfile() { - UserProfileDTO userProfile = userProfileService.getUserProfile(); + String userId = UserUtil.getLoginUserIdByToken(); + UserProfileDTO userProfile = userProfileService.getUserProfile(userId); return ResponseEntity.ok(SuccessResponse.of(SuccessCode.USER_PROFILE_SUCCESS, userProfile)); } + } diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java index 0a809fe..92021bc 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/service/UserProfileService.java @@ -1,23 +1,19 @@ package com.hjjang.backend.domain.user.service; -import javax.persistence.EntityNotFoundException; - -import org.springframework.stereotype.Service; - import com.hjjang.backend.domain.user.dto.UserProfileDTO; import com.hjjang.backend.domain.user.entity.User; import com.hjjang.backend.domain.user.repository.UserRepository; -import com.hjjang.backend.global.util.UserUtil; - import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.persistence.EntityNotFoundException; @Service @RequiredArgsConstructor public class UserProfileService { private final UserRepository userRepository; - public UserProfileDTO getUserProfile() { - String userId = UserUtil.getLoginUserIdByToken(); + public UserProfileDTO getUserProfile(String userId) { //todo add exception User user = userRepository.findUserByProviderId(userId).orElseThrow(EntityNotFoundException::new); From c8e3175224884f64855c9f9b80c9bdbf9e4147a5 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Thu, 12 May 2022 18:30:35 +0900 Subject: [PATCH 32/57] =?UTF-8?q?feat:=20=EB=8B=A8=EC=9C=84=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20controller=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserControllerTest.java | 12 ++-- .../user/service/UserProfileServiceTest.java | 71 +++++++++++++++++++ 2 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java diff --git a/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java b/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java index 1a59144..b6c3945 100644 --- a/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java @@ -6,17 +6,18 @@ import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; import com.hjjang.backend.domain.user.repository.UserRepository; import com.hjjang.backend.domain.user.service.UserProfileService; +import com.hjjang.backend.security.WithMockCustomUser; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.ComponentScan; import org.springframework.http.MediaType; import org.springframework.restdocs.RestDocumentationContextProvider; import org.springframework.restdocs.RestDocumentationExtension; +import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; @@ -24,10 +25,10 @@ import java.nio.charset.StandardCharsets; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -43,8 +44,6 @@ class UserControllerTest { @MockBean protected UserRefreshTokenRepository userRefreshTokenRepository; - @InjectMocks - private UserController userController; @MockBean private UserProfileService userProfileService; @@ -67,6 +66,7 @@ void setUp(WebApplicationContext webApplicationContext, RestDocumentationContext } @Test + @WithMockCustomUser @DisplayName("유저 프로필 정보 조회") void get_user_profile_success() throws Exception { UserProfileDTO userProfileDTO = UserProfileDTO.builder() @@ -76,9 +76,9 @@ void get_user_profile_success() throws Exception { .userMannerTemperature(36L) .userUnivName("한국공학대") .build(); - when(userProfileService.getUserProfile()).thenReturn(userProfileDTO); + when(userProfileService.getUserProfile(any())).thenReturn(userProfileDTO); - mockMvc.perform(get("/api/v1/users/profile") + mockMvc.perform(RestDocumentationRequestBuilders.get("/api/v1/users/profile") .header("authorization", "Bearer USER_TOKEN") .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) diff --git a/backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java b/backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java new file mode 100644 index 0000000..8cb0a4c --- /dev/null +++ b/backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java @@ -0,0 +1,71 @@ +package com.hjjang.backend.domain.user.service; + +import com.hjjang.backend.domain.user.dto.UserProfileDTO; +import com.hjjang.backend.domain.user.entity.Agreement; +import com.hjjang.backend.domain.user.entity.RoleType; +import com.hjjang.backend.domain.user.entity.User; +import com.hjjang.backend.domain.user.repository.UserRepository; +import com.hjjang.backend.security.WithMockCustomUser; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class UserProfileServiceTest { + + @InjectMocks + private UserProfileService userProfileService; + + @Mock + private UserRepository userRepository; + + @Test + @WithMockCustomUser + @DisplayName("유저 조회 api test") + void getUserProfileTest() { + // given + User givenUser = User.builder() + .email("tester@tukorea.ac.kr") + .imageUrl("이미지 url") + .isPushAgree(Agreement.AGREE) + .mannerTemperature(36L) + .nickName("kevinkim") + .providerId("123412512") + .role(RoleType.USER) + .univId(null) + .build(); + + UserProfileDTO exceptUserProfileDTO = UserProfileDTO.builder() + .userEmail("tester@tukorea.ac.kr") + .userImageUrl("이미지 url") + .userMannerTemperature(36L) + .userNickname("kevinkim") + .userUnivName("산기대") + .build(); + + // when + when(userRepository.findUserByProviderId(any())).thenReturn(Optional.of(givenUser)); + UserProfileDTO actualUserProfileDTO = userProfileService.getUserProfile(givenUser.getProviderId()); + + // then + assertAll( + () -> assertEquals(exceptUserProfileDTO.getUserEmail(), actualUserProfileDTO.getUserEmail()), + () -> assertEquals(exceptUserProfileDTO.getUserNickname(), actualUserProfileDTO.getUserNickname()), + () -> assertEquals(exceptUserProfileDTO.getUserImageUrl(), actualUserProfileDTO.getUserImageUrl()), + () -> assertEquals(exceptUserProfileDTO.getUserMannerTemperature(), actualUserProfileDTO.getUserMannerTemperature()), + () -> assertEquals(exceptUserProfileDTO.getUserUnivName(), actualUserProfileDTO.getUserUnivName()) + ); + + } + +} \ No newline at end of file From 94c225534da72e5a84ff4d2db11800d5e05b3f2c Mon Sep 17 00:00:00 2001 From: kim1387 Date: Thu, 12 May 2022 18:31:06 +0900 Subject: [PATCH 33/57] =?UTF-8?q?feat:=20spring=20security=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20security=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/security/WithMockCustomUser.java | 31 ++++++++++++++++++ .../WithMockUserSecurityContextFactory.java | 32 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 backend/src/test/java/com/hjjang/backend/security/WithMockCustomUser.java create mode 100644 backend/src/test/java/com/hjjang/backend/security/WithMockUserSecurityContextFactory.java diff --git a/backend/src/test/java/com/hjjang/backend/security/WithMockCustomUser.java b/backend/src/test/java/com/hjjang/backend/security/WithMockCustomUser.java new file mode 100644 index 0000000..7284459 --- /dev/null +++ b/backend/src/test/java/com/hjjang/backend/security/WithMockCustomUser.java @@ -0,0 +1,31 @@ +package com.hjjang.backend.security; + +import com.hjjang.backend.domain.user.entity.Agreement; +import com.hjjang.backend.domain.user.entity.RoleType; +import org.springframework.security.test.context.support.WithSecurityContext; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +@WithSecurityContext(factory = WithMockUserSecurityContextFactory.class) +public @interface WithMockCustomUser { + + long id() default 1L; + + String email() default "kevinkim@email.com"; + + String imageUrl() default "이미지입니다아아아"; + + String nickName() default "김겨여여연"; + + RoleType roles() default RoleType.USER; + + String providerId() default "kakao123456"; + + long mannerTemperature() default 36L; + + Agreement isPushAgree() default Agreement.AGREE; + + long univId() default 1L; +} \ No newline at end of file diff --git a/backend/src/test/java/com/hjjang/backend/security/WithMockUserSecurityContextFactory.java b/backend/src/test/java/com/hjjang/backend/security/WithMockUserSecurityContextFactory.java new file mode 100644 index 0000000..864084d --- /dev/null +++ b/backend/src/test/java/com/hjjang/backend/security/WithMockUserSecurityContextFactory.java @@ -0,0 +1,32 @@ +package com.hjjang.backend.security; + +import com.hjjang.backend.domain.user.entity.User; +import com.hjjang.backend.global.security.principal.UserPrincipal; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.test.context.support.WithSecurityContextFactory; + +public class WithMockUserSecurityContextFactory implements WithSecurityContextFactory { + @Override + public SecurityContext createSecurityContext(WithMockCustomUser customUser) { + SecurityContext context = SecurityContextHolder.createEmptyContext(); + + User givenUser = User.builder() + .email(customUser.email()) + .imageUrl(customUser.imageUrl()) + .isPushAgree(customUser.isPushAgree()) + .mannerTemperature(customUser.mannerTemperature()) + .nickName(customUser.nickName()) + .providerId(customUser.providerId()) + .role(customUser.roles()) + .univId(customUser.univId()) + .build(); + + UserPrincipal principal = UserPrincipal.create(givenUser); + Authentication auth = new UsernamePasswordAuthenticationToken(principal, "", principal.getAuthorities()); + context.setAuthentication(auth); + return context; + } +} \ No newline at end of file From f5c6388f02005344ae7478e4025dc17ea8c55e80 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Thu, 12 May 2022 18:31:30 +0900 Subject: [PATCH 34/57] feat: add empty User --- .../backend/domain/user/entity/AnonymousEmptyUser.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java new file mode 100644 index 0000000..0367359 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java @@ -0,0 +1,8 @@ +package com.hjjang.backend.domain.user.entity; + +public class AnonymousEmptyUser extends User { + public AnonymousEmptyUser() { + super(null, null, null, null, null, null, null, null, null); + } + +} From 1d0dbbbc0fec44edce1c86a402ce0b2aab0b6047 Mon Sep 17 00:00:00 2001 From: 0BVer Date: Thu, 12 May 2022 23:27:57 +0900 Subject: [PATCH 35/57] feat : add Jacoco --- backend/build.gradle | 32 ++++++++++++++++++++++++++++++++ backend/lombok.config | 2 ++ 2 files changed, 34 insertions(+) create mode 100644 backend/lombok.config diff --git a/backend/build.gradle b/backend/build.gradle index 6f96ced..8c4db17 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -4,6 +4,7 @@ plugins { id 'org.asciidoctor.convert' version '1.5.8' id 'java' id 'application' + id 'jacoco' } group = 'com.hjjang' @@ -88,3 +89,34 @@ tasks.named('asciidoctor') { inputs.dir snippetsDir dependsOn test } + +jacocoTestReport { + reports { + html.enabled true + xml.enabled false + csv.enabled true + } + finalizedBy 'jacocoTestCoverageVerification' +} + +jacocoTestCoverageVerification { + violationRules { + rule { + enabled = true + element = 'CLASS' + + limit { + counter = 'METHOD' + value = 'COVEREDRATIO' + minimum = 0.00 + } + + limit { + counter = 'INSTRUCTION' + value = 'COVEREDRATIO' + minimum = 0.00 + } + excludes = ["*Dto*", "*.dto.*", "*.SvProjectApplication*", "*.config.*", "*.exceptions.*", "*.utils.*"] + } + } +} \ No newline at end of file diff --git a/backend/lombok.config b/backend/lombok.config new file mode 100644 index 0000000..a23edb4 --- /dev/null +++ b/backend/lombok.config @@ -0,0 +1,2 @@ +config.stopBubbling = true +lombok.addLombokGeneratedAnnotation = true \ No newline at end of file From 8ec5ebd8cf0552ab843c88b302d7b1fcf36afd2e Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 02:08:24 +0900 Subject: [PATCH 36/57] =?UTF-8?q?fix:=20=EB=88=84=EB=9D=BD=EB=90=9C=20user?= =?UTF-8?q?repository=20=EB=A9=94=EC=84=9C=EB=93=9C=20mock=EC=9D=84=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C=20=ED=95=98=EA=B3=A0=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=93=A4=EC=9D=84=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=96=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserControllerTest.java | 57 ++++++++++++++++++- .../controller/docs/UserRestDocument.java | 2 +- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java b/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java index b6c3945..b442e7e 100644 --- a/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java @@ -3,6 +3,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.hjjang.backend.domain.user.controller.docs.UserRestDocument; import com.hjjang.backend.domain.user.dto.UserProfileDTO; +import com.hjjang.backend.domain.user.entity.Agreement; +import com.hjjang.backend.domain.user.entity.RoleType; +import com.hjjang.backend.domain.user.entity.User; import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; import com.hjjang.backend.domain.user.repository.UserRepository; import com.hjjang.backend.domain.user.service.UserProfileService; @@ -24,6 +27,7 @@ import org.springframework.web.filter.CharacterEncodingFilter; import java.nio.charset.StandardCharsets; +import java.util.Optional; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -54,6 +58,19 @@ class UserControllerTest { @BeforeEach void setUp(WebApplicationContext webApplicationContext, RestDocumentationContextProvider restDocumentationContextProvider) { + + User givenUser = User.builder() + .email("kevinkim@email.com") + .imageUrl("이미지입니다아아아") + .isPushAgree(Agreement.AGREE) + .mannerTemperature(36L) + .nickName("김겨여여연") + .providerId("kakao123456") + .role(RoleType.USER) + .univId(1L) + .build(); + when(userRepository.findUserByProviderId(any())).thenReturn(Optional.of(givenUser)); + objectMapper = new ObjectMapper(); mockMvc = MockMvcBuilders @@ -67,8 +84,8 @@ void setUp(WebApplicationContext webApplicationContext, RestDocumentationContext @Test @WithMockCustomUser - @DisplayName("유저 프로필 정보 조회") - void get_user_profile_success() throws Exception { + @DisplayName("유저 프로필 정보 조회 성공") + void getUserProfileSuccess() throws Exception { UserProfileDTO userProfileDTO = UserProfileDTO.builder() .userEmail("tester@tukorea.ac.kr") .userImageUrl("이미지 url입니다") @@ -79,11 +96,45 @@ void get_user_profile_success() throws Exception { when(userProfileService.getUserProfile(any())).thenReturn(userProfileDTO); mockMvc.perform(RestDocumentationRequestBuilders.get("/api/v1/users/profile") - .header("authorization", "Bearer USER_TOKEN") + .header("Authorization", "Bearer USER_TOKEN") .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(print()) .andDo(UserRestDocument.getProfile()); } + // 아래 예외 테스트들은 정상적인 테스트가 아니므로 실패되는 게 맞음 + @Test + @DisplayName("유저 프로필 정보 조회 토큰이 없어서 인증 실패 401 에러") + void getUserProfileNoToken() throws Exception { + + when(userProfileService.getUserProfile(any())).thenThrow(new IllegalArgumentException("유효하지 않은 토큰입니다.")); + + mockMvc.perform(RestDocumentationRequestBuilders.get("/api/v1/users/profile") + .header("Authorization", "Bearer USER_TOKEN") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isUnauthorized()) + .andDo(print()) + .andDo(UserRestDocument.getProfile()); + } + @Test + @DisplayName("유저 프로필 정보 조회 유효하지 않은 권한 403 에러") + void getUserProfileNoAuthorization() throws Exception { + UserProfileDTO userProfileDTO = UserProfileDTO.builder() + .userEmail("tester@tukorea.ac.kr") + .userImageUrl("이미지 url입니다") + .userNickname("내 닉네임은 테스타") + .userMannerTemperature(36L) + .userUnivName("한국공학대") + .build(); + when(userProfileService.getUserProfile(any())).thenReturn(userProfileDTO); + + mockMvc.perform(RestDocumentationRequestBuilders.get("/api/v1/users/profile") + .header("Authorization", "Bearer USER_TOKEN") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isForbidden()) + .andDo(print()) + .andDo(UserRestDocument.getProfile()); + } + } \ No newline at end of file diff --git a/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java b/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java index 8bb2108..27b1a81 100644 --- a/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java @@ -13,7 +13,7 @@ public class UserRestDocument { public static RestDocumentationResultHandler getProfile() { return document("v1/users/profile", requestHeaders( - headerWithName("authorization").description("Bearer 토큰")), + headerWithName("Authorization").description("Bearer 토큰")), responseFields( fieldWithPath("status").type(JsonFieldType.NUMBER).description("status code"), fieldWithPath("code").type(JsonFieldType.STRING).description("Business code"), From 2729e278b052bcdfe83d121c235652a0a00ee006 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 02:11:08 +0900 Subject: [PATCH 37/57] =?UTF-8?q?fix:=20=EA=B0=80=EC=A7=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=EC=99=80=20=EA=B0=80=EC=A7=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=EC=99=80=20=EC=9D=B8=EC=A6=9D=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=B6=94=EA=B0=80=ED=95=98=EB=8A=94=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WithMockUserSecurityContextFactory.java | 51 ++++++++++++------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/backend/src/test/java/com/hjjang/backend/security/WithMockUserSecurityContextFactory.java b/backend/src/test/java/com/hjjang/backend/security/WithMockUserSecurityContextFactory.java index 864084d..4663a60 100644 --- a/backend/src/test/java/com/hjjang/backend/security/WithMockUserSecurityContextFactory.java +++ b/backend/src/test/java/com/hjjang/backend/security/WithMockUserSecurityContextFactory.java @@ -1,32 +1,45 @@ package com.hjjang.backend.security; -import com.hjjang.backend.domain.user.entity.User; -import com.hjjang.backend.global.security.principal.UserPrincipal; +import com.hjjang.backend.domain.user.entity.RoleType; +import com.hjjang.backend.global.config.security.properties.AuthProperties; +import lombok.RequiredArgsConstructor; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; +import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.User; import org.springframework.security.test.context.support.WithSecurityContextFactory; +import java.util.Collections; +import java.util.Date; + + +@RequiredArgsConstructor public class WithMockUserSecurityContextFactory implements WithSecurityContextFactory { + + private final AuthProperties authProperties; + @Override public SecurityContext createSecurityContext(WithMockCustomUser customUser) { - SecurityContext context = SecurityContextHolder.createEmptyContext(); - - User givenUser = User.builder() - .email(customUser.email()) - .imageUrl(customUser.imageUrl()) - .isPushAgree(customUser.isPushAgree()) - .mannerTemperature(customUser.mannerTemperature()) - .nickName(customUser.nickName()) - .providerId(customUser.providerId()) - .role(customUser.roles()) - .univId(customUser.univId()) - .build(); - - UserPrincipal principal = UserPrincipal.create(givenUser); - Authentication auth = new UsernamePasswordAuthenticationToken(principal, "", principal.getAuthorities()); - context.setAuthentication(auth); - return context; + SecurityContext securityContext = SecurityContextHolder.createEmptyContext(); + + Date now = new Date(); + + // 가짜 user 정보 설정 + User principal = new User( + customUser.providerId(), + "", + Collections.singletonList(new SimpleGrantedAuthority(RoleType.USER.getCode())) + ); + + // 가짜 security 인증 user 저장 + Authentication authentication = new UsernamePasswordAuthenticationToken( + principal, + "", + principal.getAuthorities() + ); + securityContext.setAuthentication(authentication); + return securityContext; } } \ No newline at end of file From e388fd05b97adfcd341f85c12cacf663d5518a50 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 02:11:48 +0900 Subject: [PATCH 38/57] =?UTF-8?q?fix:=20error=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=EA=B0=80=20=EB=B6=88=EC=99=84=EC=A0=84=ED=95=9C=20=EC=83=81?= =?UTF-8?q?=ED=99=A9=EC=97=90=EC=84=9C=20=EB=AA=A8=EB=93=A0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EB=A5=BC=20500=EC=9C=BC=EB=A1=9C=20=EB=B0=9B=EC=95=84?= =?UTF-8?q?=EB=B2=84=EB=A6=AC=EB=A9=B4=20=EA=B0=9C=EB=B0=9C=EC=97=90=20?= =?UTF-8?q?=EC=96=B4=EB=A0=A4=EC=9B=80=EC=9D=B4=20=EC=9E=88=EC=96=B4?= =?UTF-8?q?=EC=84=9C=20=ED=95=B4=EC=B2=B4=ED=95=98=EC=98=80=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/GlobalExceptionHandler.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/execption/handler/GlobalExceptionHandler.java b/backend/src/main/java/com/hjjang/backend/global/execption/handler/GlobalExceptionHandler.java index a6f4a42..73db56a 100644 --- a/backend/src/main/java/com/hjjang/backend/global/execption/handler/GlobalExceptionHandler.java +++ b/backend/src/main/java/com/hjjang/backend/global/execption/handler/GlobalExceptionHandler.java @@ -1,21 +1,15 @@ package com.hjjang.backend.global.execption.handler; -import com.hjjang.backend.global.response.response.ErrorResponse; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import static com.hjjang.backend.global.response.code.ErrorCode.INTERNAL_SERVER_ERROR; - @RestControllerAdvice public class GlobalExceptionHandler { // 500 에러 - @ExceptionHandler - protected ResponseEntity handleException(Exception e) { - final ErrorResponse response = ErrorResponse.of(INTERNAL_SERVER_ERROR); - return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); - } +// @ExceptionHandler +// protected ResponseEntity handleException(Exception e) { +// final ErrorResponse response = ErrorResponse.of(INTERNAL_SERVER_ERROR); +// return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); +// } } From bd37dc3d88f3a770150dfd63472ce2b6514ef0ab Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 02:14:16 +0900 Subject: [PATCH 39/57] style: move directory --- .../backend/domain/user/controller/UserControllerTest.java | 2 +- .../backend/domain/user/service/UserProfileServiceTest.java | 2 +- .../backend/{ => global}/security/WithMockCustomUser.java | 2 +- .../security/WithMockUserSecurityContextFactory.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename backend/src/test/java/com/hjjang/backend/{ => global}/security/WithMockCustomUser.java (94%) rename backend/src/test/java/com/hjjang/backend/{ => global}/security/WithMockUserSecurityContextFactory.java (97%) diff --git a/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java b/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java index b442e7e..4659329 100644 --- a/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java @@ -9,7 +9,7 @@ import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; import com.hjjang.backend.domain.user.repository.UserRepository; import com.hjjang.backend.domain.user.service.UserProfileService; -import com.hjjang.backend.security.WithMockCustomUser; +import com.hjjang.backend.global.security.WithMockCustomUser; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java b/backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java index 8cb0a4c..c7af03a 100644 --- a/backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java @@ -5,7 +5,7 @@ import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.entity.User; import com.hjjang.backend.domain.user.repository.UserRepository; -import com.hjjang.backend.security.WithMockCustomUser; +import com.hjjang.backend.global.security.WithMockCustomUser; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/backend/src/test/java/com/hjjang/backend/security/WithMockCustomUser.java b/backend/src/test/java/com/hjjang/backend/global/security/WithMockCustomUser.java similarity index 94% rename from backend/src/test/java/com/hjjang/backend/security/WithMockCustomUser.java rename to backend/src/test/java/com/hjjang/backend/global/security/WithMockCustomUser.java index 7284459..3e193ad 100644 --- a/backend/src/test/java/com/hjjang/backend/security/WithMockCustomUser.java +++ b/backend/src/test/java/com/hjjang/backend/global/security/WithMockCustomUser.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.security; +package com.hjjang.backend.global.security; import com.hjjang.backend.domain.user.entity.Agreement; import com.hjjang.backend.domain.user.entity.RoleType; diff --git a/backend/src/test/java/com/hjjang/backend/security/WithMockUserSecurityContextFactory.java b/backend/src/test/java/com/hjjang/backend/global/security/WithMockUserSecurityContextFactory.java similarity index 97% rename from backend/src/test/java/com/hjjang/backend/security/WithMockUserSecurityContextFactory.java rename to backend/src/test/java/com/hjjang/backend/global/security/WithMockUserSecurityContextFactory.java index 4663a60..514e6bd 100644 --- a/backend/src/test/java/com/hjjang/backend/security/WithMockUserSecurityContextFactory.java +++ b/backend/src/test/java/com/hjjang/backend/global/security/WithMockUserSecurityContextFactory.java @@ -1,4 +1,4 @@ -package com.hjjang.backend.security; +package com.hjjang.backend.global.security; import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.global.config.security.properties.AuthProperties; From 378ae347a458efeac38b0c0e4c820a3cd9d32b90 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 02:27:13 +0900 Subject: [PATCH 40/57] =?UTF-8?q?feat:=20=EC=BD=94=EB=93=9C=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=EC=9D=84=20=EC=A4=84=EC=9D=B4=EA=B8=B0=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20CustomSecurityExtension=EC=9D=84=20=ED=86=B5?= =?UTF-8?q?=ED=95=B4=20=EA=B3=B5=ED=86=B5=EC=A0=81=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=EB=90=98=EB=8A=94=20security=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=EC=9D=84=20=EA=B0=84=EB=8B=A8=ED=95=98=EA=B2=8C=20?= =?UTF-8?q?=EB=A7=8C=EB=93=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserControllerTest.java | 42 ++++-------------- .../security/CustomSecurityExtension.java | 44 +++++++++++++++++++ 2 files changed, 52 insertions(+), 34 deletions(-) create mode 100644 backend/src/test/java/com/hjjang/backend/global/security/CustomSecurityExtension.java diff --git a/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java b/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java index 4659329..f8f4a26 100644 --- a/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/controller/UserControllerTest.java @@ -3,23 +3,16 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.hjjang.backend.domain.user.controller.docs.UserRestDocument; import com.hjjang.backend.domain.user.dto.UserProfileDTO; -import com.hjjang.backend.domain.user.entity.Agreement; -import com.hjjang.backend.domain.user.entity.RoleType; -import com.hjjang.backend.domain.user.entity.User; -import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; -import com.hjjang.backend.domain.user.repository.UserRepository; import com.hjjang.backend.domain.user.service.UserProfileService; +import com.hjjang.backend.global.security.CustomSecurityExtension; import com.hjjang.backend.global.security.WithMockCustomUser; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.http.MediaType; import org.springframework.restdocs.RestDocumentationContextProvider; -import org.springframework.restdocs.RestDocumentationExtension; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -27,7 +20,6 @@ import org.springframework.web.filter.CharacterEncodingFilter; import java.nio.charset.StandardCharsets; -import java.util.Optional; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -36,18 +28,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@ComponentScan(basePackages = "com.hjjang.backend.global.config.security") -@ComponentScan(basePackages = "com.hjjang.backend.global.security") -@ExtendWith(RestDocumentationExtension.class) -@WebMvcTest(controllers = UserController.class) -class UserControllerTest { - - @MockBean - protected UserRepository userRepository; - - @MockBean - protected UserRefreshTokenRepository userRefreshTokenRepository; +@WebMvcTest(controllers = UserController.class) +class UserControllerTest extends CustomSecurityExtension { @MockBean private UserProfileService userProfileService; @@ -57,20 +40,10 @@ class UserControllerTest { private MockMvc mockMvc; @BeforeEach - void setUp(WebApplicationContext webApplicationContext, RestDocumentationContextProvider restDocumentationContextProvider) { - - User givenUser = User.builder() - .email("kevinkim@email.com") - .imageUrl("이미지입니다아아아") - .isPushAgree(Agreement.AGREE) - .mannerTemperature(36L) - .nickName("김겨여여연") - .providerId("kakao123456") - .role(RoleType.USER) - .univId(1L) - .build(); - when(userRepository.findUserByProviderId(any())).thenReturn(Optional.of(givenUser)); - + void setUp(WebApplicationContext webApplicationContext, + RestDocumentationContextProvider restDocumentationContextProvider) { + //security 관련 user repository mock + super.userInfoSetUp(); objectMapper = new ObjectMapper(); mockMvc = MockMvcBuilders @@ -117,6 +90,7 @@ void getUserProfileNoToken() throws Exception { .andDo(print()) .andDo(UserRestDocument.getProfile()); } + @Test @DisplayName("유저 프로필 정보 조회 유효하지 않은 권한 403 에러") void getUserProfileNoAuthorization() throws Exception { diff --git a/backend/src/test/java/com/hjjang/backend/global/security/CustomSecurityExtension.java b/backend/src/test/java/com/hjjang/backend/global/security/CustomSecurityExtension.java new file mode 100644 index 0000000..a88c9e1 --- /dev/null +++ b/backend/src/test/java/com/hjjang/backend/global/security/CustomSecurityExtension.java @@ -0,0 +1,44 @@ +package com.hjjang.backend.global.security; + +import com.hjjang.backend.domain.user.entity.Agreement; +import com.hjjang.backend.domain.user.entity.RoleType; +import com.hjjang.backend.domain.user.entity.User; +import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; +import com.hjjang.backend.domain.user.repository.UserRepository; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.restdocs.RestDocumentationExtension; + +import java.util.Optional; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ComponentScan(basePackages = "com.hjjang.backend.global.config.security") +@ComponentScan(basePackages = "com.hjjang.backend.global.security") +@ExtendWith(RestDocumentationExtension.class) +public class CustomSecurityExtension { + + @MockBean + protected UserRepository userRepository; + + @MockBean + protected UserRefreshTokenRepository userRefreshTokenRepository; + + public void userInfoSetUp() { + User givenUser = User.builder() + .email("kevinkim@email.com") + .imageUrl("이미지입니다아아아") + .isPushAgree(Agreement.AGREE) + .mannerTemperature(36L) + .nickName("김겨여여연") + .providerId("kakao123456") + .role(RoleType.USER) + .univId(1L) + .build(); + when(userRepository.findUserByProviderId(any())).thenReturn(Optional.of(givenUser)); + } + + +} From 801aeace9a8bc1ba450ebe586c0f2f83af8eb7cb Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 02:53:49 +0900 Subject: [PATCH 41/57] =?UTF-8?q?fix:=20PostControllerTest=20=EB=95=8C?= =?UTF-8?q?=EB=AC=B8=EC=97=90=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EA=B0=80=20?= =?UTF-8?q?=EC=95=88=EB=90=98=EB=8A=94=20=EA=B2=83=EC=9D=84=20=EB=A7=89?= =?UTF-8?q?=EA=B8=B0=20=EC=9C=84=ED=95=B4=20=EC=9E=84=EC=9D=98=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PostControllerTest.java | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/backend/src/test/java/com/hjjang/backend/domain/post/controller/PostControllerTest.java b/backend/src/test/java/com/hjjang/backend/domain/post/controller/PostControllerTest.java index 5ed3ef6..e753e20 100644 --- a/backend/src/test/java/com/hjjang/backend/domain/post/controller/PostControllerTest.java +++ b/backend/src/test/java/com/hjjang/backend/domain/post/controller/PostControllerTest.java @@ -1,9 +1,7 @@ package com.hjjang.backend.domain.post.controller; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.hjjang.backend.domain.post.domain.entity.Post; -import com.hjjang.backend.domain.post.domain.entity.PostDefaultValue; import com.hjjang.backend.domain.post.dto.PostMapper; import com.hjjang.backend.domain.post.dto.PostRequestDto; import com.hjjang.backend.domain.post.dto.PostResponseDto; @@ -11,26 +9,16 @@ import com.hjjang.backend.domain.user.entity.Agreement; import com.hjjang.backend.domain.user.entity.RoleType; import com.hjjang.backend.domain.user.entity.User; -import com.hjjang.backend.domain.user.repository.UserRefreshTokenRepository; -import com.hjjang.backend.global.config.properties.AuthProperties; -import com.hjjang.backend.global.config.security.handler.TokenAccessDeniedHandler; -import com.hjjang.backend.global.config.security.service.CustomOAuth2UserService; -import com.hjjang.backend.global.config.security.token.AuthTokenProvider; import com.hjjang.backend.global.util.UserUtil; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; -import org.springframework.restdocs.RestDocumentationExtension; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.RequestBuilder; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.filter.CharacterEncodingFilter; @@ -43,7 +31,8 @@ import static com.hjjang.backend.domain.post.domain.entity.PostDefaultValue.*; import static org.mockito.Mockito.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @ExtendWith(SpringExtension.class) @WebMvcTest(controllers = PostController.class) @@ -121,8 +110,8 @@ void setUp(WebApplicationContext context) { .itemPrice(givenItemPrice) .build(); - User expectSavedUser = new User(givenId, providerId, nickName, email, - mannerTemperature, imagePath, LocalDateTime.now(), pushAgree, univId, role); +// User expectSavedUser = new User(givenId, providerId, nickName, email, +// mannerTemperature, imagePath, LocalDateTime.now(), pushAgree, univId, role); Post expectSavedPost = new Post(givenId, givenUser, givenTitle, givenContent, givenItemPrice, DEFAULT_VIEWS, DEFAULT_INTEREST_NUMBER, DEFAULT_CHAT_NUMBER, @@ -168,7 +157,6 @@ void setUp(WebApplicationContext context) { .thenReturn(expectUpdatedPost); doNothing().when(postService).deleteOneById(anyLong()); - when(userUtil.getLoginUserByToken()).thenReturn(expectSavedUser); } @Test From 9d368d5c13aa772d6441add96cee34a78edc08c6 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 02:57:01 +0900 Subject: [PATCH 42/57] =?UTF-8?q?fix:=20test=EB=A5=BC=20=EC=9C=84=ED=95=9C?= =?UTF-8?q?=20yml=EC=9D=80=20=EC=98=AC=EB=A6=AC=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EA=B8=B0=EB=A1=9C=20=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/test/resources/application.yml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 backend/src/test/resources/application.yml diff --git a/backend/src/test/resources/application.yml b/backend/src/test/resources/application.yml deleted file mode 100644 index 884acd5..0000000 --- a/backend/src/test/resources/application.yml +++ /dev/null @@ -1,16 +0,0 @@ -spring: - datasource: - url: jdbc:h2:mem:test_db;MODE=MySQL;DB_CLOSE_DELAY=-1 - driverClassName: org.h2.Driver - username: sa - password: - h2: - console: - enabled: true - jpa: - database-platform: org.hibernate.dialect.H2Dialect - hibernate.ddl-auto: create-drop - properties: - hibernate: - format_sql: true - generate-ddl: true \ No newline at end of file From c09145491d1abee8819e180b7818d3e2cd9d4dcc Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 03:03:31 +0900 Subject: [PATCH 43/57] =?UTF-8?q?fix:=20=EB=B0=98=ED=99=98=20=ED=85=9C?= =?UTF-8?q?=ED=94=8C=EB=A6=BF=EC=97=90=EC=84=9C=20status=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 이미 반환이 되는데 굳이 body에서 또 반환될 필요가 없음 --- .../backend/global/response/code/ErrorCode.java | 13 +++++-------- .../backend/global/response/code/SuccessCode.java | 3 +-- .../global/response/response/ErrorResponse.java | 2 -- .../global/response/response/SuccessResponse.java | 3 --- .../user/controller/docs/UserRestDocument.java | 1 - 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/response/code/ErrorCode.java b/backend/src/main/java/com/hjjang/backend/global/response/code/ErrorCode.java index 233d6d7..d8cf3df 100644 --- a/backend/src/main/java/com/hjjang/backend/global/response/code/ErrorCode.java +++ b/backend/src/main/java/com/hjjang/backend/global/response/code/ErrorCode.java @@ -1,7 +1,5 @@ package com.hjjang.backend.global.response.code; -import org.springframework.http.HttpStatus; - import lombok.AllArgsConstructor; import lombok.Getter; @@ -10,16 +8,15 @@ public enum ErrorCode { //Global - INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), "G001", "내부 서버 오류"), - NOT_ALLOWED_METHOD(HttpStatus.METHOD_NOT_ALLOWED.value(), "G002", "허용 되지 않은 HTTP method"), - INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST.value(), "G003", "검증 되지 않은 입력"), + INTERNAL_SERVER_ERROR("G001", "내부 서버 오류"), + NOT_ALLOWED_METHOD("G002", "허용 되지 않은 HTTP method"), + INVALID_INPUT_VALUE("G003", "검증 되지 않은 입력"), //User - MEMBER_NOT_FOUND(HttpStatus.BAD_REQUEST.value(), "U001", "존재 하지 않는 사용자"), - NO_AUTHORITY(HttpStatus.FORBIDDEN.value(), "U002", "권한이 없음"),; + MEMBER_NOT_FOUND("U001", "존재 하지 않는 사용자"), + NO_AUTHORITY("U002", "권한이 없음"),; - private final int httpStatus; private final String code; private final String message; } diff --git a/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java b/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java index 3f22430..506a47c 100644 --- a/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java +++ b/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java @@ -8,9 +8,8 @@ public enum SuccessCode { //User - USER_PROFILE_SUCCESS(200, "U001", "프로필 조회 완료."),; + USER_PROFILE_SUCCESS( "U001", "프로필 조회 완료."),; - private final int status; private final String code; private final String message; } diff --git a/backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java b/backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java index bc53a6d..e577079 100644 --- a/backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java +++ b/backend/src/main/java/com/hjjang/backend/global/response/response/ErrorResponse.java @@ -20,14 +20,12 @@ public class ErrorResponse { private ErrorResponse(final ErrorCode code, final List errors) { this.message = code.getMessage(); - this.status = code.getHttpStatus(); this.errors = errors; this.code = code.getCode(); } private ErrorResponse(final ErrorCode code) { this.message = code.getMessage(); - this.status = code.getHttpStatus(); this.code = code.getCode(); this.errors = new ArrayList<>(); } diff --git a/backend/src/main/java/com/hjjang/backend/global/response/response/SuccessResponse.java b/backend/src/main/java/com/hjjang/backend/global/response/response/SuccessResponse.java index 9f53bc5..9e571a6 100644 --- a/backend/src/main/java/com/hjjang/backend/global/response/response/SuccessResponse.java +++ b/backend/src/main/java/com/hjjang/backend/global/response/response/SuccessResponse.java @@ -7,8 +7,6 @@ @Getter public class SuccessResponse { - @Schema(description = "status code") - private final int status; @Schema(description = "Business code") private final String code; @Schema(description = "response message") @@ -25,7 +23,6 @@ public static SuccessResponse of(SuccessCode successCode) { } public SuccessResponse(SuccessCode successCode, Object data) { - this.status = successCode.getStatus(); this.code = successCode.getCode(); this.message = successCode.getMessage(); this.data = data; diff --git a/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java b/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java index 27b1a81..3834d74 100644 --- a/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java @@ -15,7 +15,6 @@ public static RestDocumentationResultHandler getProfile() { requestHeaders( headerWithName("Authorization").description("Bearer 토큰")), responseFields( - fieldWithPath("status").type(JsonFieldType.NUMBER).description("status code"), fieldWithPath("code").type(JsonFieldType.STRING).description("Business code"), fieldWithPath("message").type(JsonFieldType.STRING).description("response message"), fieldWithPath("data.userNickname").type(JsonFieldType.STRING).description("user 닉네임"), From 67fc3bc39cb5ac79926231ec3ef53ad8c2867df0 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 03:11:48 +0900 Subject: [PATCH 44/57] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=EB=90=9C=20=EC=9C=A0=EC=A0=80=EC=9D=B8?= =?UTF-8?q?=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98=EA=B8=B0=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20column=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/user/entity/AnonymousEmptyUser.java | 2 +- .../java/com/hjjang/backend/domain/user/entity/User.java | 6 +++++- .../backend/domain/user/repository/UserRepositoryTest.java | 1 + .../backend/domain/user/service/UserProfileServiceTest.java | 1 + .../backend/global/security/CustomSecurityExtension.java | 3 +++ 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java index 0367359..435c27b 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java @@ -2,7 +2,7 @@ public class AnonymousEmptyUser extends User { public AnonymousEmptyUser() { - super(null, null, null, null, null, null, null, null, null); + super(null, null, null, null, null, null, null, null, null, false); } } diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java index fd0cafd..4647087 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java @@ -50,9 +50,12 @@ public class User extends BaseTimeEntity { @Enumerated(STRING) private RoleType role; + @Column(name = "is_email_verification", length = 20) + private boolean isEmailVerification; + @Builder public User(String providerId, String nickName, String email, Long mannerTemperature, - String imageUrl, Agreement isPushAgree, Long univId, RoleType role) { + String imageUrl, Agreement isPushAgree, Long univId, RoleType role, boolean isEmailVerification) { this.providerId = providerId; this.nickName = nickName; this.email = email; @@ -61,5 +64,6 @@ public User(String providerId, String nickName, String email, Long mannerTempera this.isPushAgree = isPushAgree; this.univId = univId; this.role = role; + this.isEmailVerification = isEmailVerification; } } diff --git a/backend/src/test/java/com/hjjang/backend/domain/user/repository/UserRepositoryTest.java b/backend/src/test/java/com/hjjang/backend/domain/user/repository/UserRepositoryTest.java index 02e8e9a..4ce9f07 100644 --- a/backend/src/test/java/com/hjjang/backend/domain/user/repository/UserRepositoryTest.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/repository/UserRepositoryTest.java @@ -34,6 +34,7 @@ void setUp() { .providerId("123412512") .role(RoleType.USER) .univId(null) + .isEmailVerification(false) .build(); newUser = userRepository.save(givenUser); diff --git a/backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java b/backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java index c7af03a..960b6aa 100644 --- a/backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/service/UserProfileServiceTest.java @@ -43,6 +43,7 @@ void getUserProfileTest() { .providerId("123412512") .role(RoleType.USER) .univId(null) + .isEmailVerification(true) .build(); UserProfileDTO exceptUserProfileDTO = UserProfileDTO.builder() diff --git a/backend/src/test/java/com/hjjang/backend/global/security/CustomSecurityExtension.java b/backend/src/test/java/com/hjjang/backend/global/security/CustomSecurityExtension.java index a88c9e1..b9fd1be 100644 --- a/backend/src/test/java/com/hjjang/backend/global/security/CustomSecurityExtension.java +++ b/backend/src/test/java/com/hjjang/backend/global/security/CustomSecurityExtension.java @@ -26,6 +26,7 @@ public class CustomSecurityExtension { @MockBean protected UserRefreshTokenRepository userRefreshTokenRepository; + // 인증된 user setup public void userInfoSetUp() { User givenUser = User.builder() .email("kevinkim@email.com") @@ -36,9 +37,11 @@ public void userInfoSetUp() { .providerId("kakao123456") .role(RoleType.USER) .univId(1L) + .isEmailVerification(true) .build(); when(userRepository.findUserByProviderId(any())).thenReturn(Optional.of(givenUser)); } + // todo 인증되지 않은 user setup } From 0e4e07a26bde541cf2cb09586f993447a473e81c Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 17:40:08 +0900 Subject: [PATCH 45/57] =?UTF-8?q?feat:=20restdocs=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=ED=99=95=EC=9D=B8=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EA=B2=8C=20=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 8 ++- .../src/main/resources/static.docs/api.adoc | 52 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 backend/src/main/resources/static.docs/api.adoc diff --git a/backend/build.gradle b/backend/build.gradle index ca4cdf3..b0acf4b 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -95,12 +95,18 @@ tasks.named('compileJava') { bootRun { mainClassName = 'com.hjjang.backend.BackendApplication' + } +// 작성된 문서를 서버에서 접근할 수 있도록 이동 bootJar { mainClassName = 'com.hjjang.backend.BackendApplication' -} + dependsOn asciidoctor + from ("${asciidoctor.outputDir}/html5") { + into 'static/docs' + } +} tasks.named('test') { outputs.dir snippetsDir useJUnitPlatform() diff --git a/backend/src/main/resources/static.docs/api.adoc b/backend/src/main/resources/static.docs/api.adoc new file mode 100644 index 0000000..72017dd --- /dev/null +++ b/backend/src/main/resources/static.docs/api.adoc @@ -0,0 +1,52 @@ +ifndef::snippets[] +:snippets: ./build/generated-snippets +endif::[] +:doctype: book +:icons: font +:source-highlighter: highlightjs +:toc: left +:toclevels: 2 +:sectlinks: +:docinfo: shared-head + += REST API Document + +[[introduction]] +== Introduction + +✨BAuction (Book + Auction)✨ + +중고책 실시간 경매 서비스 + +[[common]] +== Common + +=== Domain + +|=== +| 환경 | Domain +| 로컬 서버 +| `http://localhost:3000` +|=== + +=== Exception + +|=== +| 상태 코드 | 설명 + +| 400 +| `잘못된 데이터` + +| 401 +| `권한 없음` +|=== + +|=== + +|=== +== User API +include::{snippets}/v1/users/profile/request-headers.adoc[] +include::{snippets}/v1/users/profile/http-request.adoc[] +include::{snippets}/v1/users/profile/response-body.adoc[] + + From 2221b607acdd49016e25d7d57c1bc14d087b9db3 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 18:16:52 +0900 Subject: [PATCH 46/57] =?UTF-8?q?fix:=20api=20=EC=97=B0=EA=B2=B0=20?= =?UTF-8?q?=EC=8B=AC=ED=94=8C=ED=95=98=EA=B2=8C=20=EB=B0=94=EA=BE=B8?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/static.docs/api.adoc | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/backend/src/main/resources/static.docs/api.adoc b/backend/src/main/resources/static.docs/api.adoc index 72017dd..adb71df 100644 --- a/backend/src/main/resources/static.docs/api.adoc +++ b/backend/src/main/resources/static.docs/api.adoc @@ -40,13 +40,7 @@ endif::[] | 401 | `권한 없음` |=== - +== User API +operation::v1/users/profile[snippets='http-request,request-fields,http-response,response-fields'] |=== - |=== -== User API -include::{snippets}/v1/users/profile/request-headers.adoc[] -include::{snippets}/v1/users/profile/http-request.adoc[] -include::{snippets}/v1/users/profile/response-body.adoc[] - - From abcf7b06a6549f886f13622e674aefc358f5b8dc Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 18:17:19 +0900 Subject: [PATCH 47/57] =?UTF-8?q?chore:=20restdocs=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/build.gradle b/backend/build.gradle index b0acf4b..87db889 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -1,7 +1,7 @@ plugins { id 'org.springframework.boot' version '2.6.4' id 'io.spring.dependency-management' version '1.0.11.RELEASE' - id 'org.asciidoctor.convert' version '1.5.8' + id "org.asciidoctor.jvm.convert" version "3.3.2" id 'java' id 'application' id 'jacoco' @@ -12,6 +12,7 @@ version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' configurations { + asciidoctorExtensions // dependencies 에서 적용한 것 추가 compileOnly { extendsFrom annotationProcessor } @@ -70,6 +71,7 @@ dependencies { testImplementation 'org.springframework.batch:spring-batch-test' testImplementation 'org.springframework.kafka:spring-kafka-test' testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + asciidoctorExtensions 'org.springframework.restdocs:spring-restdocs-asciidoctor' testImplementation 'org.springframework.security:spring-security-test' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' //junit 4 하위 호환을 위한 라이브러리 제거 From 2fed9a3e86502b97dd9a115858d420624c0e277b Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 18:17:48 +0900 Subject: [PATCH 48/57] =?UTF-8?q?fix:=20HTTP=20response=20json=EC=9D=98=20?= =?UTF-8?q?formatting=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/user/controller/docs/UserRestDocument.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java b/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java index 3834d74..37087c3 100644 --- a/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java +++ b/backend/src/test/java/com/hjjang/backend/domain/user/controller/docs/UserRestDocument.java @@ -1,6 +1,7 @@ package com.hjjang.backend.domain.user.controller.docs; import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; +import org.springframework.restdocs.operation.preprocess.Preprocessors; import org.springframework.restdocs.payload.JsonFieldType; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; @@ -12,6 +13,8 @@ public class UserRestDocument { public static RestDocumentationResultHandler getProfile() { return document("v1/users/profile", + Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), + Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), requestHeaders( headerWithName("Authorization").description("Bearer 토큰")), responseFields( From 15f57e833bd34596e834867d70e0c9bdc2c906d4 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 18:36:23 +0900 Subject: [PATCH 49/57] =?UTF-8?q?chore:=20=20Bug=20Report=20template=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/bug-report.md | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.md diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 0000000..2a9bf54 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,30 @@ +--- +name: Bug Report +about: Bug Report 설명 +title: "[BUG]" +labels: "Bug" +assignees: '' + +--- + +## 🤔 버그 내용 +### 버그 내용 및 버그 발생 상황을 알려주세요! +ex) 어떤 api를 호출하였더니 오류가 생겼어요. +
+ +## 🚩 버그 발견 위치 +### 버그 발견 예상 패키지 위치를 알려주세요! +ex) + +
+ +## ⚠ 에러 캡쳐 +### 주요 에러 stack trace를 캡쳐해주세요! + +
+ + +## 🙂 etc +### 추가적으로 하고 싶은 말! (Optional) + +
\ No newline at end of file From 07fe37f1109079558a0ef0f4d14c844ddb812077 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 18:48:51 +0900 Subject: [PATCH 50/57] =?UTF-8?q?docs:=20feature-request=20template=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/feature-request.md | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/feature-request.md diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md new file mode 100644 index 0000000..8e43fe2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -0,0 +1,24 @@ +--- +name: Feature Request +about: 기능 개발 제안 +title: "[FEAT]" +labels: "enhancement" +assignees: '' + +--- + +## ✨ 제안 기능 +### 기능에 대해 간략하게 설명해주세요! + +## 🎇 제안 배경 +### 이 기능을 추가하게 되는 배경에 대해 적어주세요! +ex) 중고 거래에 필요한 채팅 기능이 필요해서 도입한다! + +
+ +## 📢 기능 설명 +### 개발할 기능에 대해 설명해주세요. + +
+ +### 📕 래퍼런스 From 532b729cab86189c56f13aa64845e12e624e3dd4 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Sat, 14 May 2022 19:07:30 +0900 Subject: [PATCH 51/57] =?UTF-8?q?docs:=20pr=20template=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PULL_REQUEST_TEMPLATE.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..77abbd6 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,22 @@ +--- +name: Pull Request +about: pr 설명 +title: "[PR]" +labels: "" +assignees: '' + +--- + + +## 추가한 기능 설명 + +
+ + +## check list +- [ ] issue number를 브랜치 앞에 추가 하였는가?
+- [ ] 그외의 [pr 규칙](https://github.com/h-jjang/bauction/wiki/%5BProject-Rules%5D#pr-%EA%B7%9C%EC%B9%99)을 잘 지켰는가? +- [ ] 모든 단위 테스트를 돌려보고 기존에 작동하던 테스트에 영향이 없는 것을 확인했는가? +설명 +- [ ] naver code style formatting(단축키)을 했는가? +- [ ] [우테코 pr 규칙](https://github.com/woowacourse/woowacourse-docs/blob/master/cleancode/pr_checklist.md)을 준수하였는가? \ No newline at end of file From 6c8222d3f9b7dc2d9bb3d575c31cdeffac3382fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B8=B0=ED=98=84?= <58874807+kim1387@users.noreply.github.com> Date: Sat, 14 May 2022 22:05:40 +0900 Subject: [PATCH 52/57] =?UTF-8?q?docs:=20###=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/bug-report.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 2a9bf54..067808f 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -8,23 +8,23 @@ assignees: '' --- ## 🤔 버그 내용 -### 버그 내용 및 버그 발생 상황을 알려주세요! +버그 내용 및 버그 발생 상황을 알려주세요! ex) 어떤 api를 호출하였더니 오류가 생겼어요.
## 🚩 버그 발견 위치 -### 버그 발견 예상 패키지 위치를 알려주세요! +버그 발견 예상 패키지 위치를 알려주세요! ex)
## ⚠ 에러 캡쳐 -### 주요 에러 stack trace를 캡쳐해주세요! +주요 에러 stack trace를 캡쳐해주세요!
## 🙂 etc -### 추가적으로 하고 싶은 말! (Optional) +추가적으로 하고 싶은 말! (Optional) -
\ No newline at end of file +
From b26504d40d8a8b80da71783c6ce5651eda8d1856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B8=B0=ED=98=84?= <58874807+kim1387@users.noreply.github.com> Date: Sat, 14 May 2022 22:06:26 +0900 Subject: [PATCH 53/57] =?UTF-8?q?docs:=20###=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/feature-request.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md index 8e43fe2..9c1d33d 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.md +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -8,16 +8,16 @@ assignees: '' --- ## ✨ 제안 기능 -### 기능에 대해 간략하게 설명해주세요! +기능에 대해 간략하게 설명해주세요! ## 🎇 제안 배경 -### 이 기능을 추가하게 되는 배경에 대해 적어주세요! +이 기능을 추가하게 되는 배경에 대해 적어주세요! ex) 중고 거래에 필요한 채팅 기능이 필요해서 도입한다!
## 📢 기능 설명 -### 개발할 기능에 대해 설명해주세요. +개발할 기능에 대해 설명해주세요.
From b713b2b6bc3ad7ca14a55bd3689ca75101662982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B8=B0=ED=98=84?= <58874807+kim1387@users.noreply.github.com> Date: Sat, 14 May 2022 22:07:33 +0900 Subject: [PATCH 54/57] =?UTF-8?q?docs:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EB=9D=BC=EB=B2=A8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/bug-report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 067808f..6a1fd62 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -2,7 +2,7 @@ name: Bug Report about: Bug Report 설명 title: "[BUG]" -labels: "Bug" +labels: "ug" assignees: '' --- From 5f292f3ae35a6a3b8e55adc8a48e60d4f77c50b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B8=B0=ED=98=84?= <58874807+kim1387@users.noreply.github.com> Date: Sat, 14 May 2022 22:09:13 +0900 Subject: [PATCH 55/57] =?UTF-8?q?docs:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EB=9D=BC=EB=B2=A8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/bug-report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 6a1fd62..8e3f6ae 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -2,7 +2,7 @@ name: Bug Report about: Bug Report 설명 title: "[BUG]" -labels: "ug" +labels: "bug" assignees: '' --- From 0d1d196665db074db5b5f66991839f95a7e3c598 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 17 May 2022 01:20:15 +0900 Subject: [PATCH 56/57] =?UTF-8?q?hotfix:=20entity=EC=97=90=EB=8A=94=20bool?= =?UTF-8?q?ean=ED=83=80=EC=9E=85=EC=9D=B4=20=EC=98=AC=20=EC=88=98=20?= =?UTF-8?q?=EC=97=86=EC=96=B4=EC=84=9C=20Boolean=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=94=EA=BF=94=EC=A4=AC=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/user/entity/AnonymousEmptyUser.java | 2 +- .../java/com/hjjang/backend/domain/user/entity/User.java | 9 +++++++-- .../global/security/service/CustomOAuth2UserService.java | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java index 435c27b..a8d39e5 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/AnonymousEmptyUser.java @@ -2,7 +2,7 @@ public class AnonymousEmptyUser extends User { public AnonymousEmptyUser() { - super(null, null, null, null, null, null, null, null, null, false); + super(null, null, null, null, null, null, null, null, null, false, false); } } diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java index 4647087..86fb0bf 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java @@ -51,11 +51,15 @@ public class User extends BaseTimeEntity { private RoleType role; @Column(name = "is_email_verification", length = 20) - private boolean isEmailVerification; + private Boolean isEmailVerification; + + @Column(name = "is_blocked", length = 20) + private Boolean isBlocked; @Builder public User(String providerId, String nickName, String email, Long mannerTemperature, - String imageUrl, Agreement isPushAgree, Long univId, RoleType role, boolean isEmailVerification) { + String imageUrl, Agreement isPushAgree, Long univId, RoleType role, Boolean isEmailVerification, + Boolean isBlocked) { this.providerId = providerId; this.nickName = nickName; this.email = email; @@ -65,5 +69,6 @@ public User(String providerId, String nickName, String email, Long mannerTempera this.univId = univId; this.role = role; this.isEmailVerification = isEmailVerification; + this.isBlocked = isBlocked; } } diff --git a/backend/src/main/java/com/hjjang/backend/global/security/service/CustomOAuth2UserService.java b/backend/src/main/java/com/hjjang/backend/global/security/service/CustomOAuth2UserService.java index c7efb1b..ec921f5 100644 --- a/backend/src/main/java/com/hjjang/backend/global/security/service/CustomOAuth2UserService.java +++ b/backend/src/main/java/com/hjjang/backend/global/security/service/CustomOAuth2UserService.java @@ -62,6 +62,8 @@ private User createUser(ParsingUserContext userInfo) { .mannerTemperature((long)36.5) .imageUrl(userInfo.getImageUrl()) .role(RoleType.USER) + .isEmailVerification(false) + .isBlocked(false) .build(); return userRepository.saveAndFlush(user); } From 191e6eecac4c175afdcf59cb55af1bf4834c4b12 Mon Sep 17 00:00:00 2001 From: kim1387 Date: Tue, 17 May 2022 21:17:19 +0900 Subject: [PATCH 57/57] =?UTF-8?q?fix:=20Boolean=20=EA=B0=92=EC=97=90=20?= =?UTF-8?q?=EA=B8=B8=EC=9D=B4=20=EC=98=B5=EC=85=98=20=EB=B9=BC=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hjjang/backend/domain/user/entity/User.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java index 86fb0bf..57f9530 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java @@ -36,7 +36,7 @@ public class User extends BaseTimeEntity { @Column(name = "manner_temperature", nullable = false) private Long mannerTemperature; - @Column(name = "image_url", nullable = true, length = 50) + @Column(name = "image_url", length = 50) private String imageUrl; @Enumerated(STRING) @@ -50,10 +50,10 @@ public class User extends BaseTimeEntity { @Enumerated(STRING) private RoleType role; - @Column(name = "is_email_verification", length = 20) + @Column(name = "is_email_verification") private Boolean isEmailVerification; - @Column(name = "is_blocked", length = 20) + @Column(name = "is_blocked") private Boolean isBlocked; @Builder