AuthenticationFailureHandler->ServerAuthenticationFailureHandler

Issue gh-4615
This commit is contained in:
Rob Winch
2017-10-10 15:58:20 -05:00
parent 897e7111e3
commit c9ce528206
6 changed files with 23 additions and 21 deletions

View File

@@ -49,7 +49,7 @@ public class AuthenticationWebFilter implements WebFilter {
private Function<ServerWebExchange,Mono<Authentication>> authenticationConverter = new ServerHttpBasicAuthenticationConverter();
private AuthenticationFailureHandler authenticationFailureHandler = new AuthenticationEntryPointFailureHandler(new HttpBasicServerAuthenticationEntryPoint());
private ServerAuthenticationFailureHandler serverAuthenticationFailureHandler = new ServerAuthenticationEntryPointFailureHandler(new HttpBasicServerAuthenticationEntryPoint());
private SecurityContextServerRepository securityContextServerRepository = new ServerWebExchangeAttributeSecurityContextServerRepository();
@@ -79,7 +79,8 @@ public class AuthenticationWebFilter implements WebFilter {
WebFilterExchange webFilterExchange = new WebFilterExchange(wrappedExchange, chain);
return this.authenticationManager.authenticate(token)
.flatMap(authentication -> onAuthenticationSuccess(authentication, webFilterExchange))
.onErrorResume(AuthenticationException.class, e -> this.authenticationFailureHandler.onAuthenticationFailure(webFilterExchange, e));
.onErrorResume(AuthenticationException.class, e -> this.serverAuthenticationFailureHandler
.onAuthenticationFailure(webFilterExchange, e));
}
private Mono<Void> onAuthenticationSuccess(Authentication authentication, WebFilterExchange webFilterExchange) {
@@ -105,10 +106,10 @@ public class AuthenticationWebFilter implements WebFilter {
this.authenticationConverter = authenticationConverter;
}
public void setAuthenticationFailureHandler(
AuthenticationFailureHandler authenticationFailureHandler) {
Assert.notNull(authenticationFailureHandler, "authenticationFailureHandler cannot be null");
this.authenticationFailureHandler = authenticationFailureHandler;
public void setServerAuthenticationFailureHandler(
ServerAuthenticationFailureHandler serverAuthenticationFailureHandler) {
Assert.notNull(serverAuthenticationFailureHandler, "authenticationFailureHandler cannot be null");
this.serverAuthenticationFailureHandler = serverAuthenticationFailureHandler;
}
public void setRequiresAuthenticationMatcher(

View File

@@ -26,10 +26,11 @@ import reactor.core.publisher.Mono;
* @author Rob Winch
* @since 5.0
*/
public class AuthenticationEntryPointFailureHandler implements AuthenticationFailureHandler {
public class ServerAuthenticationEntryPointFailureHandler
implements ServerAuthenticationFailureHandler {
private final ServerAuthenticationEntryPoint serverAuthenticationEntryPoint;
public AuthenticationEntryPointFailureHandler(
public ServerAuthenticationEntryPointFailureHandler(
ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) {
Assert.notNull(serverAuthenticationEntryPoint, "authenticationEntryPoint cannot be null");
this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint;

View File

@@ -26,6 +26,6 @@ import org.springframework.security.web.server.WebFilterExchange;
* @author Rob Winch
* @since 5.0
*/
public interface AuthenticationFailureHandler {
public interface ServerAuthenticationFailureHandler {
Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange, AuthenticationException exception);
}

View File

@@ -60,7 +60,7 @@ public class AuthenticationWebFilterTests {
@Mock
private ReactiveAuthenticationManager authenticationManager;
@Mock
private AuthenticationFailureHandler failureHandler;
private ServerAuthenticationFailureHandler failureHandler;
@Mock
private SecurityContextServerRepository securityContextServerRepository;
@@ -72,7 +72,7 @@ public class AuthenticationWebFilterTests {
this.filter.setServerAuthenticationSuccessHandler(this.successHandler);
this.filter.setAuthenticationConverter(this.authenticationConverter);
this.filter.setSecurityContextServerRepository(this.securityContextServerRepository);
this.filter.setAuthenticationFailureHandler(this.failureHandler);
this.filter.setServerAuthenticationFailureHandler(this.failureHandler);
}
@Test

View File

@@ -49,12 +49,12 @@ public class ServerAuthenticationEntryPointFailureHandlerTests {
private WebFilterExchange filterExchange;
@InjectMocks
private AuthenticationEntryPointFailureHandler handler;
private ServerAuthenticationEntryPointFailureHandler handler;
@Test(expected = IllegalArgumentException.class)
public void constructorWhenNullEntryPointThenException() {
this.serverAuthenticationEntryPoint = null;
new AuthenticationEntryPointFailureHandler(this.serverAuthenticationEntryPoint);
new ServerAuthenticationEntryPointFailureHandler(this.serverAuthenticationEntryPoint);
}
@Test