Skip to content

Commit 2dee621

Browse files
Create NoOpAccessDeniedHandler
Closes gh-13109
1 parent e35faa8 commit 2dee621

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2002-2023 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+
17+
package org.springframework.security.web.access;
18+
19+
import java.io.IOException;
20+
21+
import jakarta.servlet.ServletException;
22+
import jakarta.servlet.http.HttpServletRequest;
23+
import jakarta.servlet.http.HttpServletResponse;
24+
25+
import org.springframework.security.access.AccessDeniedException;
26+
27+
/**
28+
* An {@link AccessDeniedHandler} implementation that does nothing.
29+
*
30+
* @author Marcus da Coregio
31+
* @since 6.2
32+
*/
33+
public class NoOpAccessDeniedHandler implements AccessDeniedHandler {
34+
35+
@Override
36+
public void handle(HttpServletRequest request, HttpServletResponse response,
37+
AccessDeniedException accessDeniedException) throws IOException, ServletException {
38+
39+
}
40+
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2002-2023 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+
17+
package org.springframework.security.web.access;
18+
19+
import jakarta.servlet.http.HttpServletRequest;
20+
import jakarta.servlet.http.HttpServletResponse;
21+
import org.junit.jupiter.api.Test;
22+
23+
import org.springframework.security.access.AccessDeniedException;
24+
25+
import static org.mockito.Mockito.mock;
26+
import static org.mockito.Mockito.verifyNoInteractions;
27+
28+
class NoOpAccessDeniedHandlerTests {
29+
30+
private final NoOpAccessDeniedHandler handler = new NoOpAccessDeniedHandler();
31+
32+
@Test
33+
void handleWhenInvokedThenDoesNothing() throws Exception {
34+
HttpServletRequest request = mock(HttpServletRequest.class);
35+
HttpServletResponse response = mock(HttpServletResponse.class);
36+
AccessDeniedException exception = mock(AccessDeniedException.class);
37+
this.handler.handle(request, response, exception);
38+
verifyNoInteractions(request, response, exception);
39+
}
40+
41+
}

0 commit comments

Comments
 (0)