From f2bec9f746fadac461cb5575737d345bac086ca0 Mon Sep 17 00:00:00 2001 From: forge-bot Date: Mon, 13 Jul 2026 10:30:37 +0000 Subject: [PATCH] =?UTF-8?q?=EC=9D=B8=EC=A6=9D/=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EC=97=85=EB=AC=B4=20=EA=B7=9C=EC=B9=99=EA=B3=BC=20=EC=A0=84?= =?UTF-8?q?=ED=99=98=20=EB=B6=88=EB=B3=80=EC=8B=9D=20=EC=B6=94=EC=B6=9C=20?= =?UTF-8?q?(codex-bais-final3-20260713-192718-BAIS-SPRING-ANA-AUTH-001)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/CustomAccessDeniedHandler.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 auth-migration/src/main/java/com/example/auth/security/CustomAccessDeniedHandler.java diff --git a/auth-migration/src/main/java/com/example/auth/security/CustomAccessDeniedHandler.java b/auth-migration/src/main/java/com/example/auth/security/CustomAccessDeniedHandler.java new file mode 100644 index 0000000..634cebd --- /dev/null +++ b/auth-migration/src/main/java/com/example/auth/security/CustomAccessDeniedHandler.java @@ -0,0 +1,46 @@ +package com.example.auth.security; + +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.http.MediaType; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.web.access.AccessDeniedHandler; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.time.Instant; +import java.util.Map; + +/** + * Custom Access Denied Handler - preserves error response format. + * Maps to AUTH_030, AUTH_031, AUTH_040, AUTH_041 error codes. + */ +@Component +public class CustomAccessDeniedHandler implements AccessDeniedHandler { + + private final ObjectMapper objectMapper; + + public CustomAccessDeniedHandler(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @Override + public void handle( + HttpServletRequest request, + HttpServletResponse response, + AccessDeniedException accessDeniedException) throws IOException { + + response.setStatus(HttpServletResponse.SC_FORBIDDEN); + response.setContentType(MediaType.APPLICATION_JSON_VALUE); + + Map errorResponse = Map.of( + "code", "AUTH_030", + "message", "Insufficient permissions", + "timestamp", Instant.now().toString(), + "path", request.getRequestURI() + ); + + objectMapper.writeValue(response.getOutputStream(), errorResponse); + } +}