BearerTokenServerAuthenticationEntryPoint waits for subscriber
Fixes: gh-5742
This commit is contained in:
parent
362c2ef1f2
commit
713e1e3356
|
@ -58,14 +58,16 @@ public final class BearerTokenServerAuthenticationEntryPoint implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException authException) {
|
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException authException) {
|
||||||
HttpStatus status = getStatus(authException);
|
return Mono.defer(() -> {
|
||||||
|
HttpStatus status = getStatus(authException);
|
||||||
|
|
||||||
Map<String, String> parameters = createParameters(authException);
|
Map<String, String> parameters = createParameters(authException);
|
||||||
String wwwAuthenticate = computeWWWAuthenticateHeaderValue(parameters);
|
String wwwAuthenticate = computeWWWAuthenticateHeaderValue(parameters);
|
||||||
ServerHttpResponse response = exchange.getResponse();
|
ServerHttpResponse response = exchange.getResponse();
|
||||||
response.getHeaders().set(HttpHeaders.WWW_AUTHENTICATE, wwwAuthenticate);
|
response.getHeaders().set(HttpHeaders.WWW_AUTHENTICATE, wwwAuthenticate);
|
||||||
response.setStatusCode(status);
|
response.setStatusCode(status);
|
||||||
return response.setComplete();
|
return response.setComplete();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> createParameters(AuthenticationException authException) {
|
private Map<String, String> createParameters(AuthenticationException authException) {
|
||||||
|
|
|
@ -91,6 +91,14 @@ public class BearerTokenServerAuthenticationEntryPointTests {
|
||||||
assertThat(getResponse().getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
assertThat(getResponse().getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void commenceWhenNoSubscriberThenNothingHappens() {
|
||||||
|
this.entryPoint.commence(this.exchange, new BadCredentialsException(""));
|
||||||
|
|
||||||
|
assertThat(getResponse().getHeaders()).isEmpty();
|
||||||
|
assertThat(getResponse().getStatusCode()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
private MockServerHttpResponse getResponse() {
|
private MockServerHttpResponse getResponse() {
|
||||||
return this.exchange.getResponse();
|
return this.exchange.getResponse();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue