diff --git a/build.gradle b/build.gradle index 8ba3f7437..df975f31a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.2.1' + id 'org.springframework.boot' version '3.2.3' id 'io.spring.dependency-management' version '1.1.4' id 'org.asciidoctor.jvm.convert' version '3.3.2' id 'com.diffplug.spotless' version '6.23.3' diff --git a/src/main/java/com/gdschongik/gdsc/global/common/constant/UrlConstant.java b/src/main/java/com/gdschongik/gdsc/global/common/constant/UrlConstant.java index 28abc5581..57c4ed62a 100644 --- a/src/main/java/com/gdschongik/gdsc/global/common/constant/UrlConstant.java +++ b/src/main/java/com/gdschongik/gdsc/global/common/constant/UrlConstant.java @@ -14,4 +14,6 @@ private UrlConstant() {} public static final String PROD_SERVER_URL = "https://api.gdschongik.com"; public static final String DEV_SERVER_URL = "https://dev-api.gdschongik.com"; public static final String LOCAL_SERVER_URL = "http://localhost:8080"; + + public static final String SOCIAL_LOGIN_REDIRECT_URL = "%ssocial-login/redirect"; } diff --git a/src/main/java/com/gdschongik/gdsc/global/config/WebSecurityConfig.java b/src/main/java/com/gdschongik/gdsc/global/config/WebSecurityConfig.java index 4802c3994..c7910f364 100644 --- a/src/main/java/com/gdschongik/gdsc/global/config/WebSecurityConfig.java +++ b/src/main/java/com/gdschongik/gdsc/global/config/WebSecurityConfig.java @@ -48,7 +48,7 @@ public class WebSecurityConfig { private final EnvironmentUtil environmentUtil; private final SwaggerProperty swaggerProperty; - private static void defaultFilterChain(HttpSecurity http) throws Exception { + private void defaultFilterChain(HttpSecurity http) throws Exception { http.httpBasic(AbstractHttpConfigurer::disable) .formLogin(AbstractHttpConfigurer::disable) .logout(AbstractHttpConfigurer::disable) diff --git a/src/main/java/com/gdschongik/gdsc/global/security/CustomSuccessHandler.java b/src/main/java/com/gdschongik/gdsc/global/security/CustomSuccessHandler.java index 4533e0e1e..dd735f815 100644 --- a/src/main/java/com/gdschongik/gdsc/global/security/CustomSuccessHandler.java +++ b/src/main/java/com/gdschongik/gdsc/global/security/CustomSuccessHandler.java @@ -1,6 +1,8 @@ package com.gdschongik.gdsc.global.security; import static com.gdschongik.gdsc.global.common.constant.SecurityConstant.*; +import static com.gdschongik.gdsc.global.common.constant.UrlConstant.*; +import static org.springframework.http.HttpHeaders.*; import com.gdschongik.gdsc.domain.auth.application.JwtService; import com.gdschongik.gdsc.domain.auth.dto.AccessTokenDto; @@ -9,22 +11,27 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; +import java.io.IOException; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; @Slf4j -@RequiredArgsConstructor public class CustomSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { private final JwtService jwtService; private final CookieUtil cookieUtil; + public CustomSuccessHandler(JwtService jwtService, CookieUtil cookieUtil) { + this.jwtService = jwtService; + this.cookieUtil = cookieUtil; + this.setUseReferer(true); + } + @Override public void onAuthenticationSuccess( HttpServletRequest request, HttpServletResponse response, Authentication authentication) - throws ServletException { + throws ServletException, IOException { CustomOAuth2User oAuth2User = (CustomOAuth2User) authentication.getPrincipal(); @@ -36,5 +43,9 @@ public void onAuthenticationSuccess( jwtService.createAccessToken(oAuth2User.getMemberId(), oAuth2User.getMemberRole()); RefreshTokenDto refreshTokenDto = jwtService.createRefreshToken(oAuth2User.getMemberId()); cookieUtil.addTokenCookies(response, accessTokenDto.tokenValue(), refreshTokenDto.tokenValue()); + + String baseUrl = determineTargetUrl(request, response); + String redirectUrl = String.format(SOCIAL_LOGIN_REDIRECT_URL, baseUrl); + getRedirectStrategy().sendRedirect(request, response, redirectUrl); } } diff --git a/src/main/java/com/gdschongik/gdsc/global/security/LandingStatus.java b/src/main/java/com/gdschongik/gdsc/global/security/LandingStatus.java index abaf7f122..01d434a63 100644 --- a/src/main/java/com/gdschongik/gdsc/global/security/LandingStatus.java +++ b/src/main/java/com/gdschongik/gdsc/global/security/LandingStatus.java @@ -1,14 +1,21 @@ package com.gdschongik.gdsc.global.security; import com.gdschongik.gdsc.domain.member.domain.Member; +import com.gdschongik.gdsc.domain.member.domain.MemberRole; public enum LandingStatus { + TO_ADMIN, // 어드민 페이지로 랜딩 TO_STUDENT_AUTHENTICATION, // 재학생 인증 페이지로 랜딩 TO_REGISTRATION, // 가입신청 페이지로 랜딩 TO_DASHBOARD, // 대시보드로 랜딩 ; public static LandingStatus of(Member member) { + // 어드민이라면 어드민 페이지로 랜딩 + if (member.getRole().equals(MemberRole.ADMIN)) { + return TO_ADMIN; + } + // 아직 재학생 인증을 하지 않았다면 재학생 인증 페이지로 랜딩 if (!member.getRequirement().isUnivVerified()) { return TO_STUDENT_AUTHENTICATION;