-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Exception Advisor 생성 및 서비스단 적용 (#24)
* refactor: 로그인 요청 DTO 접목 * refactor: Spring Security Exception 생성 및 Response 규격화 * feat: ExceptionAdvisor 및 Custom Exception Handler 생성 * refactor: Service layer에 Exception Handler 적용
- Loading branch information
Showing
38 changed files
with
660 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/org/goormuniv/ponnect/auth/JwtAuthenticationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.goormuniv.ponnect.auth; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.goormuniv.ponnect.exception.ErrCode; | ||
import org.goormuniv.ponnect.exception.ErrResponse; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import java.io.IOException; | ||
|
||
@Deprecated | ||
@Slf4j | ||
@Component | ||
public class JwtAuthenticationHandler extends OncePerRequestFilter { | ||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { | ||
try{ | ||
doFilter(request, response, filterChain); | ||
}catch (Exception exception){ | ||
log.info("JwtAuthenticationHandler ::{}", exception.getMessage()); | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
response.setContentType("application/json;charset=UTF-8"); | ||
response.setStatus(HttpServletResponse.SC_FORBIDDEN); | ||
ErrResponse errResponse = ErrResponse.builder() | ||
.code(ErrCode.INVALID_ACCESS_TOKEN.getCode()) | ||
.message(ErrCode.INVALID_ACCESS_TOKEN.getMessage()) | ||
.status(ErrCode.INVALID_ACCESS_TOKEN.getStatus()) | ||
.build(); | ||
|
||
response.getWriter().write(objectMapper.writeValueAsString(errResponse)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
import lombok.*; | ||
|
||
@Deprecated | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.goormuniv.ponnect.dto; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class LoginDto { | ||
private String principal; | ||
private String credential; | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/goormuniv/ponnect/exception/CustomException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.goormuniv.ponnect.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public class CustomException extends RuntimeException { | ||
|
||
|
||
private final ErrCode errCode; | ||
|
||
private final HttpStatus httpStatus; | ||
|
||
|
||
public CustomException(final ErrCode errCode, final HttpStatus status) { | ||
super(errCode.getMessage()); | ||
this.errCode = errCode; | ||
this.httpStatus = status; | ||
} | ||
// public CustomException(String message, final ErrCode errCode, final HttpStatus status) { | ||
// super(message); | ||
// this.errCode = errCode; | ||
// this.httpStatus = status; | ||
// } | ||
|
||
|
||
public HttpStatus getStatus() { | ||
return httpStatus; | ||
} | ||
|
||
public ErrCode getErrorCode() { | ||
return errCode; | ||
} | ||
|
||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/goormuniv/ponnect/exception/ErrCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.goormuniv.ponnect.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ErrCode { | ||
UNAUTHORIZED("P401", "인증에 실패하였습니다.", HttpStatus.UNAUTHORIZED.value()), | ||
INVALID_ACCESS_TOKEN("P007", "JWT가 없습니다.", HttpStatus.FORBIDDEN.value()), | ||
DUPLICATED_EMAIL("P0006", "이미 사용중인 이메일입니다.", HttpStatus.BAD_REQUEST.value()), | ||
LOGIN_FAILED("P001", "아이디 또는 비밀번호가 잘못되었습니다.", HttpStatus.BAD_REQUEST.value()), | ||
SIGN_UP_FAILED("P002", "회원가입에 실패하였습니다.", HttpStatus.NOT_ACCEPTABLE.value()), | ||
REISSUE_FAILED("P003", "비밀번호 재발급에 실패했습니다.", HttpStatus.NOT_ACCEPTABLE.value()), | ||
ALREADY_MEMBER("P004", "이미 가입된 사용자 입니다.", HttpStatus.BAD_REQUEST.value()), | ||
USER_NOT_FOUND("P005", "사용자를 찾을 수 없습니다,", HttpStatus.NOT_FOUND.value()), | ||
|
||
ALREADY_FOLLOW("P100", "이미 추가한 사용자입니다.", HttpStatus.BAD_REQUEST.value()), | ||
|
||
|
||
NO_EXIST_FOLLOW_MEMBER("P101", "해당 회원은 팔로우 된 상태가 아닙니다.", HttpStatus.BAD_REQUEST.value()), | ||
NO_EXIST_CARD("P102","해당 명함이 존재하지 않습니다." , HttpStatus.NOT_FOUND.value()), | ||
|
||
SELF_FOLLOW("P103", "자신을 팔로우 할 수 업습니다.", HttpStatus.BAD_REQUEST.value()), | ||
NO_EXIST_CATEGORY("P104", "해당 카테고리를 찾을 수 없습니다.", HttpStatus.NOT_FOUND.value()), | ||
NOT_CONTENT("P105", "추가할 항목이 없습니다.", HttpStatus.NOT_ACCEPTABLE.value()), | ||
NOT_FOUND_MEMBER("P410", "사용자 정보를 찾을 수 없습니다.", HttpStatus.NOT_FOUND.value()), | ||
INTERNAL_SERVER_ERROR("P500", "서버가 요청 처리에 실패하였습니다..", HttpStatus.INTERNAL_SERVER_ERROR.value()), | ||
CREATE_CARD_TO_CATEGORY_FAILED("P106", "명함함 등록에 실패하였습니다.", HttpStatus.NOT_ACCEPTABLE.value()), | ||
RENAME_CATEGORY_FAILED("P107", "카테고리 이름 수정에 실파하였습니다.", HttpStatus.NOT_ACCEPTABLE.value()), | ||
REMOVE_CARD_OF_CATEGORY_FAILED("P108", "카테고리 내 명함 삭제에 실파하였습니다.", HttpStatus.NOT_ACCEPTABLE.value()), | ||
NO_EXIST_CARD_OF_CATEGORY("P109", "해당 카테고리 내 명함을 찾을 수 없습니다.", HttpStatus.NOT_FOUND.value()), | ||
REMOVE_CATEGORY_FAILED("P110", "해당 카테고리를 삭제할 수 없습니다.", HttpStatus.NOT_ACCEPTABLE.value()), | ||
NO_PERMISSION("P406", "접근 권한이 없어 수행할 수 없습니다.", HttpStatus.NOT_ACCEPTABLE.value()); | ||
|
||
|
||
|
||
|
||
|
||
private final String code; | ||
private final String message; | ||
private final int status; | ||
|
||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/goormuniv/ponnect/exception/ErrResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.goormuniv.ponnect.exception; | ||
|
||
import lombok.*; | ||
|
||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Setter | ||
@Builder | ||
public class ErrResponse { | ||
|
||
private String code; | ||
|
||
private int status; | ||
|
||
private String message; | ||
|
||
public ErrResponse(ErrCode errCode) { | ||
this.code = errCode.getCode(); | ||
this.message = errCode.getMessage(); | ||
this.status = errCode.getStatus(); | ||
} | ||
|
||
} |
Oops, something went wrong.