Răsfoiți Sursa

ServerAuthenticationSuccessHandler consistent parameter order

Previously it started with Authentication while all the other APIs started
with ServerWebExchange

Fixes gh-4619
Rob Winch 7 ani în urmă
părinte
comite
364de19048

+ 1 - 1
webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java

@@ -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(

+ 2 - 1
webflux/src/main/java/org/springframework/security/web/server/authentication/RedirectServerAuthenticationSuccessHandler.java

@@ -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);
 	}

+ 2 - 1
webflux/src/main/java/org/springframework/security/web/server/authentication/ServerAuthenticationSuccessHandler.java

@@ -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);
 }

+ 2 - 1
webflux/src/main/java/org/springframework/security/web/server/authentication/WebFilterChainServerAuthenticationSuccessHandler.java

@@ -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);
 	}

+ 3 - 2
webflux/src/test/java/org/springframework/security/web/server/authentication/AuthenticationWebFilterTests.java

@@ -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);
 	}

+ 6 - 6
webflux/src/test/java/org/springframework/security/web/server/authentication/RedirectServerAuthenticationSuccessHandlerTests.java

@@ -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));
 	}