diff --git a/auth/auth-interceptor/build.gradle b/auth/auth-interceptor/build.gradle index 2b138d2b..4b178849 100644 --- a/auth/auth-interceptor/build.gradle +++ b/auth/auth-interceptor/build.gradle @@ -1,5 +1,6 @@ dependencies { implementation project(':auth:auth-application') - + implementation project(':core:exception-handler') + implementation 'org.springframework.boot:spring-boot-starter-web' } diff --git a/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/AuthExceptionAdvice.java b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/AuthExceptionAdvice.java new file mode 100644 index 00000000..84140b65 --- /dev/null +++ b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/AuthExceptionAdvice.java @@ -0,0 +1,17 @@ +package me.nalab.auth.interceptor; + +import me.nalab.core.exception.handler.ErrorTemplate; +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; + +@RestControllerAdvice +public class AuthExceptionAdvice { + + @ExceptionHandler(CannotValidTokenException.class) + @ResponseStatus(HttpStatus.UNAUTHORIZED) + public ErrorTemplate handleCannotValidTokenException(CannotValidTokenException exception) { + return ErrorTemplate.of(exception.getMessage()); + } +} diff --git a/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/CannotValidMockTokenException.java b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/CannotValidMockTokenException.java deleted file mode 100644 index 93c1c6bc..00000000 --- a/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/CannotValidMockTokenException.java +++ /dev/null @@ -1,4 +0,0 @@ -package me.nalab.auth.interceptor; - -public class CannotValidMockTokenException extends RuntimeException { -} diff --git a/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/CannotValidTokenException.java b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/CannotValidTokenException.java new file mode 100644 index 00000000..5498f7db --- /dev/null +++ b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/CannotValidTokenException.java @@ -0,0 +1,8 @@ +package me.nalab.auth.interceptor; + +public class CannotValidTokenException extends RuntimeException { + + public CannotValidTokenException(String message) { + super(message); + } +} diff --git a/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptor.java b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptor.java index 4604ad64..d3e1a7fc 100644 --- a/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptor.java +++ b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptor.java @@ -30,12 +30,20 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons if (!isExcludedURI(request)) { String token = request.getHeader("Authorization"); throwIfCannotValidToken(token); - Long targetId = targetIdGetPort.getTargetId(token.split(" ")[1]); + Long targetId = getTargetId(token); request.setAttribute("logined", targetId); } return true; } + private Long getTargetId(String token) { + try { + return targetIdGetPort.getTargetId(token.split(" ")[1]); + } catch (Exception exception) { + throw new CannotValidTokenException(exception.getMessage()); + } + } + private boolean isPreflight(HttpServletRequest request) { return request.getMethod().equals("OPTIONS"); } @@ -63,7 +71,7 @@ private boolean isExcludedURI(HttpServletRequest httpServletRequest) { private void throwIfCannotValidToken(String token) { if (token == null) { - throw new CannotValidMockTokenException(); + throw new CannotValidTokenException("Null token"); } } diff --git a/auth/auth-interceptor/src/main/java/module-info.java b/auth/auth-interceptor/src/main/java/module-info.java deleted file mode 100644 index ecae26d5..00000000 --- a/auth/auth-interceptor/src/main/java/module-info.java +++ /dev/null @@ -1,7 +0,0 @@ -module luffy.auth.auth.interceptor.main { - requires spring.webmvc; - requires spring.context; - requires spring.beans; - requires luffy.auth.auth.application.main; - requires org.apache.tomcat.embed.core; -} diff --git a/gallery/build.gradle b/gallery/build.gradle index 1a0e5aae..4847c734 100644 --- a/gallery/build.gradle +++ b/gallery/build.gradle @@ -4,9 +4,10 @@ repositories { dependencies { implementation project(":core:data") - implementation project(":core:id-generator:id-core") implementation project(":core:time") + implementation project(":core:exception-handler") implementation project(":survey:survey-application") + implementation project(":core:id-generator:id-core") implementation "org.springframework.boot:spring-boot-starter-web" implementation "org.springframework.boot:spring-boot-starter-data-jpa" diff --git a/gallery/src/main/kotlin/me/nalab/gallery/controller/GalleryController.kt b/gallery/src/main/kotlin/me/nalab/gallery/controller/GalleryController.kt index 18c21259..5aa0ea2b 100644 --- a/gallery/src/main/kotlin/me/nalab/gallery/controller/GalleryController.kt +++ b/gallery/src/main/kotlin/me/nalab/gallery/controller/GalleryController.kt @@ -1,5 +1,6 @@ package me.nalab.gallery.controller +import me.nalab.core.exception.handler.ErrorTemplate import me.nalab.gallery.app.GalleryGetApp import me.nalab.gallery.app.GalleryPreviewApp import me.nalab.gallery.app.GalleryRegisterApp @@ -48,4 +49,8 @@ class GalleryController( return galleryGetApp.getGalleries(job, page, count, orderType) } + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(IllegalArgumentException::class) + fun handleIllegalArgumentException(exception: IllegalArgumentException): ErrorTemplate = + ErrorTemplate.of(exception.message ?: "잘못된 요청입니다.") } diff --git a/support/e2e/v1_12_find_bookmarked_survey.hurl b/support/e2e/v1_12_find_bookmarked_survey.hurl index 96840ffe..b2405d05 100644 --- a/support/e2e/v1_12_find_bookmarked_survey.hurl +++ b/support/e2e/v1_12_find_bookmarked_survey.hurl @@ -133,9 +133,6 @@ Authorization: {{ token_type_1 }} {{ auth_token_1 }} HTTP 200 [Asserts] -header "Content-type" == "application/json" - -jsonpath "$.survey_id" == {{ survey_id_1 }} ########## @@ -144,9 +141,6 @@ Authorization: {{ token_type_1 }} {{ auth_token_1 }} HTTP 200 [Asserts] -header "Content-type" == "application/json" - -jsonpath "$.survey_id" == {{ survey_id_2 }} ##########