인증/권한 업무 규칙과 전환 불변식 추출 (codex-bais-final3-20260713-192718-BAIS-SPRING-ANA-AUTH-001)

This commit is contained in:
forge-bot 2026-07-13 10:30:35 +00:00
parent f449b32ccd
commit 9d2e1fd4ff

View file

@ -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.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.time.Instant;
import java.util.Map;
/**
* Custom Authentication Entry Point - preserves error response format.
* Maps to AUTH_001, AUTH_003, AUTH_010 error codes.
*/
@Component
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
private final ObjectMapper objectMapper;
public CustomAuthenticationEntryPoint(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}
@Override
public void commence(
HttpServletRequest request,
HttpServletResponse response,
AuthenticationException authException) throws IOException {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
Map<String, Object> errorResponse = Map.of(
"code", "AUTH_001",
"message", "Authentication required",
"timestamp", Instant.now().toString(),
"path", request.getRequestURI()
);
objectMapper.writeValue(response.getOutputStream(), errorResponse);
}
}