Browse Source

Add DelegatingServerLogoutHandler(List<ServerLogoutHandler> delegates)

Issue: gh-4839
pull/5392/head
Rob Winch 8 years ago
parent
commit
6a12415d23
  1. 6
      web/src/main/java/org/springframework/security/web/server/authentication/logout/DelegatingServerLogoutHandler.java
  2. 12
      web/src/test/java/org/springframework/security/web/server/authentication/logout/DelegatingServerLogoutHandlerTests.java

6
web/src/main/java/org/springframework/security/web/server/authentication/logout/DelegatingServerLogoutHandler.java

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.security.web.server.authentication.logout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@ -41,6 +42,11 @@ public class DelegatingServerLogoutHandler implements ServerLogoutHandler { @@ -41,6 +42,11 @@ public class DelegatingServerLogoutHandler implements ServerLogoutHandler {
this.delegates = Arrays.asList(delegates);
}
public DelegatingServerLogoutHandler(List<ServerLogoutHandler> delegates) {
Assert.notEmpty(delegates, "delegates cannot be null or empty");
this.delegates = new ArrayList<>(delegates);
}
@Override
public Mono<Void> logout(WebFilterExchange exchange, Authentication authentication) {
Stream<Mono<Void>> results = this.delegates.stream().map(delegate -> delegate.logout(exchange, authentication));

12
web/src/test/java/org/springframework/security/web/server/authentication/logout/DelegatingServerLogoutHandlerTests.java

@ -30,6 +30,8 @@ import org.springframework.security.web.server.WebFilterExchange; @@ -30,6 +30,8 @@ import org.springframework.security.web.server.WebFilterExchange;
import reactor.test.publisher.PublisherProbe;
import java.util.List;
/**
* @author Eric Deandrea
* @since 5.1
@ -57,13 +59,21 @@ public class DelegatingServerLogoutHandlerTests { @@ -57,13 +59,21 @@ public class DelegatingServerLogoutHandlerTests {
}
@Test
public void constructorWhenNullThenIllegalArgumentException() {
public void constructorWhenNullVargsThenIllegalArgumentException() {
assertThatThrownBy(() -> new DelegatingServerLogoutHandler((ServerLogoutHandler[]) null))
.isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessage("delegates cannot be null or empty")
.hasNoCause();
}
@Test
public void constructorWhenNullListThenIllegalArgumentException() {
assertThatThrownBy(() -> new DelegatingServerLogoutHandler((List<ServerLogoutHandler>) null))
.isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessage("delegates cannot be null or empty")
.hasNoCause();
}
@Test
public void constructorWhenEmptyThenIllegalArgumentException() {
assertThatThrownBy(() -> new DelegatingServerLogoutHandler(new ServerLogoutHandler[0]))

Loading…
Cancel
Save