From 9e82fc0b8329654c8955fe3fa0ab190991b2165d Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Tue, 14 Nov 2017 15:12:19 -0600 Subject: [PATCH] serverAuthenticationEntryPoint->authenticationEntryPoint Issue: gh-4822 --- .../config/web/server/ServerHttpSecurity.java | 35 ++++++++++--------- ...uthenticationEntryPointFailureHandler.java | 10 +++--- .../ExceptionTranslationWebFilter.java | 14 ++++---- ...ticationEntryPointFailureHandlerTests.java | 8 ++--- .../ExceptionTranslationWebFilterTests.java | 4 +-- 5 files changed, 36 insertions(+), 35 deletions(-) diff --git a/config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java b/config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java index 97b5e72840..3fbd794f4b 100644 --- a/config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java +++ b/config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java @@ -115,7 +115,7 @@ public class ServerHttpSecurity { private ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository(); - private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint; + private ServerAuthenticationEntryPoint authenticationEntryPoint; private List defaultEntryPoints = new ArrayList<>(); @@ -239,7 +239,7 @@ public class ServerHttpSecurity { if(this.securityContextRepository != null) { this.formLogin.securityContextRepository(this.securityContextRepository); } - if(this.formLogin.serverAuthenticationEntryPoint == null) { + if(this.formLogin.authenticationEntryPoint == null) { this.webFilters.add(new OrderedWebFilter(new LoginPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGIN_PAGE_GENERATING.getOrder())); this.webFilters.add(new OrderedWebFilter(new LogoutPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGOUT_PAGE_GENERATING.getOrder())); } @@ -251,11 +251,11 @@ public class ServerHttpSecurity { this.requestCache.configure(this); this.addFilterAt(new SecurityContextServerWebExchangeWebFilter(), SecurityWebFiltersOrder.SECURITY_CONTEXT_SERVER_WEB_EXCHANGE); if(this.authorizeExchange != null) { - ServerAuthenticationEntryPoint serverAuthenticationEntryPoint = getServerAuthenticationEntryPoint(); + ServerAuthenticationEntryPoint authenticationEntryPoint = getAuthenticationEntryPoint(); ExceptionTranslationWebFilter exceptionTranslationWebFilter = new ExceptionTranslationWebFilter(); - if(serverAuthenticationEntryPoint != null) { - exceptionTranslationWebFilter.setServerAuthenticationEntryPoint( - serverAuthenticationEntryPoint); + if(authenticationEntryPoint != null) { + exceptionTranslationWebFilter.setAuthenticationEntryPoint( + authenticationEntryPoint); } this.addFilterAt(exceptionTranslationWebFilter, SecurityWebFiltersOrder.EXCEPTION_TRANSLATION); this.authorizeExchange.configure(this); @@ -286,9 +286,9 @@ public class ServerHttpSecurity { } } - private ServerAuthenticationEntryPoint getServerAuthenticationEntryPoint() { - if(this.serverAuthenticationEntryPoint != null || this.defaultEntryPoints.isEmpty()) { - return this.serverAuthenticationEntryPoint; + private ServerAuthenticationEntryPoint getAuthenticationEntryPoint() { + if(this.authenticationEntryPoint != null || this.defaultEntryPoints.isEmpty()) { + return this.authenticationEntryPoint; } if(this.defaultEntryPoints.size() == 1) { return this.defaultEntryPoints.get(0).getEntryPoint(); @@ -432,8 +432,9 @@ public class ServerHttpSecurity { * @since 5.0 */ public class ExceptionHandlingSpec { - public ExceptionHandlingSpec serverAuthenticationEntryPoint(ServerAuthenticationEntryPoint authenticationEntryPoint) { - ServerHttpSecurity.this.serverAuthenticationEntryPoint = authenticationEntryPoint; + + public ExceptionHandlingSpec authenticationEntryPoint(ServerAuthenticationEntryPoint authenticationEntryPoint) { + ServerHttpSecurity.this.authenticationEntryPoint = authenticationEntryPoint; return this; } @@ -537,7 +538,7 @@ public class ServerHttpSecurity { private ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository(); - private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint; + private ServerAuthenticationEntryPoint authenticationEntryPoint; private ServerWebExchangeMatcher requiresAuthenticationMatcher; @@ -559,14 +560,14 @@ public class ServerHttpSecurity { public FormLoginSpec loginPage(String loginPage) { this.defaultEntryPoint = new RedirectServerAuthenticationEntryPoint(loginPage); - this.serverAuthenticationEntryPoint = this.defaultEntryPoint; + this.authenticationEntryPoint = this.defaultEntryPoint; this.requiresAuthenticationMatcher = ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, loginPage); this.authenticationFailureHandler = new RedirectServerAuthenticationFailureHandler(loginPage + "?error"); return this; } - public FormLoginSpec authenticationEntryPoint(ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) { - this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint; + public FormLoginSpec authenticationEntryPoint(ServerAuthenticationEntryPoint authenticationEntryPoint) { + this.authenticationEntryPoint = authenticationEntryPoint; return this; } @@ -595,7 +596,7 @@ public class ServerHttpSecurity { } protected void configure(ServerHttpSecurity http) { - if(this.serverAuthenticationEntryPoint == null) { + if(this.authenticationEntryPoint == null) { loginPage("/login"); } if(http.requestCache != null) { @@ -608,7 +609,7 @@ public class ServerHttpSecurity { MediaTypeServerWebExchangeMatcher htmlMatcher = new MediaTypeServerWebExchangeMatcher( MediaType.TEXT_HTML); htmlMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL)); - ServerHttpSecurity.this.defaultEntryPoints.add(0, new DelegateEntry(htmlMatcher, this.serverAuthenticationEntryPoint)); + ServerHttpSecurity.this.defaultEntryPoints.add(0, new DelegateEntry(htmlMatcher, this.authenticationEntryPoint)); AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter( this.authenticationManager); authenticationFilter.setRequiresAuthenticationMatcher(this.requiresAuthenticationMatcher); diff --git a/web/src/main/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandler.java b/web/src/main/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandler.java index ee7ad4f8df..1779c38f9f 100644 --- a/web/src/main/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandler.java +++ b/web/src/main/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandler.java @@ -28,18 +28,18 @@ import reactor.core.publisher.Mono; */ public class ServerAuthenticationEntryPointFailureHandler implements ServerAuthenticationFailureHandler { - private final ServerAuthenticationEntryPoint serverAuthenticationEntryPoint; + private final ServerAuthenticationEntryPoint authenticationEntryPoint; public ServerAuthenticationEntryPointFailureHandler( - ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) { - Assert.notNull(serverAuthenticationEntryPoint, "authenticationEntryPoint cannot be null"); - this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint; + ServerAuthenticationEntryPoint authenticationEntryPoint) { + Assert.notNull(authenticationEntryPoint, "authenticationEntryPoint cannot be null"); + this.authenticationEntryPoint = authenticationEntryPoint; } @Override public Mono onAuthenticationFailure(WebFilterExchange webFilterExchange, AuthenticationException exception) { - return this.serverAuthenticationEntryPoint + return this.authenticationEntryPoint .commence(webFilterExchange.getExchange(), exception); } } diff --git a/web/src/main/java/org/springframework/security/web/server/authorization/ExceptionTranslationWebFilter.java b/web/src/main/java/org/springframework/security/web/server/authorization/ExceptionTranslationWebFilter.java index 24c22de72f..a4d6592716 100644 --- a/web/src/main/java/org/springframework/security/web/server/authorization/ExceptionTranslationWebFilter.java +++ b/web/src/main/java/org/springframework/security/web/server/authorization/ExceptionTranslationWebFilter.java @@ -33,7 +33,7 @@ import org.springframework.web.server.WebFilterChain; * @since 5.0 */ public class ExceptionTranslationWebFilter implements WebFilter { - private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint = new HttpBasicServerAuthenticationEntryPoint(); + private ServerAuthenticationEntryPoint authenticationEntryPoint = new HttpBasicServerAuthenticationEntryPoint(); private ServerAccessDeniedHandler serverAccessDeniedHandler = new HttpStatusServerAccessDeniedHandler(HttpStatus.FORBIDDEN); @@ -59,17 +59,17 @@ public class ExceptionTranslationWebFilter implements WebFilter { /** * Sets the authentication entry point used when authentication is required - * @param serverAuthenticationEntryPoint the authentication entry point to use. Default is + * @param authenticationEntryPoint the authentication entry point to use. Default is * {@link HttpBasicServerAuthenticationEntryPoint} */ - public void setServerAuthenticationEntryPoint( - ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) { - Assert.notNull(serverAuthenticationEntryPoint, "authenticationEntryPoint cannot be null"); - this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint; + public void setAuthenticationEntryPoint( + ServerAuthenticationEntryPoint authenticationEntryPoint) { + Assert.notNull(authenticationEntryPoint, "authenticationEntryPoint cannot be null"); + this.authenticationEntryPoint = authenticationEntryPoint; } private Mono commenceAuthentication(ServerWebExchange exchange, AccessDeniedException denied) { - return this.serverAuthenticationEntryPoint.commence(exchange, new AuthenticationCredentialsNotFoundException("Not Authenticated", denied)) + return this.authenticationEntryPoint.commence(exchange, new AuthenticationCredentialsNotFoundException("Not Authenticated", denied)) .then(Mono.empty()); } } diff --git a/web/src/test/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandlerTests.java b/web/src/test/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandlerTests.java index 31171e0133..254cb137d3 100644 --- a/web/src/test/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandlerTests.java +++ b/web/src/test/java/org/springframework/security/web/server/authentication/ServerAuthenticationEntryPointFailureHandlerTests.java @@ -39,7 +39,7 @@ import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class ServerAuthenticationEntryPointFailureHandlerTests { @Mock - private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint; + private ServerAuthenticationEntryPoint authenticationEntryPoint; @Mock private ServerWebExchange exchange; @Mock @@ -53,15 +53,15 @@ public class ServerAuthenticationEntryPointFailureHandlerTests { @Test(expected = IllegalArgumentException.class) public void constructorWhenNullEntryPointThenException() { - this.serverAuthenticationEntryPoint = null; - new ServerAuthenticationEntryPointFailureHandler(this.serverAuthenticationEntryPoint); + this.authenticationEntryPoint = null; + new ServerAuthenticationEntryPointFailureHandler(this.authenticationEntryPoint); } @Test public void onAuthenticationFailureWhenInvokedThenDelegatesToEntryPoint() { Mono result = Mono.empty(); BadCredentialsException e = new BadCredentialsException("Failed"); - when(this.serverAuthenticationEntryPoint.commence(this.exchange, e)).thenReturn(result); + when(this.authenticationEntryPoint.commence(this.exchange, e)).thenReturn(result); assertThat(this.handler.onAuthenticationFailure(this.filterExchange, e)).isEqualTo(result); } diff --git a/web/src/test/java/org/springframework/security/web/server/authorization/ExceptionTranslationWebFilterTests.java b/web/src/test/java/org/springframework/security/web/server/authorization/ExceptionTranslationWebFilterTests.java index accc8c4f43..fbbbe28370 100644 --- a/web/src/test/java/org/springframework/security/web/server/authorization/ExceptionTranslationWebFilterTests.java +++ b/web/src/test/java/org/springframework/security/web/server/authorization/ExceptionTranslationWebFilterTests.java @@ -66,7 +66,7 @@ public class ExceptionTranslationWebFilterTests { when(this.deniedHandler.handle(any(), any())).thenReturn(this.deniedPublisher.mono()); when(this.entryPoint.commence(any(), any())).thenReturn(this.entryPointPublisher.mono()); - this.filter.setServerAuthenticationEntryPoint(this.entryPoint); + this.filter.setAuthenticationEntryPoint(this.entryPoint); this.filter.setServerAccessDeniedHandler(this.deniedHandler); } @@ -155,6 +155,6 @@ public class ExceptionTranslationWebFilterTests { @Test(expected = IllegalArgumentException.class) public void setAuthenticationEntryPointWhenNullThenException() { - this.filter.setServerAuthenticationEntryPoint(null); + this.filter.setAuthenticationEntryPoint(null); } }