From c9ce5282060e785cdc581ef31d0d6139aeef39d3 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Tue, 10 Oct 2017 15:58:20 -0500 Subject: [PATCH] AuthenticationFailureHandler->ServerAuthenticationFailureHandler Issue gh-4615 --- .../security/config/web/server/HttpSecurity.java | 16 ++++++++-------- .../authentication/AuthenticationWebFilter.java | 13 +++++++------ ...rAuthenticationEntryPointFailureHandler.java} | 5 +++-- ...a => ServerAuthenticationFailureHandler.java} | 2 +- .../AuthenticationWebFilterTests.java | 4 ++-- ...henticationEntryPointFailureHandlerTests.java | 4 ++-- 6 files changed, 23 insertions(+), 21 deletions(-) rename webflux/src/main/java/org/springframework/security/web/server/authentication/{AuthenticationEntryPointFailureHandler.java => ServerAuthenticationEntryPointFailureHandler.java} (90%) rename webflux/src/main/java/org/springframework/security/web/server/authentication/{AuthenticationFailureHandler.java => ServerAuthenticationFailureHandler.java} (95%) diff --git a/config/src/main/java/org/springframework/security/config/web/server/HttpSecurity.java b/config/src/main/java/org/springframework/security/config/web/server/HttpSecurity.java index cea684db38..75100de3a6 100644 --- a/config/src/main/java/org/springframework/security/config/web/server/HttpSecurity.java +++ b/config/src/main/java/org/springframework/security/config/web/server/HttpSecurity.java @@ -30,8 +30,8 @@ import org.springframework.security.web.server.ServerFormLoginAuthenticationConv import org.springframework.security.web.server.ServerHttpBasicAuthenticationConverter; import org.springframework.security.web.server.MatcherSecurityWebFilterChain; import org.springframework.security.web.server.SecurityWebFilterChain; -import org.springframework.security.web.server.authentication.AuthenticationEntryPointFailureHandler; -import org.springframework.security.web.server.authentication.AuthenticationFailureHandler; +import org.springframework.security.web.server.authentication.ServerAuthenticationEntryPointFailureHandler; +import org.springframework.security.web.server.authentication.ServerAuthenticationFailureHandler; import org.springframework.security.web.server.authentication.AuthenticationWebFilter; import org.springframework.security.web.server.authentication.RedirectServerAuthenticationEntryPoint; import org.springframework.security.web.server.authentication.RedirectServerAuthenticationSuccessHandler; @@ -355,7 +355,7 @@ public class HttpSecurity { HttpSecurity.this.defaultEntryPoints.add(new DelegateEntry(restMatcher, this.entryPoint)); AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter( this.authenticationManager); - authenticationFilter.setAuthenticationFailureHandler(new AuthenticationEntryPointFailureHandler(this.entryPoint)); + authenticationFilter.setServerAuthenticationFailureHandler(new ServerAuthenticationEntryPointFailureHandler(this.entryPoint)); authenticationFilter.setAuthenticationConverter(new ServerHttpBasicAuthenticationConverter()); if(this.securityContextServerRepository != null) { authenticationFilter.setSecurityContextServerRepository(this.securityContextServerRepository); @@ -379,7 +379,7 @@ public class HttpSecurity { private ServerWebExchangeMatcher requiresAuthenticationMatcher; - private AuthenticationFailureHandler authenticationFailureHandler; + private ServerAuthenticationFailureHandler serverAuthenticationFailureHandler; public FormLoginBuilder authenticationManager(ReactiveAuthenticationManager authenticationManager) { this.authenticationManager = authenticationManager; @@ -389,7 +389,7 @@ public class HttpSecurity { public FormLoginBuilder loginPage(String loginPage) { this.serverAuthenticationEntryPoint = new RedirectServerAuthenticationEntryPoint(loginPage); this.requiresAuthenticationMatcher = ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, loginPage); - this.authenticationFailureHandler = new AuthenticationEntryPointFailureHandler(new RedirectServerAuthenticationEntryPoint(loginPage + "?error")); + this.serverAuthenticationFailureHandler = new ServerAuthenticationEntryPointFailureHandler(new RedirectServerAuthenticationEntryPoint(loginPage + "?error")); return this; } @@ -403,8 +403,8 @@ public class HttpSecurity { return this; } - public FormLoginBuilder authenticationFailureHandler(AuthenticationFailureHandler authenticationFailureHandler) { - this.authenticationFailureHandler = authenticationFailureHandler; + public FormLoginBuilder authenticationFailureHandler(ServerAuthenticationFailureHandler serverAuthenticationFailureHandler) { + this.serverAuthenticationFailureHandler = serverAuthenticationFailureHandler; return this; } @@ -433,7 +433,7 @@ public class HttpSecurity { AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter( this.authenticationManager); authenticationFilter.setRequiresAuthenticationMatcher(this.requiresAuthenticationMatcher); - authenticationFilter.setAuthenticationFailureHandler(this.authenticationFailureHandler); + authenticationFilter.setServerAuthenticationFailureHandler(this.serverAuthenticationFailureHandler); authenticationFilter.setAuthenticationConverter(new ServerFormLoginAuthenticationConverter()); authenticationFilter.setServerAuthenticationSuccessHandler(new RedirectServerAuthenticationSuccessHandler("/")); authenticationFilter.setSecurityContextServerRepository(this.securityContextServerRepository); diff --git a/webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java b/webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java index 87211e2d6b..f5fa337a9b 100644 --- a/webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java +++ b/webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java @@ -49,7 +49,7 @@ public class AuthenticationWebFilter implements WebFilter { private Function> 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 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( diff --git a/webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationEntryPointFailureHandler.java b/webflux/src/main/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandler.java similarity index 90% rename from webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationEntryPointFailureHandler.java rename to webflux/src/main/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandler.java index 5d5193d56e..ee7ad4f8df 100644 --- a/webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationEntryPointFailureHandler.java +++ b/webflux/src/main/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandler.java @@ -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; diff --git a/webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationFailureHandler.java b/webflux/src/main/java/org/springframework/security/web/server/authentication/ServerAuthenticationFailureHandler.java similarity index 95% rename from webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationFailureHandler.java rename to webflux/src/main/java/org/springframework/security/web/server/authentication/ServerAuthenticationFailureHandler.java index 09a0174a73..5f7ca0aef2 100644 --- a/webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationFailureHandler.java +++ b/webflux/src/main/java/org/springframework/security/web/server/authentication/ServerAuthenticationFailureHandler.java @@ -26,6 +26,6 @@ import org.springframework.security.web.server.WebFilterExchange; * @author Rob Winch * @since 5.0 */ -public interface AuthenticationFailureHandler { +public interface ServerAuthenticationFailureHandler { Mono onAuthenticationFailure(WebFilterExchange webFilterExchange, AuthenticationException exception); } diff --git a/webflux/src/test/java/org/springframework/security/web/server/authentication/AuthenticationWebFilterTests.java b/webflux/src/test/java/org/springframework/security/web/server/authentication/AuthenticationWebFilterTests.java index bfbad2ec64..50017993fc 100644 --- a/webflux/src/test/java/org/springframework/security/web/server/authentication/AuthenticationWebFilterTests.java +++ b/webflux/src/test/java/org/springframework/security/web/server/authentication/AuthenticationWebFilterTests.java @@ -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 diff --git a/webflux/src/test/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandlerTests.java b/webflux/src/test/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandlerTests.java index 867b7d838f..31171e0133 100644 --- a/webflux/src/test/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandlerTests.java +++ b/webflux/src/test/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandlerTests.java @@ -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