diff --git a/webflux/src/main/java/org/springframework/security/web/server/DefaultRedirectStrategy.java b/webflux/src/main/java/org/springframework/security/web/server/DefaultServerRedirectStrategy.java similarity index 96% rename from webflux/src/main/java/org/springframework/security/web/server/DefaultRedirectStrategy.java rename to webflux/src/main/java/org/springframework/security/web/server/DefaultServerRedirectStrategy.java index a4d0b31f34..4d78bd03ff 100644 --- a/webflux/src/main/java/org/springframework/security/web/server/DefaultRedirectStrategy.java +++ b/webflux/src/main/java/org/springframework/security/web/server/DefaultServerRedirectStrategy.java @@ -28,7 +28,7 @@ import java.net.URI; * @author Rob Winch * @since 5.0 */ -public class DefaultRedirectStrategy implements RedirectStrategy { +public class DefaultServerRedirectStrategy implements ServerRedirectStrategy { private HttpStatus httpStatus = HttpStatus.FOUND; private boolean contextRelative = true; diff --git a/webflux/src/main/java/org/springframework/security/web/server/RedirectStrategy.java b/webflux/src/main/java/org/springframework/security/web/server/ServerRedirectStrategy.java similarity index 95% rename from webflux/src/main/java/org/springframework/security/web/server/RedirectStrategy.java rename to webflux/src/main/java/org/springframework/security/web/server/ServerRedirectStrategy.java index 6bb6385a84..912d9a95ad 100644 --- a/webflux/src/main/java/org/springframework/security/web/server/RedirectStrategy.java +++ b/webflux/src/main/java/org/springframework/security/web/server/ServerRedirectStrategy.java @@ -26,7 +26,7 @@ import org.springframework.web.server.ServerWebExchange; * @author Rob Winch * @since 5.0 */ -public interface RedirectStrategy { +public interface ServerRedirectStrategy { Mono sendRedirect(ServerWebExchange exchange, URI location); } diff --git a/webflux/src/main/java/org/springframework/security/web/server/authentication/RedirectAuthenticationEntryPoint.java b/webflux/src/main/java/org/springframework/security/web/server/authentication/RedirectAuthenticationEntryPoint.java index 34e7d3cf80..52d786c517 100644 --- a/webflux/src/main/java/org/springframework/security/web/server/authentication/RedirectAuthenticationEntryPoint.java +++ b/webflux/src/main/java/org/springframework/security/web/server/authentication/RedirectAuthenticationEntryPoint.java @@ -18,12 +18,10 @@ package org.springframework.security.web.server.authentication; import java.net.URI; -import org.springframework.security.web.server.DefaultRedirectStrategy; -import org.springframework.security.web.server.RedirectStrategy; +import org.springframework.security.web.server.DefaultServerRedirectStrategy; +import org.springframework.security.web.server.ServerRedirectStrategy; import reactor.core.publisher.Mono; -import org.springframework.http.HttpStatus; -import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.server.AuthenticationEntryPoint; import org.springframework.util.Assert; @@ -38,7 +36,7 @@ import org.springframework.web.server.ServerWebExchange; public class RedirectAuthenticationEntryPoint implements AuthenticationEntryPoint { private final URI location; - private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); + private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy(); public RedirectAuthenticationEntryPoint(String location) { Assert.notNull(location, "location cannot be null"); @@ -47,15 +45,15 @@ public class RedirectAuthenticationEntryPoint implements AuthenticationEntryPoin @Override public Mono commence(ServerWebExchange exchange, AuthenticationException e) { - return this.redirectStrategy.sendRedirect(exchange, this.location); + return this.serverRedirectStrategy.sendRedirect(exchange, this.location); } /** * Sets the RedirectStrategy to use. - * @param redirectStrategy the strategy to use. Default is DefaultRedirectStrategy. + * @param serverRedirectStrategy the strategy to use. Default is DefaultRedirectStrategy. */ - public void setRedirectStrategy(RedirectStrategy redirectStrategy) { - Assert.notNull(redirectStrategy, "redirectStrategy cannot be null"); - this.redirectStrategy = redirectStrategy; + public void setServerRedirectStrategy(ServerRedirectStrategy serverRedirectStrategy) { + Assert.notNull(serverRedirectStrategy, "redirectStrategy cannot be null"); + this.serverRedirectStrategy = serverRedirectStrategy; } } diff --git a/webflux/src/main/java/org/springframework/security/web/server/authentication/RedirectAuthenticationSuccessHandler.java b/webflux/src/main/java/org/springframework/security/web/server/authentication/RedirectAuthenticationSuccessHandler.java index e754f75566..9de4c74954 100644 --- a/webflux/src/main/java/org/springframework/security/web/server/authentication/RedirectAuthenticationSuccessHandler.java +++ b/webflux/src/main/java/org/springframework/security/web/server/authentication/RedirectAuthenticationSuccessHandler.java @@ -17,12 +17,11 @@ package org.springframework.security.web.server.authentication; import org.springframework.security.core.Authentication; -import org.springframework.security.web.server.DefaultRedirectStrategy; -import org.springframework.security.web.server.RedirectStrategy; +import org.springframework.security.web.server.DefaultServerRedirectStrategy; +import org.springframework.security.web.server.ServerRedirectStrategy; import org.springframework.security.web.server.WebFilterExchange; import org.springframework.util.Assert; import org.springframework.web.server.ServerWebExchange; -import org.springframework.web.server.WebFilterChain; import reactor.core.publisher.Mono; import java.net.URI; @@ -34,7 +33,7 @@ import java.net.URI; public class RedirectAuthenticationSuccessHandler implements AuthenticationSuccessHandler { private URI location = URI.create("/"); - private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); + private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy(); public RedirectAuthenticationSuccessHandler() {} @@ -45,7 +44,7 @@ public class RedirectAuthenticationSuccessHandler implements AuthenticationSucce @Override public Mono success(Authentication authentication, WebFilterExchange webFilterExchange) { ServerWebExchange exchange = webFilterExchange.getExchange(); - return this.redirectStrategy.sendRedirect(exchange, this.location); + return this.serverRedirectStrategy.sendRedirect(exchange, this.location); } /** @@ -59,10 +58,10 @@ public class RedirectAuthenticationSuccessHandler implements AuthenticationSucce /** * The RedirectStrategy to use. - * @param redirectStrategy the strategy to use. Default is DefaultRedirectStrategy. + * @param serverRedirectStrategy the strategy to use. Default is DefaultRedirectStrategy. */ - public void setRedirectStrategy(RedirectStrategy redirectStrategy) { - Assert.notNull(redirectStrategy, "redirectStrategy cannot be null"); - this.redirectStrategy = redirectStrategy; + public void setServerRedirectStrategy(ServerRedirectStrategy serverRedirectStrategy) { + Assert.notNull(serverRedirectStrategy, "redirectStrategy cannot be null"); + this.serverRedirectStrategy = serverRedirectStrategy; } } diff --git a/webflux/src/main/java/org/springframework/security/web/server/authentication/logout/SecurityContextRepositoryLogoutHandler.java b/webflux/src/main/java/org/springframework/security/web/server/authentication/logout/SecurityContextRepositoryLogoutHandler.java index a64e4c4a30..71104f172a 100644 --- a/webflux/src/main/java/org/springframework/security/web/server/authentication/logout/SecurityContextRepositoryLogoutHandler.java +++ b/webflux/src/main/java/org/springframework/security/web/server/authentication/logout/SecurityContextRepositoryLogoutHandler.java @@ -17,8 +17,8 @@ package org.springframework.security.web.server.authentication.logout; import org.springframework.security.core.Authentication; -import org.springframework.security.web.server.DefaultRedirectStrategy; -import org.springframework.security.web.server.RedirectStrategy; +import org.springframework.security.web.server.DefaultServerRedirectStrategy; +import org.springframework.security.web.server.ServerRedirectStrategy; import org.springframework.security.web.server.context.SecurityContextRepository; import org.springframework.security.web.server.WebFilterExchange; import org.springframework.security.web.server.context.WebSessionSecurityContextRepository; @@ -35,12 +35,12 @@ public class SecurityContextRepositoryLogoutHandler implements LogoutHandler { private URI logoutSuccessUrl = URI.create("/login?logout"); - private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); + private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy(); @Override public Mono logout(WebFilterExchange exchange, Authentication authentication) { return this.repository.save(exchange.getExchange(), null) - .then(this.redirectStrategy.sendRedirect(exchange.getExchange(), this.logoutSuccessUrl)); + .then(this.serverRedirectStrategy.sendRedirect(exchange.getExchange(), this.logoutSuccessUrl)); } } diff --git a/webflux/src/test/java/org/springframework/security/web/server/DefaultRedirectStrategyTests.java b/webflux/src/test/java/org/springframework/security/web/server/DefaultServerRedirectStrategyTests.java similarity index 95% rename from webflux/src/test/java/org/springframework/security/web/server/DefaultRedirectStrategyTests.java rename to webflux/src/test/java/org/springframework/security/web/server/DefaultServerRedirectStrategyTests.java index e29870bb37..2b91da38b6 100644 --- a/webflux/src/test/java/org/springframework/security/web/server/DefaultRedirectStrategyTests.java +++ b/webflux/src/test/java/org/springframework/security/web/server/DefaultServerRedirectStrategyTests.java @@ -24,7 +24,6 @@ import org.springframework.http.HttpStatus; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; import org.springframework.security.core.AuthenticationException; -import org.springframework.security.web.server.authentication.RedirectAuthenticationEntryPoint; import org.springframework.web.server.ServerWebExchange; import java.net.URI; @@ -37,15 +36,15 @@ import static org.mockito.Mockito.verifyZeroInteractions; * @since 5.0 */ @RunWith(MockitoJUnitRunner.class) -public class DefaultRedirectStrategyTests { +public class DefaultServerRedirectStrategyTests { @Mock private ServerWebExchange exchange; private URI location = URI.create("/login"); - private DefaultRedirectStrategy strategy = - new DefaultRedirectStrategy(); + private DefaultServerRedirectStrategy strategy = + new DefaultServerRedirectStrategy(); private AuthenticationException exception = new AuthenticationCredentialsNotFoundException("Authentication Required"); diff --git a/webflux/src/test/java/org/springframework/security/web/server/authentication/RedirectAuthenticationEntryPointTests.java b/webflux/src/test/java/org/springframework/security/web/server/authentication/RedirectAuthenticationEntryPointTests.java index 3eed25613d..7888f319e8 100644 --- a/webflux/src/test/java/org/springframework/security/web/server/authentication/RedirectAuthenticationEntryPointTests.java +++ b/webflux/src/test/java/org/springframework/security/web/server/authentication/RedirectAuthenticationEntryPointTests.java @@ -25,7 +25,7 @@ import org.springframework.http.HttpStatus; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; import org.springframework.security.core.AuthenticationException; -import org.springframework.security.web.server.RedirectStrategy; +import org.springframework.security.web.server.ServerRedirectStrategy; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; @@ -44,7 +44,7 @@ public class RedirectAuthenticationEntryPointTests { @Mock private ServerWebExchange exchange; @Mock - private RedirectStrategy redirectStrategy; + private ServerRedirectStrategy serverRedirectStrategy; private String location = "/login"; @@ -81,9 +81,9 @@ public class RedirectAuthenticationEntryPointTests { @Test public void commenceWhenCustomStatusThenStatusSet() { Mono result = Mono.empty(); - when(this.redirectStrategy.sendRedirect(any(), any())).thenReturn(result); + when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(result); HttpStatus status = HttpStatus.MOVED_PERMANENTLY; - this.entryPoint.setRedirectStrategy(this.redirectStrategy); + this.entryPoint.setServerRedirectStrategy(this.serverRedirectStrategy); this.exchange = MockServerHttpRequest.get("/").toExchange(); assertThat(this.entryPoint.commence(this.exchange, this.exception)).isEqualTo(result); @@ -91,6 +91,6 @@ public class RedirectAuthenticationEntryPointTests { @Test(expected = IllegalArgumentException.class) public void setRedirectStrategyWhenNullThenException() { - this.entryPoint.setRedirectStrategy(null); + this.entryPoint.setServerRedirectStrategy(null); } } diff --git a/webflux/src/test/java/org/springframework/security/web/server/authentication/RedirectAuthenticationSuccessHandlerTests.java b/webflux/src/test/java/org/springframework/security/web/server/authentication/RedirectAuthenticationSuccessHandlerTests.java index 3f613b4ec4..2fafb706ef 100644 --- a/webflux/src/test/java/org/springframework/security/web/server/authentication/RedirectAuthenticationSuccessHandlerTests.java +++ b/webflux/src/test/java/org/springframework/security/web/server/authentication/RedirectAuthenticationSuccessHandlerTests.java @@ -22,10 +22,8 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.springframework.http.HttpStatus; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; -import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; import org.springframework.security.core.Authentication; -import org.springframework.security.core.AuthenticationException; -import org.springframework.security.web.server.RedirectStrategy; +import org.springframework.security.web.server.ServerRedirectStrategy; import org.springframework.security.web.server.WebFilterExchange; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilterChain; @@ -34,7 +32,6 @@ import reactor.core.publisher.Mono; import java.net.URI; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; @@ -53,7 +50,7 @@ public class RedirectAuthenticationSuccessHandlerTests { @Mock private WebFilterChain chain; @Mock - private RedirectStrategy redirectStrategy; + private ServerRedirectStrategy serverRedirectStrategy; @Mock private Authentication authentication; @@ -90,18 +87,18 @@ public class RedirectAuthenticationSuccessHandlerTests { @Test public void successWhenCustomLocationThenCustomLocationUsed() { Mono result = Mono.empty(); - when(this.redirectStrategy.sendRedirect(any(), any())).thenReturn(result); - this.handler.setRedirectStrategy(this.redirectStrategy); + when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(result); + this.handler.setServerRedirectStrategy(this.serverRedirectStrategy); this.exchange = MockServerHttpRequest.get("/").toExchange(); assertThat(this.handler.success(this.authentication, new WebFilterExchange(this.exchange, this.chain))).isEqualTo(result); - verify(this.redirectStrategy).sendRedirect(any(), eq(this.location)); + verify(this.serverRedirectStrategy).sendRedirect(any(), eq(this.location)); } @Test(expected = IllegalArgumentException.class) public void setRedirectStrategyWhenNullThenException() { - this.handler.setRedirectStrategy(null); + this.handler.setServerRedirectStrategy(null); } @Test(expected = IllegalArgumentException.class)