Skip to content

Commit

Permalink
Merge pull request #113 from studio-recoding/dev
Browse files Browse the repository at this point in the history
[⚠️!HOTFIX] 12차 배포
  • Loading branch information
JeonHaeseung authored Jun 11, 2024
2 parents 9770fd6 + 3dde479 commit ace43dd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Ness.Backend.domain.auth.oAuth;

import Ness.Backend.global.error.ErrorCode;
import Ness.Backend.global.error.exception.OAuthVerificationException;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import java.io.IOException;
@Slf4j
@RequiredArgsConstructor
public class OAuthFailureHandler implements AuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
throw new OAuthVerificationException(exception.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Ness.Backend.domain.auth.jwt.JwtAuthorizationFilter;
import Ness.Backend.domain.auth.jwt.JwtTokenProvider;
import Ness.Backend.domain.auth.oAuth.OAuth2CustomUserService;
import Ness.Backend.domain.auth.oAuth.OAuthFailureHandler;
import Ness.Backend.domain.auth.oAuth.OAuthSuccessHandler;
import Ness.Backend.domain.member.MemberRepository;
import jakarta.servlet.DispatcherType;
Expand Down Expand Up @@ -44,6 +45,11 @@ public OAuthSuccessHandler oAuthSuccessHandler(){
return new OAuthSuccessHandler(jwtTokenProvider());
}

@Bean
public OAuthFailureHandler oAuthFailureHandler(){
return new OAuthFailureHandler();
}

/* 로그인: 사용자 정보(memberRepository 내용)를 토대로 토큰을 생성하거나 검증 */
@Bean
public JwtTokenProvider jwtTokenProvider() {
Expand Down Expand Up @@ -91,7 +97,8 @@ public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Excepti
.oauth2Login((oauth2) -> oauth2 //oauth가 성공하면 보내줄 포인트
.userInfoEndpoint(userInfoEndpoint -> userInfoEndpoint
.userService(oAuth2CustomUserService))
.successHandler(oAuthSuccessHandler()))
.successHandler(oAuthSuccessHandler())
.failureHandler(oAuthFailureHandler()))
.authorizeHttpRequests(requests -> requests
.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll()
//.requestMatchers("/signup/**", "/login/**").permitAll() // 회원가입 및 로그인 경로는 인증 생략
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Ness/Backend/global/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum ErrorCode {
INVALID_TOKEN_SIGNATURE(BAD_REQUEST, "AUTH010", "유효하지 않은 시그니처를 가진 토큰입니다. 온전한 토큰이 맞는지 확인해주세요."),
TOKEN_ERROR(BAD_REQUEST, "AUTH011", "기타 토큰 에러입니다."),
INVALID_PRINCIPAL(BAD_REQUEST, "AUTH012", "인증정보가 존재하지 않습니다."),
OAUTH_ERROR(BAD_REQUEST, "AUTH012", "소셜 로그인 에러입니다."),

/* 카테고리 관련 */
INVALID_CATEGORY_NAME(CONFLICT, "CATE001", "해당 카테고리명이 이미 존재합니다. 카테고리명은 중복될 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package Ness.Backend.global.error.exception;

import Ness.Backend.global.error.ErrorCode;
import lombok.Getter;
@Getter
public class OAuthVerificationException extends BaseException {
public OAuthVerificationException() {
super(ErrorCode.OAUTH_ERROR, ErrorCode.OAUTH_ERROR.getMessage());
}
public OAuthVerificationException(String message) {
super(ErrorCode.OAUTH_ERROR, message);
}
public OAuthVerificationException(ErrorCode errorCode) {
super(errorCode, errorCode.getMessage());
}
}

0 comments on commit ace43dd

Please sign in to comment.