Skip to content

Commit

Permalink
feat: 소셜 로그인 후 리다이렉트 경로를 지정하도록 변경 (#127)
Browse files Browse the repository at this point in the history
* feat: 어드민 랜딩 상태 추가

* feat: 소셜 로그인 후 클라이언트로 리다이렉트하도록 설정

* chore: 테스트 트리거 활성화

* chore: 테스트 트리거 비활성화

* chore: 스프링부트 버전업

* feat: 소셜 로그인 리다이렉트 URL 수정

* refactor: 비정적 메서드를 사용하도록 변경

* refactor: 레퍼러를 base url로 사용하도록 활성화
  • Loading branch information
uwoobeat authored Feb 25, 2024
1 parent d00d6f1 commit 9aacd4a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 9aacd4a

Please sign in to comment.