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+
117package org .springframework .security .web .access ;
218
19+ import java .io .IOException ;
20+
321import jakarta .servlet .ServletException ;
422import jakarta .servlet .http .HttpServletRequest ;
523import jakarta .servlet .http .HttpServletResponse ;
624import org .apache .commons .logging .Log ;
725import org .apache .commons .logging .LogFactory ;
26+
827import org .springframework .core .log .LogMessage ;
928import org .springframework .http .HttpStatus ;
1029import org .springframework .security .access .AccessDeniedException ;
1130import org .springframework .util .Assert ;
1231
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 {
1639
17- protected static final Log logger = LogFactory .getLog (HttpStatusAccessDeniedHandler .class );
40+ private static final Log logger = LogFactory .getLog (HttpStatusAccessDeniedHandler .class );
1841
1942 private final HttpStatus httpStatus ;
2043
44+ /**
45+ * Creates a new instance.
46+ * @param httpStatus the HttpStatus to set
47+ */
2148 public HttpStatusAccessDeniedHandler (HttpStatus httpStatus ) {
2249 Assert .notNull (httpStatus , "httpStatus cannot be null" );
2350 this .httpStatus = httpStatus ;
@@ -28,7 +55,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response,
2855 AccessDeniedException accessDeniedException ) throws IOException , ServletException {
2956 logger .debug (LogMessage .format ("Access denied with status code %d" , this .httpStatus .value ()));
3057
31- response .sendError (this .httpStatus .value (), "Access Denied" );
58+ response .sendError (this .httpStatus .value (), "Access Denied" );
3259 }
3360
3461}
0 commit comments