ServerAuthenticationSuccessHandler consistent parameter order
Previously it started with Authentication while all the other APIs started with ServerWebExchange Fixes gh-4619
This commit is contained in:
parent
78d2069c46
commit
364de19048
|
@ -88,7 +88,7 @@ public class AuthenticationWebFilter implements WebFilter {
|
||||||
securityContext.setAuthentication(authentication);
|
securityContext.setAuthentication(authentication);
|
||||||
return this.serverSecurityContextRepository.save(exchange, securityContext)
|
return this.serverSecurityContextRepository.save(exchange, securityContext)
|
||||||
.then(this.serverAuthenticationSuccessHandler
|
.then(this.serverAuthenticationSuccessHandler
|
||||||
.onAuthenticationSuccess(authentication, webFilterExchange));
|
.onAuthenticationSuccess(webFilterExchange, authentication));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServerSecurityContextRepository(
|
public void setServerSecurityContextRepository(
|
||||||
|
|
|
@ -43,7 +43,8 @@ public class RedirectServerAuthenticationSuccessHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> onAuthenticationSuccess(Authentication authentication, WebFilterExchange webFilterExchange) {
|
public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange,
|
||||||
|
Authentication authentication) {
|
||||||
ServerWebExchange exchange = webFilterExchange.getExchange();
|
ServerWebExchange exchange = webFilterExchange.getExchange();
|
||||||
return this.serverRedirectStrategy.sendRedirect(exchange, this.location);
|
return this.serverRedirectStrategy.sendRedirect(exchange, this.location);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,5 +25,6 @@ import reactor.core.publisher.Mono;
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public interface ServerAuthenticationSuccessHandler {
|
public interface ServerAuthenticationSuccessHandler {
|
||||||
Mono<Void> onAuthenticationSuccess(Authentication authentication, WebFilterExchange webFilterExchange);
|
Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange,
|
||||||
|
Authentication authentication);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ import reactor.core.publisher.Mono;
|
||||||
public class WebFilterChainServerAuthenticationSuccessHandler
|
public class WebFilterChainServerAuthenticationSuccessHandler
|
||||||
implements ServerAuthenticationSuccessHandler {
|
implements ServerAuthenticationSuccessHandler {
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> onAuthenticationSuccess(Authentication authentication, WebFilterExchange webFilterExchange) {
|
public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange,
|
||||||
|
Authentication authentication) {
|
||||||
ServerWebExchange exchange = webFilterExchange.getExchange();
|
ServerWebExchange exchange = webFilterExchange.getExchange();
|
||||||
return webFilterExchange.getChain().filter(exchange);
|
return webFilterExchange.getChain().filter(exchange);
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@ public class AuthenticationWebFilterTests {
|
||||||
Mono<Authentication> authentication = Mono.just(new TestingAuthenticationToken("test", "this", "ROLE_USER"));
|
Mono<Authentication> authentication = Mono.just(new TestingAuthenticationToken("test", "this", "ROLE_USER"));
|
||||||
when(this.authenticationConverter.apply(any())).thenReturn(authentication);
|
when(this.authenticationConverter.apply(any())).thenReturn(authentication);
|
||||||
when(this.authenticationManager.authenticate(any())).thenReturn(authentication);
|
when(this.authenticationManager.authenticate(any())).thenReturn(authentication);
|
||||||
when(this.successHandler.onAuthenticationSuccess(any(),any())).thenReturn(Mono.empty());
|
when(this.successHandler.onAuthenticationSuccess(any(), any())).thenReturn(Mono.empty());
|
||||||
when(this.serverSecurityContextRepository.save(any(),any())).thenAnswer( a -> Mono.just(a.getArguments()[0]));
|
when(this.serverSecurityContextRepository.save(any(),any())).thenAnswer( a -> Mono.just(a.getArguments()[0]));
|
||||||
|
|
||||||
WebTestClient client = WebTestClientBuilder
|
WebTestClient client = WebTestClientBuilder
|
||||||
|
@ -198,7 +198,8 @@ public class AuthenticationWebFilterTests {
|
||||||
.expectStatus().isOk()
|
.expectStatus().isOk()
|
||||||
.expectBody().isEmpty();
|
.expectBody().isEmpty();
|
||||||
|
|
||||||
verify(this.successHandler).onAuthenticationSuccess(eq(authentication.block()), any());
|
verify(this.successHandler).onAuthenticationSuccess(any(),
|
||||||
|
eq(authentication.block()));
|
||||||
verify(this.serverSecurityContextRepository).save(any(), any());
|
verify(this.serverSecurityContextRepository).save(any(), any());
|
||||||
verifyZeroInteractions(this.failureHandler);
|
verifyZeroInteractions(this.failureHandler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,8 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void successWhenNoSubscribersThenNoActions() {
|
public void successWhenNoSubscribersThenNoActions() {
|
||||||
this.handler.onAuthenticationSuccess(this.authentication, new WebFilterExchange(this.exchange,
|
this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange,
|
||||||
this.chain));
|
this.chain), this.authentication);
|
||||||
|
|
||||||
verifyZeroInteractions(this.exchange);
|
verifyZeroInteractions(this.exchange);
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,8 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
|
||||||
public void successWhenSubscribeThenStatusAndLocationSet() {
|
public void successWhenSubscribeThenStatusAndLocationSet() {
|
||||||
this.exchange = MockServerHttpRequest.get("/").toExchange();
|
this.exchange = MockServerHttpRequest.get("/").toExchange();
|
||||||
|
|
||||||
this.handler.onAuthenticationSuccess(this.authentication, new WebFilterExchange(this.exchange,
|
this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange,
|
||||||
this.chain)).block();
|
this.chain), this.authentication).block();
|
||||||
|
|
||||||
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(
|
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(
|
||||||
HttpStatus.FOUND);
|
HttpStatus.FOUND);
|
||||||
|
@ -91,8 +91,8 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
|
||||||
this.handler.setServerRedirectStrategy(this.serverRedirectStrategy);
|
this.handler.setServerRedirectStrategy(this.serverRedirectStrategy);
|
||||||
this.exchange = MockServerHttpRequest.get("/").toExchange();
|
this.exchange = MockServerHttpRequest.get("/").toExchange();
|
||||||
|
|
||||||
assertThat(this.handler.onAuthenticationSuccess(this.authentication, new WebFilterExchange(this.exchange,
|
assertThat(this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange,
|
||||||
this.chain))).isEqualTo(result);
|
this.chain), this.authentication)).isEqualTo(result);
|
||||||
verify(this.serverRedirectStrategy).sendRedirect(any(), eq(this.location));
|
verify(this.serverRedirectStrategy).sendRedirect(any(), eq(this.location));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue