Skip to content

Commit 22472f2

Browse files
committed
Add HttpStatusAccessDeniedHandler
1 parent 174f17e commit 22472f2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.springframework.security.web.access;
2+
3+
import jakarta.servlet.ServletException;
4+
import jakarta.servlet.http.HttpServletRequest;
5+
import jakarta.servlet.http.HttpServletResponse;
6+
import org.springframework.http.HttpStatus;
7+
import org.springframework.security.access.AccessDeniedException;
8+
import org.springframework.util.Assert;
9+
10+
import java.io.IOException;
11+
12+
public class HttpStatusAccessDeniedHandler implements AccessDeniedHandler {
13+
private final HttpStatus httpStatus;
14+
15+
public HttpStatusAccessDeniedHandler(HttpStatus httpStatus) {
16+
Assert.notNull(httpStatus, "httpStatus cannot be null");
17+
this.httpStatus = httpStatus;
18+
}
19+
20+
@Override
21+
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
22+
response.sendError(this.httpStatus.value(), accessDeniedException.getMessage());
23+
}
24+
}

0 commit comments

Comments
 (0)