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:
Rob Winch 2017-10-11 15:23:24 -05:00
parent 78d2069c46
commit 364de19048
6 changed files with 16 additions and 12 deletions

View File

@ -88,7 +88,7 @@ public class AuthenticationWebFilter implements WebFilter {
securityContext.setAuthentication(authentication);
return this.serverSecurityContextRepository.save(exchange, securityContext)
.then(this.serverAuthenticationSuccessHandler
.onAuthenticationSuccess(authentication, webFilterExchange));
.onAuthenticationSuccess(webFilterExchange, authentication));
}
public void setServerSecurityContextRepository(

View File

@ -43,7 +43,8 @@ public class RedirectServerAuthenticationSuccessHandler
}
@Override
public Mono<Void> onAuthenticationSuccess(Authentication authentication, WebFilterExchange webFilterExchange) {
public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange,
Authentication authentication) {
ServerWebExchange exchange = webFilterExchange.getExchange();
return this.serverRedirectStrategy.sendRedirect(exchange, this.location);
}

View File

@ -25,5 +25,6 @@ import reactor.core.publisher.Mono;
* @since 5.0
*/
public interface ServerAuthenticationSuccessHandler {
Mono<Void> onAuthenticationSuccess(Authentication authentication, WebFilterExchange webFilterExchange);
Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange,
Authentication authentication);
}

View File

@ -28,7 +28,8 @@ import reactor.core.publisher.Mono;
public class WebFilterChainServerAuthenticationSuccessHandler
implements ServerAuthenticationSuccessHandler {
@Override
public Mono<Void> onAuthenticationSuccess(Authentication authentication, WebFilterExchange webFilterExchange) {
public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange,
Authentication authentication) {
ServerWebExchange exchange = webFilterExchange.getExchange();
return webFilterExchange.getChain().filter(exchange);
}

View File

@ -184,7 +184,7 @@ public class AuthenticationWebFilterTests {
Mono<Authentication> authentication = Mono.just(new TestingAuthenticationToken("test", "this", "ROLE_USER"));
when(this.authenticationConverter.apply(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]));
WebTestClient client = WebTestClientBuilder
@ -198,7 +198,8 @@ public class AuthenticationWebFilterTests {
.expectStatus().isOk()
.expectBody().isEmpty();
verify(this.successHandler).onAuthenticationSuccess(eq(authentication.block()), any());
verify(this.successHandler).onAuthenticationSuccess(any(),
eq(authentication.block()));
verify(this.serverSecurityContextRepository).save(any(), any());
verifyZeroInteractions(this.failureHandler);
}

View File

@ -66,8 +66,8 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
@Test
public void successWhenNoSubscribersThenNoActions() {
this.handler.onAuthenticationSuccess(this.authentication, new WebFilterExchange(this.exchange,
this.chain));
this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange,
this.chain), this.authentication);
verifyZeroInteractions(this.exchange);
}
@ -76,8 +76,8 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
public void successWhenSubscribeThenStatusAndLocationSet() {
this.exchange = MockServerHttpRequest.get("/").toExchange();
this.handler.onAuthenticationSuccess(this.authentication, new WebFilterExchange(this.exchange,
this.chain)).block();
this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange,
this.chain), this.authentication).block();
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(
HttpStatus.FOUND);
@ -91,8 +91,8 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
this.handler.setServerRedirectStrategy(this.serverRedirectStrategy);
this.exchange = MockServerHttpRequest.get("/").toExchange();
assertThat(this.handler.onAuthenticationSuccess(this.authentication, new WebFilterExchange(this.exchange,
this.chain))).isEqualTo(result);
assertThat(this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange,
this.chain), this.authentication)).isEqualTo(result);
verify(this.serverRedirectStrategy).sendRedirect(any(), eq(this.location));
}