mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-02-24 07:37:50 +00:00
HttpStatusServerAccessDeniedHandler use injected HttpStatus
Fixes: gh-5078
This commit is contained in:
parent
ca93b34f56
commit
9f23212e43
@ -46,7 +46,7 @@ public class HttpStatusServerAccessDeniedHandler implements ServerAccessDeniedHa
|
||||
public Mono<Void> handle(ServerWebExchange exchange, AccessDeniedException e) {
|
||||
return Mono.defer(() -> Mono.just(exchange.getResponse()))
|
||||
.flatMap(response -> {
|
||||
response.setStatusCode(HttpStatus.FORBIDDEN);
|
||||
response.setStatusCode(this.httpStatus);
|
||||
response.getHeaders().setContentType(MediaType.TEXT_PLAIN);
|
||||
DataBufferFactory dataBufferFactory = response.bufferFactory();
|
||||
DataBuffer buffer = dataBufferFactory.wrap(e.getMessage().getBytes(
|
||||
|
@ -38,7 +38,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
public class HttpStatusServerAccessDeniedHandlerTests {
|
||||
@Mock
|
||||
private ServerWebExchange exchange;
|
||||
private final HttpStatus httpStatus = HttpStatus.FORBIDDEN;
|
||||
private HttpStatus httpStatus = HttpStatus.FORBIDDEN;
|
||||
private HttpStatusServerAccessDeniedHandler handler = new HttpStatusServerAccessDeniedHandler(this.httpStatus);
|
||||
|
||||
private AccessDeniedException exception = new AccessDeniedException("Forbidden");
|
||||
@ -63,4 +63,15 @@ public class HttpStatusServerAccessDeniedHandlerTests {
|
||||
|
||||
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(this.httpStatus);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commenceWhenCustomStatusSubscribeThenStatusSet() {
|
||||
this.httpStatus = HttpStatus.NOT_FOUND;
|
||||
this.handler = new HttpStatusServerAccessDeniedHandler(this.httpStatus);
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
|
||||
this.handler.handle(this.exchange, this.exception).block();
|
||||
|
||||
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(this.httpStatus);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user