From 90513234017a157cac5ee33af1ed0013e75a33e1 Mon Sep 17 00:00:00 2001 From: Jin Hyuk Date: Thu, 2 Jan 2025 17:26:59 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Exception=EC=9D=84=20throw=20=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EA=B3=A0=20request.setAttribute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/JwtAuthenticationPoint.java | 15 ++++++++++----- .../security/filter/JwtAuthenticationFilter.java | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gaebaljip/exceed/common/security/exception/JwtAuthenticationPoint.java b/src/main/java/com/gaebaljip/exceed/common/security/exception/JwtAuthenticationPoint.java index 14c8afeb..6d7bf683 100644 --- a/src/main/java/com/gaebaljip/exceed/common/security/exception/JwtAuthenticationPoint.java +++ b/src/main/java/com/gaebaljip/exceed/common/security/exception/JwtAuthenticationPoint.java @@ -36,13 +36,18 @@ public void commence( HttpServletResponse response, AuthenticationException authException) throws IOException { - Object exceptionAttribute = request.getAttribute("javax.servlet.error.exception"); - if (exceptionAttribute == null) { + + if (request.getAttribute("swaggerCannotProdException") != null) { + resolver.resolveException( + request, + response, + null, + (Exception) request.getAttribute("swaggerCannotProdException")); + } else if (request.getAttribute("exception") == null) { handleAuthenticationException(response); - } else if (exceptionAttribute instanceof Exception exception) { - resolver.resolveException(request, response, null, exception); } else { - handleAuthenticationException(response); + resolver.resolveException( + request, response, null, (Exception) request.getAttribute("exception")); } } diff --git a/src/main/java/com/gaebaljip/exceed/common/security/filter/JwtAuthenticationFilter.java b/src/main/java/com/gaebaljip/exceed/common/security/filter/JwtAuthenticationFilter.java index 2ffa972e..ee29a780 100644 --- a/src/main/java/com/gaebaljip/exceed/common/security/filter/JwtAuthenticationFilter.java +++ b/src/main/java/com/gaebaljip/exceed/common/security/filter/JwtAuthenticationFilter.java @@ -46,6 +46,8 @@ protected void doFilterInternal( // prod 환경에서 swagger 요청을 차단 if (Boolean.TRUE.equals(springEnvironmentHelper.isProdProfile()) && isSwaggerRequest(request)) { + request.setAttribute( + "swaggerCannotProdException", SwaggerCannotProdException.EXCEPTION); throw SwaggerCannotProdException.EXCEPTION; }