forked from IT-Pick/IT-Pick-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request IT-Pick#5 from ho0010/dev
Feat: setting
- Loading branch information
Showing
30 changed files
with
759 additions
and
17 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
34 changes: 34 additions & 0 deletions
34
...in/java/store/itpick/backend/common/argument_resolver/JwtAuthHandlerArgumentResolver.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 store.itpick.backend.common.argument_resolver; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.MethodParameter; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.support.WebDataBinderFactory; | ||
import org.springframework.web.context.request.NativeWebRequest; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.method.support.ModelAndViewContainer; | ||
|
||
import java.util.Arrays; | ||
|
||
@Slf4j | ||
@Component | ||
public class JwtAuthHandlerArgumentResolver implements HandlerMethodArgumentResolver { | ||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
boolean hasAnnotation = parameter.hasParameterAnnotation(PreAuthorize.class); | ||
log.info(Arrays.toString(parameter.getParameterAnnotations())); | ||
boolean hasType = long.class.isAssignableFrom(parameter.getParameterType()); | ||
log.info("hasAnnotation={}, hasType={}, hasAnnotation && hasType={}", hasAnnotation, hasType, hasAnnotation&&hasType); | ||
return hasAnnotation && hasType; | ||
} | ||
|
||
@Override | ||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { | ||
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); | ||
log.info("userId={}", request.getAttribute("userId")); | ||
return request.getAttribute("userId"); | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/store/itpick/backend/common/argument_resolver/PreAuthorize.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,11 @@ | ||
package store.itpick.backend.common.argument_resolver; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface PreAuthorize { | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/store/itpick/backend/common/exception/BadRequestException.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,15 @@ | ||
package store.itpick.backend.common.exception; | ||
|
||
import kuit3.backend.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BadRequestException extends RuntimeException { | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public BadRequestException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/store/itpick/backend/common/exception/DatabaseException.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,15 @@ | ||
package store.itpick.backend.common.exception; | ||
|
||
import kuit3.backend.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class DatabaseException extends RuntimeException{ | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public DatabaseException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/store/itpick/backend/common/exception/InternalServerErrorException.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,15 @@ | ||
package store.itpick.backend.common.exception; | ||
|
||
import kuit3.backend.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class InternalServerErrorException extends RuntimeException { | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public InternalServerErrorException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...in/java/store/itpick/backend/common/exception/jwt/bad_request/JwtBadRequestException.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,15 @@ | ||
package store.itpick.backend.common.exception.jwt.bad_request; | ||
|
||
import kuit3.backend.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class JwtBadRequestException extends RuntimeException { | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public JwtBadRequestException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/store/itpick/backend/common/exception/jwt/bad_request/JwtNoTokenException.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,15 @@ | ||
package store.itpick.backend.common.exception.jwt.bad_request; | ||
|
||
import kuit3.backend.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class JwtNoTokenException extends JwtBadRequestException { | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public JwtNoTokenException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...a/store/itpick/backend/common/exception/jwt/bad_request/JwtUnsupportedTokenException.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,15 @@ | ||
package store.itpick.backend.common.exception.jwt.bad_request; | ||
|
||
import kuit3.backend.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class JwtUnsupportedTokenException extends JwtBadRequestException { | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public JwtUnsupportedTokenException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...java/store/itpick/backend/common/exception/jwt/unauthorized/JwtExpiredTokenException.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,15 @@ | ||
package store.itpick.backend.common.exception.jwt.unauthorized; | ||
|
||
import kuit3.backend.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class JwtExpiredTokenException extends JwtUnauthorizedTokenException { | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public JwtExpiredTokenException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...java/store/itpick/backend/common/exception/jwt/unauthorized/JwtInvalidTokenException.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,15 @@ | ||
package store.itpick.backend.common.exception.jwt.unauthorized; | ||
|
||
import kuit3.backend.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class JwtInvalidTokenException extends JwtUnauthorizedTokenException { | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public JwtInvalidTokenException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...va/store/itpick/backend/common/exception/jwt/unauthorized/JwtMalformedTokenException.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,15 @@ | ||
package store.itpick.backend.common.exception.jwt.unauthorized; | ||
|
||
import kuit3.backend.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class JwtMalformedTokenException extends JwtUnauthorizedTokenException { | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public JwtMalformedTokenException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...store/itpick/backend/common/exception/jwt/unauthorized/JwtUnauthorizedTokenException.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,15 @@ | ||
package store.itpick.backend.common.exception.jwt.unauthorized; | ||
|
||
import kuit3.backend.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class JwtUnauthorizedTokenException extends RuntimeException { | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public JwtUnauthorizedTokenException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...ain/java/store/itpick/backend/common/exception_handler/BaseExceptionControllerAdvice.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,66 @@ | ||
package store.itpick.backend.common.exception_handler; | ||
|
||
import jakarta.validation.ConstraintViolationException; | ||
import kuit3.backend.common.exception.BadRequestException; | ||
import kuit3.backend.common.exception.InternalServerErrorException; | ||
import kuit3.backend.common.response.BaseErrorResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.TypeMismatchException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.HttpRequestMethodNotSupportedException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import org.springframework.web.servlet.NoHandlerFoundException; | ||
|
||
import static kuit3.backend.common.response.status.BaseExceptionResponseStatus.*; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class BaseExceptionControllerAdvice { | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler({BadRequestException.class, NoHandlerFoundException.class, TypeMismatchException.class}) | ||
public BaseErrorResponse handle_BadRequest(Exception e) { | ||
log.error("[handle_BadRequest]", e); | ||
return new BaseErrorResponse(URL_NOT_FOUND); | ||
} | ||
|
||
// 위와 동일 (return ResponseEntity<>) | ||
/* | ||
@ExceptionHandler({BadRequestException.class, NoHandlerFoundException.class, TypeMismatchException.class, HttpRequestMethodNotSupportedException.class}) | ||
public ResponseEntity<BaseErrorResponse> handle_BadRequest(BadRequestException e) { | ||
log.error("[handle_BadRequest]", e); | ||
return ResponseEntity.badRequest().body(new BaseErrorResponse(e.getExceptionStatus())); | ||
} | ||
*/ | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class) | ||
public BaseErrorResponse handle_HttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { | ||
log.error("[handle_HttpRequestMethodNotSupportedException]", e); | ||
return new BaseErrorResponse(METHOD_NOT_ALLOWED); | ||
} | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(ConstraintViolationException.class) | ||
public BaseErrorResponse handle_ConstraintViolationException(ConstraintViolationException e) { | ||
log.error("[handle_ConstraintViolationException]", e); | ||
return new BaseErrorResponse(BAD_REQUEST, e.getMessage()); | ||
} | ||
|
||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
@ExceptionHandler(InternalServerErrorException.class) | ||
public BaseErrorResponse handle_InternalServerError(InternalServerErrorException e) { | ||
log.error("[handle_InternalServerError]", e); | ||
return new BaseErrorResponse(e.getExceptionStatus()); | ||
} | ||
|
||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
@ExceptionHandler(RuntimeException.class) | ||
public BaseErrorResponse handle_RuntimeException(Exception e) { | ||
log.error("[handle_RuntimeException]", e); | ||
return new BaseErrorResponse(SERVER_ERROR); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...java/store/itpick/backend/common/exception_handler/DatabaseExceptionControllerAdvice.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 store.itpick.backend.common.exception_handler; | ||
|
||
import jakarta.annotation.Priority; | ||
import kuit3.backend.common.response.BaseErrorResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.dao.DataAccessException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.jdbc.BadSqlGrammarException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import static kuit3.backend.common.response.status.BaseExceptionResponseStatus.BAD_SQL_GRAMMAR; | ||
import static kuit3.backend.common.response.status.BaseExceptionResponseStatus.DATABASE_ERROR; | ||
|
||
@Slf4j | ||
@Priority(0) | ||
@RestControllerAdvice | ||
public class DatabaseExceptionControllerAdvice { | ||
|
||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
@ExceptionHandler(BadSqlGrammarException.class) | ||
public BaseErrorResponse handle_BadSqlGrammarException(BadSqlGrammarException e) { | ||
log.error("[handle_BadSqlGrammarException]", e); | ||
return new BaseErrorResponse(BAD_SQL_GRAMMAR); | ||
} | ||
|
||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
@ExceptionHandler(DataAccessException.class) | ||
public BaseErrorResponse handle_DataAccessException(DataAccessException e) { | ||
log.error("[handle_DataAccessException]", e); | ||
return new BaseErrorResponse(DATABASE_ERROR); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...main/java/store/itpick/backend/common/exception_handler/JwtExceptionControllerAdvice.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,31 @@ | ||
package store.itpick.backend.common.exception_handler; | ||
|
||
import jakarta.annotation.Priority; | ||
import kuit3.backend.common.exception.jwt.bad_request.JwtBadRequestException; | ||
import kuit3.backend.common.exception.jwt.unauthorized.JwtUnauthorizedTokenException; | ||
import kuit3.backend.common.response.BaseErrorResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@Priority(0) | ||
@RestControllerAdvice | ||
public class JwtExceptionControllerAdvice { | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(JwtBadRequestException.class) | ||
public BaseErrorResponse handle_JwtBadRequestException(JwtBadRequestException e) { | ||
log.error("[handle_JwtBadRequestException]", e); | ||
return new BaseErrorResponse(e.getExceptionStatus()); | ||
} | ||
|
||
@ResponseStatus(HttpStatus.UNAUTHORIZED) | ||
@ExceptionHandler(JwtUnauthorizedTokenException.class) | ||
public BaseErrorResponse handle_JwtUnauthorizedException(JwtUnauthorizedTokenException e) { | ||
log.error("[handle_JwtUnauthorizedException]", e); | ||
return new BaseErrorResponse(e.getExceptionStatus()); | ||
} | ||
} |
Oops, something went wrong.