Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
earlgrey02 committed Jan 31, 2025
1 parent 0a49d05 commit 7fc4bcf
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.log.LogMessage;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.util.Assert;
Expand All @@ -11,6 +14,8 @@

public class HttpStatusAccessDeniedHandler implements AccessDeniedHandler {

protected static final Log logger = LogFactory.getLog(HttpStatusAccessDeniedHandler.class);

private final HttpStatus httpStatus;

public HttpStatusAccessDeniedHandler(HttpStatus httpStatus) {
Expand All @@ -21,6 +26,8 @@ public HttpStatusAccessDeniedHandler(HttpStatus httpStatus) {
@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
AccessDeniedException accessDeniedException) throws IOException, ServletException {
logger.debug(LogMessage.format("Access denied with status code %d", this.httpStatus.value()));

response.sendError(this.httpStatus.value(), "Access Denied");
}

Expand Down

0 comments on commit 7fc4bcf

Please sign in to comment.