Skip to content

Commit 531f2f4

Browse files
committed
Polish gh-16502
1 parent 97fdfb0 commit 531f2f4

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,50 @@
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+
117
package org.springframework.security.web.access;
218

19+
import java.io.IOException;
20+
321
import jakarta.servlet.ServletException;
422
import jakarta.servlet.http.HttpServletRequest;
523
import jakarta.servlet.http.HttpServletResponse;
624
import org.apache.commons.logging.Log;
725
import org.apache.commons.logging.LogFactory;
26+
827
import org.springframework.core.log.LogMessage;
928
import org.springframework.http.HttpStatus;
1029
import org.springframework.security.access.AccessDeniedException;
1130
import 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
}

web/src/test/java/org/springframework/security/web/access/HttpStatusAccessDeniedHandlerTests.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
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+
117
package org.springframework.security.web.access;
218

19+
import java.io.IOException;
20+
321
import jakarta.servlet.ServletException;
422
import jakarta.servlet.http.HttpServletRequest;
523
import jakarta.servlet.http.HttpServletResponse;
624
import org.junit.jupiter.api.Test;
725
import org.junit.jupiter.api.extension.ExtendWith;
826
import org.mockito.Mock;
927
import org.mockito.junit.jupiter.MockitoExtension;
28+
1029
import org.springframework.http.HttpStatus;
1130
import org.springframework.mock.web.MockHttpServletResponse;
1231
import org.springframework.security.access.AccessDeniedException;
1332

14-
import java.io.IOException;
15-
1633
import static org.assertj.core.api.Assertions.assertThat;
1734
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
1835

0 commit comments

Comments
 (0)