diff --git a/src/main/java/org/capstone/maru/config/JpaConfig.java b/src/main/java/org/capstone/maru/config/JpaConfig.java index 59ff2d6f20..edf60c52c1 100644 --- a/src/main/java/org/capstone/maru/config/JpaConfig.java +++ b/src/main/java/org/capstone/maru/config/JpaConfig.java @@ -6,6 +6,9 @@ import org.springframework.data.domain.AuditorAware; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +/** + * login 구현시 tester -> name 변경 + */ @EnableJpaAuditing @Configuration public class JpaConfig { diff --git a/src/main/java/org/capstone/maru/config/SecurityConfig.java b/src/main/java/org/capstone/maru/config/SecurityConfig.java index eb8fcfdb54..3616a684a5 100644 --- a/src/main/java/org/capstone/maru/config/SecurityConfig.java +++ b/src/main/java/org/capstone/maru/config/SecurityConfig.java @@ -2,10 +2,7 @@ import lombok.extern.slf4j.Slf4j; -import org.capstone.maru.security.CustomOAuth2UserService; -import org.capstone.maru.security.KakaoOAuth2Response; -import org.capstone.maru.security.SharedPostPrincipal; -import org.capstone.maru.service.MemberAccountService; +import org.capstone.maru.security.service.CustomOAuth2UserService; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.security.servlet.PathRequest; import org.springframework.context.annotation.Bean; @@ -13,12 +10,6 @@ import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; -import org.springframework.security.crypto.factory.PasswordEncoderFactories; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService; -import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest; -import org.springframework.security.oauth2.client.userinfo.OAuth2UserService; -import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.security.web.SecurityFilterChain; @Slf4j @@ -29,7 +20,7 @@ public class SecurityConfig { @ConditionalOnProperty(name = "spring.h2.console.enabled", havingValue = "true") public WebSecurityCustomizer configureH2ConsoleEnable() { return web -> web.ignoring() - .requestMatchers(PathRequest.toH2Console()); + .requestMatchers(PathRequest.toH2Console()); } @Bean @@ -58,43 +49,4 @@ public SecurityFilterChain securityFilterChain( ) .build(); } - - @Bean - public OAuth2UserService oAuth2UserService( - MemberAccountService memberAccountService, - PasswordEncoder passwordEncoder - ) { - final DefaultOAuth2UserService delegate = new DefaultOAuth2UserService(); - - return userRequest -> { - OAuth2User oAuth2User = delegate.loadUser(userRequest); - - KakaoOAuth2Response kakaoOAuthResponse = KakaoOAuth2Response.from( - oAuth2User.getAttributes()); - - String registrationId = userRequest.getClientRegistration() - .getRegistrationId(); // "kakao" - - String providerId = String.valueOf(kakaoOAuthResponse.id()); - String memberId = registrationId + "_" + providerId; - - return memberAccountService - .searchMember(memberId) - .map(SharedPostPrincipal::from) - .orElseGet(() -> - SharedPostPrincipal.from( - memberAccountService.saveUser( - memberId, - kakaoOAuthResponse.email(), - kakaoOAuthResponse.nickname() - ) - ) - ); - }; - } - - @Bean - public PasswordEncoder passwordEncoder() { - return PasswordEncoderFactories.createDelegatingPasswordEncoder(); - } } diff --git a/src/main/java/org/capstone/maru/controller/MainController.java b/src/main/java/org/capstone/maru/controller/MainController.java index 9568c0afc1..1888aacd0c 100644 --- a/src/main/java/org/capstone/maru/controller/MainController.java +++ b/src/main/java/org/capstone/maru/controller/MainController.java @@ -1,6 +1,6 @@ package org.capstone.maru.controller; -import org.capstone.maru.security.SharedPostPrincipal; +import org.capstone.maru.security.principal.SharedPostPrincipal; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -10,7 +10,7 @@ public class MainController { @GetMapping("/") public String root() { - return "home"; + return "health check"; } @GetMapping("/test") diff --git a/src/main/java/org/capstone/maru/security/constant/SocialType.java b/src/main/java/org/capstone/maru/security/constant/SocialType.java index 87e43377da..3ef5283a2d 100644 --- a/src/main/java/org/capstone/maru/security/constant/SocialType.java +++ b/src/main/java/org/capstone/maru/security/constant/SocialType.java @@ -12,14 +12,11 @@ public enum SocialType { private final String key; public static SocialType of(String registrationId) { - switch (registrationId) { - case "kakao": - return SocialType.KAKAO; - case "naver": - return SocialType.NAVER; - default: - throw new IllegalArgumentException( - "Unsupported social registrationId: " + registrationId); - } + return switch (registrationId) { + case "kakao" -> SocialType.KAKAO; + case "naver" -> SocialType.NAVER; + default -> throw new IllegalArgumentException( + "Unsupported social registrationId: " + registrationId); + }; } } diff --git a/src/main/java/org/capstone/maru/security/principal/SharedPostPrincipal.java b/src/main/java/org/capstone/maru/security/principal/SharedPostPrincipal.java index 852c6c3301..2afcc603d6 100644 --- a/src/main/java/org/capstone/maru/security/principal/SharedPostPrincipal.java +++ b/src/main/java/org/capstone/maru/security/principal/SharedPostPrincipal.java @@ -1,4 +1,4 @@ -package org.capstone.maru.security; +package org.capstone.maru.security.principal; import java.util.Collection; import java.util.Map; diff --git a/src/main/java/org/capstone/maru/security/response/KakaoOAuth2Response.java b/src/main/java/org/capstone/maru/security/response/KakaoOAuth2Response.java index 92db7d47bd..a9502a1784 100644 --- a/src/main/java/org/capstone/maru/security/response/KakaoOAuth2Response.java +++ b/src/main/java/org/capstone/maru/security/response/KakaoOAuth2Response.java @@ -1,4 +1,4 @@ -package org.capstone.maru.security; +package org.capstone.maru.security.response; import java.time.LocalDateTime; import java.time.ZoneId; diff --git a/src/main/java/org/capstone/maru/security/response/NaverOAuth2Response.java b/src/main/java/org/capstone/maru/security/response/NaverOAuth2Response.java index b645401b3d..44b1b19c98 100644 --- a/src/main/java/org/capstone/maru/security/response/NaverOAuth2Response.java +++ b/src/main/java/org/capstone/maru/security/response/NaverOAuth2Response.java @@ -1,4 +1,4 @@ -package org.capstone.maru.security; +package org.capstone.maru.security.response; import java.util.Map; import lombok.Getter; diff --git a/src/main/java/org/capstone/maru/security/response/OAuth2Response.java b/src/main/java/org/capstone/maru/security/response/OAuth2Response.java index 88c1c49456..4e11e4c4be 100644 --- a/src/main/java/org/capstone/maru/security/response/OAuth2Response.java +++ b/src/main/java/org/capstone/maru/security/response/OAuth2Response.java @@ -1,4 +1,4 @@ -package org.capstone.maru.security; +package org.capstone.maru.security.response; import java.util.Map; import lombok.Getter; @@ -11,7 +11,7 @@ public abstract class OAuth2Response { /** * SocialType에 맞는 메소드 호출하여 OAuthAttributes 객체 반환 파라미터 : userNameAttributeName -> OAuth2 로그인 시 * 키(PK)가 되는 값 / attributes : OAuth 서비스의 유저 정보들 소셜별 of 메소드(ofGoogle, ofKaKao, ofNaver)들은 각각 소셜 - * 로그인 API에서 제공하는 회원의 식별값(id), attributes, nameAttributeKey를 저장 후 build + * 로그인 API에서 제공하는 회원의 식별값(id), attributes, nameAttributeKey를 저장 후 build 필드가 들어갈 수 있을거 같은데 */ public static OAuth2Response of( SocialType socialType, diff --git a/src/main/java/org/capstone/maru/security/service/CustomOAuth2UserService.java b/src/main/java/org/capstone/maru/security/service/CustomOAuth2UserService.java index 5b0a0d65ab..df4566e29d 100644 --- a/src/main/java/org/capstone/maru/security/service/CustomOAuth2UserService.java +++ b/src/main/java/org/capstone/maru/security/service/CustomOAuth2UserService.java @@ -1,6 +1,8 @@ -package org.capstone.maru.security; +package org.capstone.maru.security.service; import lombok.RequiredArgsConstructor; +import org.capstone.maru.security.response.OAuth2Response; +import org.capstone.maru.security.principal.SharedPostPrincipal; import org.capstone.maru.security.constant.SocialType; import org.capstone.maru.service.MemberAccountService; import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService;