From bf63701e68e07f837a161f650aeb1317df1350b9 Mon Sep 17 00:00:00 2001 From: Rinjae Date: Tue, 18 Aug 2026 14:50:08 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A6=AC=EB=8B=A4=EC=9D=B4=EB=A0=89=ED=8A=B8?= =?UTF-8?q?=20=EA=B2=BD=EB=A1=9C=20=EC=83=81=EC=88=98=ED=99=94=20=EB=B0=8F?= =?UTF-8?q?=20=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0=20-=20"redirect:/",?= =?UTF-8?q?=20"redirect:/login=3Freason=3Dauth"=20=EC=83=81=EC=88=98?= =?UTF-8?q?=EB=A1=9C=20=EC=B9=98=ED=99=98=20-=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=EB=90=9C=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=EC=A0=95=EC=9D=98=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20=EA=B0=80=EB=8F=85=EC=84=B1=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PortalGlobalExceptionHandler.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/eactive/apim/portal/common/exception/PortalGlobalExceptionHandler.java b/src/main/java/com/eactive/apim/portal/common/exception/PortalGlobalExceptionHandler.java index c39c024..d06550b 100644 --- a/src/main/java/com/eactive/apim/portal/common/exception/PortalGlobalExceptionHandler.java +++ b/src/main/java/com/eactive/apim/portal/common/exception/PortalGlobalExceptionHandler.java @@ -37,23 +37,27 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; @RequiredArgsConstructor public class PortalGlobalExceptionHandler { + private static final String REDIRECT_PREFIX = "redirect:"; + private static final String REDIRECT_HOME = REDIRECT_PREFIX + "/"; + private static final String REDIRECT_LOGIN_AUTH = REDIRECT_PREFIX + "/login?reason=auth"; + private final Logger log = LoggerFactory.getLogger(getClass()); private final PortalProperties portalProperties; private final Environment environment; @ExceptionHandler(value = NotFoundException.class) public ModelAndView handleINotFoundException(HttpServletRequest request, NotFoundException ex) { - return new ModelAndView("redirect:/"); + return new ModelAndView(REDIRECT_HOME); } @ExceptionHandler(value = MethodArgumentTypeMismatchException.class) public ModelAndView handleMethodArgumentTypeMismatchException(HttpServletRequest request, MethodArgumentTypeMismatchException ex) { - return new ModelAndView("redirect:/"); + return new ModelAndView(REDIRECT_HOME); } @ExceptionHandler(value = UserNotLoginException.class) public ModelAndView handleUserNotLoginException(HttpServletRequest request, UserNotLoginException ex) { - return new ModelAndView("redirect:/login?reason=auth"); + return new ModelAndView(REDIRECT_LOGIN_AUTH); } @ExceptionHandler(value = AccessDeniedException.class) @@ -62,7 +66,7 @@ public class PortalGlobalExceptionHandler { if (!SecurityUtil.isAuthenticated()) { // 원래 요청 페이지를 세션에 저장 → 로그인+2FA 완료 후 LoginFinalizer 가 복귀시킨다. savePostLoginRedirect(request); - return new ModelAndView("redirect:/login?reason=auth"); + return new ModelAndView(REDIRECT_LOGIN_AUTH); } log.warn("접근 권한 없음: loginId={}, uri={}", StringMaskingUtil.maskLoginId(SecurityUtil.getCurrentLoginId()), request.getRequestURI()); ModelAndView modelAndView = new ModelAndView("error"); @@ -137,7 +141,7 @@ public class PortalGlobalExceptionHandler { String target = ex.getRedirectPage(); if (!isSafeRedirectTarget(target)) { log.warn("허용되지 않은 리다이렉트 대상 - uri={}, target={}", request.getRequestURI(), target); - return new ModelAndView("redirect:/"); + return new ModelAndView(REDIRECT_HOME); } return new ModelAndView(target); } @@ -148,8 +152,8 @@ public class PortalGlobalExceptionHandler { return false; } String path = target; - if (path.startsWith("redirect:")) { - path = path.substring("redirect:".length()); + if (path.startsWith(REDIRECT_PREFIX)) { + path = path.substring(REDIRECT_PREFIX.length()); } else if (path.startsWith("forward:")) { path = path.substring("forward:".length()); } @@ -172,7 +176,7 @@ public class PortalGlobalExceptionHandler { public ModelAndView handleHttpRequestMethodNotSupportedException(HttpServletRequest request, HttpRequestMethodNotSupportedException ex) { log.error(ex.getMessage()); ModelAndView modelAndView = new ModelAndView(); - modelAndView.setViewName("redirect:/"); + modelAndView.setViewName(REDIRECT_HOME); return modelAndView; } @@ -216,7 +220,7 @@ public class PortalGlobalExceptionHandler { public ModelAndView handleInvalidFileException(HttpServletRequest request, RedirectAttributes redirectAttributes, InvalidFileException ex) { ModelAndView modelAndView = new ModelAndView(); redirectAttributes.addFlashAttribute("error", ex.getMessage()); - modelAndView.setViewName("redirect:" + request.getRequestURI()); + modelAndView.setViewName(REDIRECT_PREFIX + request.getRequestURI()); return modelAndView; } @@ -227,7 +231,7 @@ public class PortalGlobalExceptionHandler { String errorMessage = "파일 크기가 허용된 최대 용량(" + maxSize + ")을 초과했습니다."; redirectAttributes.addFlashAttribute("error", errorMessage); ModelAndView modelAndView = new ModelAndView(); - modelAndView.setViewName("redirect:" + request.getRequestURI()); + modelAndView.setViewName(REDIRECT_PREFIX + request.getRequestURI()); return modelAndView; } }