diff --git a/src/main/java/team7/inplace/security/handler/CustomAccessDeniedHandler.java b/src/main/java/team7/inplace/security/handler/CustomAccessDeniedHandler.java index cc7d18a8..1eebcd8b 100644 --- a/src/main/java/team7/inplace/security/handler/CustomAccessDeniedHandler.java +++ b/src/main/java/team7/inplace/security/handler/CustomAccessDeniedHandler.java @@ -2,12 +2,13 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.web.access.AccessDeniedHandler; -import java.io.IOException; - +@Slf4j public class CustomAccessDeniedHandler implements AccessDeniedHandler { @Value("${spring.redirect.front-end-url}") @@ -15,7 +16,8 @@ public class CustomAccessDeniedHandler implements AccessDeniedHandler { @Override public void handle(HttpServletRequest request, HttpServletResponse response, - AccessDeniedException accessDeniedException) throws IOException { + AccessDeniedException accessDeniedException) throws IOException { + log.info("Access denied"); response.sendRedirect(frontEndUrl); } } diff --git a/src/main/java/team7/inplace/security/handler/CustomFailureHandler.java b/src/main/java/team7/inplace/security/handler/CustomFailureHandler.java index 1ba24dc0..e5deb740 100644 --- a/src/main/java/team7/inplace/security/handler/CustomFailureHandler.java +++ b/src/main/java/team7/inplace/security/handler/CustomFailureHandler.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; @@ -13,8 +14,6 @@ import team7.inplace.global.exception.InplaceException; import team7.inplace.global.exception.code.AuthorizationErrorCode; -import java.io.IOException; - @Slf4j public class CustomFailureHandler implements AuthenticationFailureHandler { @@ -28,10 +27,11 @@ public CustomFailureHandler(ObjectMapper objectMapper) { @Override public void onAuthenticationFailure( - HttpServletRequest request, - HttpServletResponse response, - AuthenticationException exception + HttpServletRequest request, + HttpServletResponse response, + AuthenticationException exception ) throws IOException { + log.info("Authentication failure"); String accept = request.getHeader("Accept"); if (StringUtils.hasText(accept) && accept.contains("text/html")) { response.sendRedirect(frontEndUrl); @@ -40,13 +40,13 @@ public void onAuthenticationFailure( } private void setErrorResponse( - HttpServletResponse response, - InplaceException inplaceException + HttpServletResponse response, + InplaceException inplaceException ) throws IOException { response.setStatus(inplaceException.getHttpStatus().value()); response.setContentType(MediaType.APPLICATION_JSON_VALUE); ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail( - inplaceException.getHttpStatus(), inplaceException.getMessage()); + inplaceException.getHttpStatus(), inplaceException.getMessage()); response.getWriter().write(objectMapper.writeValueAsString(problemDetail)); } }