1
+ /*
2
+ * Copyright 2002-2025 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
1
17
package org .springframework .security .web .access ;
2
18
19
+ import java .io .IOException ;
20
+
3
21
import jakarta .servlet .ServletException ;
4
22
import jakarta .servlet .http .HttpServletRequest ;
5
23
import jakarta .servlet .http .HttpServletResponse ;
6
24
import org .apache .commons .logging .Log ;
7
25
import org .apache .commons .logging .LogFactory ;
26
+
8
27
import org .springframework .core .log .LogMessage ;
9
28
import org .springframework .http .HttpStatus ;
10
29
import org .springframework .security .access .AccessDeniedException ;
11
30
import org .springframework .util .Assert ;
12
31
13
- import java .io .IOException ;
14
-
15
- public class HttpStatusAccessDeniedHandler implements AccessDeniedHandler {
32
+ /**
33
+ * An {@link AccessDeniedHandler} that sends an {@link HttpStatus} as a response.
34
+ *
35
+ * @author Sangyoon Jeong
36
+ * @since 6.5
37
+ */
38
+ public final class HttpStatusAccessDeniedHandler implements AccessDeniedHandler {
16
39
17
- protected static final Log logger = LogFactory .getLog (HttpStatusAccessDeniedHandler .class );
40
+ private static final Log logger = LogFactory .getLog (HttpStatusAccessDeniedHandler .class );
18
41
19
42
private final HttpStatus httpStatus ;
20
43
44
+ /**
45
+ * Creates a new instance.
46
+ * @param httpStatus the HttpStatus to set
47
+ */
21
48
public HttpStatusAccessDeniedHandler (HttpStatus httpStatus ) {
22
49
Assert .notNull (httpStatus , "httpStatus cannot be null" );
23
50
this .httpStatus = httpStatus ;
@@ -28,7 +55,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response,
28
55
AccessDeniedException accessDeniedException ) throws IOException , ServletException {
29
56
logger .debug (LogMessage .format ("Access denied with status code %d" , this .httpStatus .value ()));
30
57
31
- response .sendError (this .httpStatus .value (), "Access Denied" );
58
+ response .sendError (this .httpStatus .value (), "Access Denied" );
32
59
}
33
60
34
61
}
0 commit comments