Skip to content

Commit 24b7287

Browse files
kwondh5217sjohnr
authored andcommitted
Replace dynamic error message with static "Access Denied"
Closes gh-16514 Signed-off-by: Daeho Kwon <trewq231@naver.com>
1 parent 555fe1f commit 24b7287

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

web/src/main/java/org/springframework/security/web/server/authorization/HttpStatusServerAccessDeniedHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,7 +54,7 @@ public Mono<Void> handle(ServerWebExchange exchange, AccessDeniedException ex) {
5454
response.setStatusCode(this.httpStatus);
5555
response.getHeaders().setContentType(MediaType.TEXT_PLAIN);
5656
DataBufferFactory dataBufferFactory = response.bufferFactory();
57-
DataBuffer buffer = dataBufferFactory.wrap(ex.getMessage().getBytes(Charset.defaultCharset()));
57+
DataBuffer buffer = dataBufferFactory.wrap("Access Denied".getBytes(Charset.defaultCharset()));
5858
return response.writeWith(Mono.just(buffer)).doOnError((error) -> DataBufferUtils.release(buffer));
5959
});
6060
}

web/src/test/java/org/springframework/security/web/server/authorization/HttpStatusServerAccessDeniedHandlerTests.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,9 +23,9 @@
2323

2424
import org.springframework.http.HttpStatus;
2525
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
26+
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
2627
import org.springframework.mock.web.server.MockServerWebExchange;
2728
import org.springframework.security.access.AccessDeniedException;
28-
import org.springframework.web.server.ServerWebExchange;
2929

3030
import static org.assertj.core.api.Assertions.assertThat;
3131
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -39,7 +39,7 @@
3939
public class HttpStatusServerAccessDeniedHandlerTests {
4040

4141
@Mock
42-
private ServerWebExchange exchange;
42+
private MockServerWebExchange exchange;
4343

4444
private HttpStatus httpStatus = HttpStatus.FORBIDDEN;
4545

@@ -62,7 +62,9 @@ public void commenceWhenNoSubscribersThenNoActions() {
6262
public void commenceWhenSubscribeThenStatusSet() {
6363
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
6464
this.handler.handle(this.exchange, this.exception).block();
65-
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(this.httpStatus);
65+
MockServerHttpResponse response = this.exchange.getResponse();
66+
assertThat(response.getStatusCode()).isEqualTo(this.httpStatus);
67+
assertThat(response.getBodyAsString().block()).isEqualTo("Access Denied");
6668
}
6769

6870
@Test
@@ -71,7 +73,9 @@ public void commenceWhenCustomStatusSubscribeThenStatusSet() {
7173
this.handler = new HttpStatusServerAccessDeniedHandler(this.httpStatus);
7274
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
7375
this.handler.handle(this.exchange, this.exception).block();
74-
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(this.httpStatus);
76+
MockServerHttpResponse response = this.exchange.getResponse();
77+
assertThat(response.getStatusCode()).isEqualTo(this.httpStatus);
78+
assertThat(response.getBodyAsString().block()).isEqualTo("Access Denied");
7579
}
7680

7781
}

0 commit comments

Comments
 (0)