Include security error body in WebFlux Cloud Foundry endpoint responses

See gh-50256

Signed-off-by: htjworld <itjhan01@gmail.com>
This commit is contained in:
htjworld
2026-09-09 13:52:28 +01:00
committed by Andy Wilkinson
parent 4307353d6a
commit 0959b436de
2 changed files with 8 additions and 4 deletions
@@ -109,7 +109,7 @@ class CloudFoundryWebFluxEndpointHandlerMapping extends AbstractWebFluxEndpointH
return CloudFoundryWebFluxEndpointHandlerMapping.this.securityInterceptor.preHandle(exchange, "")
.map((securityResponse) -> {
if (!securityResponse.getStatus().equals(HttpStatus.OK)) {
return new ResponseEntity<>(securityResponse.getStatus());
return new ResponseEntity<>(securityResponse.getMessage(), securityResponse.getStatus());
}
AccessLevel accessLevel = exchange.getAttribute(AccessLevel.REQUEST_ATTRIBUTE);
String requestUri = UriComponentsBuilder.fromUri(request.getURI()).replaceQuery(null).toUriString();
@@ -164,7 +164,7 @@ class CloudFoundryWebFluxEndpointHandlerMapping extends AbstractWebFluxEndpointH
private Mono<ResponseEntity<Object>> flatMapResponse(ServerWebExchange exchange,
@Nullable Map<String, String> body, SecurityResponse securityResponse) {
if (!securityResponse.getStatus().equals(HttpStatus.OK)) {
return Mono.just(new ResponseEntity<>(securityResponse.getStatus()));
return Mono.just(new ResponseEntity<>(securityResponse.getMessage(), securityResponse.getStatus()));
}
return this.delegate.handle(exchange, body);
}
@@ -100,7 +100,9 @@ class CloudFoundryWebFluxEndpointIntegrationTests {
.header("Authorization", "bearer " + mockAccessToken())
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.FORBIDDEN)));
.isEqualTo(HttpStatus.FORBIDDEN)
.expectBody(String.class)
.isEqualTo("{\"security_error\":\"Access denied\"}")));
}
@Test
@@ -179,7 +181,9 @@ class CloudFoundryWebFluxEndpointIntegrationTests {
.header("Authorization", "bearer " + mockAccessToken())
.exchange()
.expectStatus()
.isUnauthorized()));
.isUnauthorized()
.expectBody(String.class)
.isEqualTo("{\"security_error\":\"invalid-token\"}")));
}
@Test