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; }