Merge pull request #50256 from htjworld

Closes gh-50256

* gh-50256:
  Include security error body in WebFlux Cloud Foundry endpoint responses
This commit is contained in:
Andy Wilkinson
2026-09-09 13:52:50 +01:00
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