serverRedirectStrategy->redirectStrategy

Issue: gh-4822
This commit is contained in:
Rob Winch 2017-11-14 15:24:16 -06:00
parent 2cbdb4ba02
commit 1c977ca15f
7 changed files with 33 additions and 33 deletions

View File

@ -39,7 +39,7 @@ public class RedirectServerAuthenticationEntryPoint
implements ServerAuthenticationEntryPoint { implements ServerAuthenticationEntryPoint {
private final URI location; private final URI location;
private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy(); private ServerRedirectStrategy redirectStrategy = new DefaultServerRedirectStrategy();
private ServerRequestCache requestCache = new WebSessionServerRequestCache(); private ServerRequestCache requestCache = new WebSessionServerRequestCache();
@ -56,15 +56,15 @@ public class RedirectServerAuthenticationEntryPoint
@Override @Override
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e) { public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e) {
return this.requestCache.saveRequest(exchange) return this.requestCache.saveRequest(exchange)
.then(this.serverRedirectStrategy.sendRedirect(exchange, this.location)); .then(this.redirectStrategy.sendRedirect(exchange, this.location));
} }
/** /**
* Sets the RedirectStrategy to use. * Sets the RedirectStrategy to use.
* @param serverRedirectStrategy the strategy to use. Default is DefaultRedirectStrategy. * @param redirectStrategy the strategy to use. Default is DefaultRedirectStrategy.
*/ */
public void setServerRedirectStrategy(ServerRedirectStrategy serverRedirectStrategy) { public void setRedirectStrategy(ServerRedirectStrategy redirectStrategy) {
Assert.notNull(serverRedirectStrategy, "redirectStrategy cannot be null"); Assert.notNull(redirectStrategy, "redirectStrategy cannot be null");
this.serverRedirectStrategy = serverRedirectStrategy; this.redirectStrategy = redirectStrategy;
} }
} }

View File

@ -35,7 +35,7 @@ public class RedirectServerAuthenticationFailureHandler
implements ServerAuthenticationFailureHandler { implements ServerAuthenticationFailureHandler {
private final URI location; private final URI location;
private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy(); private ServerRedirectStrategy redirectStrategy = new DefaultServerRedirectStrategy();
public RedirectServerAuthenticationFailureHandler(String location) { public RedirectServerAuthenticationFailureHandler(String location) {
Assert.notNull(location, "location cannot be null"); Assert.notNull(location, "location cannot be null");
@ -44,16 +44,16 @@ public class RedirectServerAuthenticationFailureHandler
/** /**
* Sets the RedirectStrategy to use. * Sets the RedirectStrategy to use.
* @param serverRedirectStrategy the strategy to use. Default is DefaultRedirectStrategy. * @param redirectStrategy the strategy to use. Default is DefaultRedirectStrategy.
*/ */
public void setServerRedirectStrategy(ServerRedirectStrategy serverRedirectStrategy) { public void setRedirectStrategy(ServerRedirectStrategy redirectStrategy) {
Assert.notNull(serverRedirectStrategy, "redirectStrategy cannot be null"); Assert.notNull(redirectStrategy, "redirectStrategy cannot be null");
this.serverRedirectStrategy = serverRedirectStrategy; this.redirectStrategy = redirectStrategy;
} }
@Override @Override
public Mono<Void> onAuthenticationFailure( public Mono<Void> onAuthenticationFailure(
WebFilterExchange webFilterExchange, AuthenticationException exception) { WebFilterExchange webFilterExchange, AuthenticationException exception) {
return this.serverRedirectStrategy.sendRedirect(webFilterExchange.getExchange(), this.location); return this.redirectStrategy.sendRedirect(webFilterExchange.getExchange(), this.location);
} }
} }

View File

@ -36,7 +36,7 @@ public class RedirectServerAuthenticationSuccessHandler
implements ServerAuthenticationSuccessHandler { implements ServerAuthenticationSuccessHandler {
private URI location = URI.create("/"); private URI location = URI.create("/");
private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy(); private ServerRedirectStrategy redirectStrategy = new DefaultServerRedirectStrategy();
private ServerRequestCache requestCache = new WebSessionServerRequestCache(); private ServerRequestCache requestCache = new WebSessionServerRequestCache();
@ -59,7 +59,7 @@ public class RedirectServerAuthenticationSuccessHandler
.map(r -> r.getPath().pathWithinApplication().value()) .map(r -> r.getPath().pathWithinApplication().value())
.map(URI::create) .map(URI::create)
.defaultIfEmpty(this.location) .defaultIfEmpty(this.location)
.flatMap(location -> this.serverRedirectStrategy.sendRedirect(exchange, location)); .flatMap(location -> this.redirectStrategy.sendRedirect(exchange, location));
} }
/** /**
@ -73,10 +73,10 @@ public class RedirectServerAuthenticationSuccessHandler
/** /**
* The RedirectStrategy to use. * The RedirectStrategy to use.
* @param serverRedirectStrategy the strategy to use. Default is DefaultRedirectStrategy. * @param redirectStrategy the strategy to use. Default is DefaultRedirectStrategy.
*/ */
public void setServerRedirectStrategy(ServerRedirectStrategy serverRedirectStrategy) { public void setRedirectStrategy(ServerRedirectStrategy redirectStrategy) {
Assert.notNull(serverRedirectStrategy, "redirectStrategy cannot be null"); Assert.notNull(redirectStrategy, "redirectStrategy cannot be null");
this.serverRedirectStrategy = serverRedirectStrategy; this.redirectStrategy = redirectStrategy;
} }
} }

View File

@ -34,11 +34,11 @@ public class RedirectServerLogoutSuccessHandler implements ServerLogoutSuccessHa
private URI logoutSuccessUrl = URI.create(DEFAULT_LOGOUT_SUCCESS_URL); private URI logoutSuccessUrl = URI.create(DEFAULT_LOGOUT_SUCCESS_URL);
private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy(); private ServerRedirectStrategy redirectStrategy = new DefaultServerRedirectStrategy();
@Override @Override
public Mono<Void> onLogoutSuccess(WebFilterExchange exchange, Authentication authentication) { public Mono<Void> onLogoutSuccess(WebFilterExchange exchange, Authentication authentication) {
return this.serverRedirectStrategy return this.redirectStrategy
.sendRedirect(exchange.getExchange(), this.logoutSuccessUrl); .sendRedirect(exchange.getExchange(), this.logoutSuccessUrl);
} }

View File

@ -44,7 +44,7 @@ public class RedirectServerAuthenticationEntryPointTests {
@Mock @Mock
private ServerWebExchange exchange; private ServerWebExchange exchange;
@Mock @Mock
private ServerRedirectStrategy serverRedirectStrategy; private ServerRedirectStrategy redirectStrategy;
private String location = "/login"; private String location = "/login";
@ -83,8 +83,8 @@ public class RedirectServerAuthenticationEntryPointTests {
@Test @Test
public void commenceWhenCustomServerRedirectStrategyThenCustomServerRedirectStrategyUsed() { public void commenceWhenCustomServerRedirectStrategyThenCustomServerRedirectStrategyUsed() {
PublisherProbe<Void> redirectResult = PublisherProbe.empty(); PublisherProbe<Void> redirectResult = PublisherProbe.empty();
when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono()); when(this.redirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono());
this.entryPoint.setServerRedirectStrategy(this.serverRedirectStrategy); this.entryPoint.setRedirectStrategy(this.redirectStrategy);
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build()); this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
this.entryPoint.commence(this.exchange, this.exception).block(); this.entryPoint.commence(this.exchange, this.exception).block();
@ -94,6 +94,6 @@ public class RedirectServerAuthenticationEntryPointTests {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void setRedirectStrategyWhenNullThenException() { public void setRedirectStrategyWhenNullThenException() {
this.entryPoint.setServerRedirectStrategy(null); this.entryPoint.setRedirectStrategy(null);
} }
} }

View File

@ -44,7 +44,7 @@ public class RedirectServerAuthenticationFailureHandlerTests {
private WebFilterExchange exchange; private WebFilterExchange exchange;
@Mock @Mock
private ServerRedirectStrategy serverRedirectStrategy; private ServerRedirectStrategy redirectStrategy;
private String location = "/login"; private String location = "/login";
@ -83,8 +83,8 @@ public class RedirectServerAuthenticationFailureHandlerTests {
@Test @Test
public void commenceWhenCustomServerRedirectStrategyThenCustomServerRedirectStrategyUsed() { public void commenceWhenCustomServerRedirectStrategyThenCustomServerRedirectStrategyUsed() {
PublisherProbe<Void> redirectResult = PublisherProbe.empty(); PublisherProbe<Void> redirectResult = PublisherProbe.empty();
when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono()); when(this.redirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono());
this.handler.setServerRedirectStrategy(this.serverRedirectStrategy); this.handler.setRedirectStrategy(this.redirectStrategy);
this.exchange = createExchange(); this.exchange = createExchange();
this.handler.onAuthenticationFailure(this.exchange, this.exception).block(); this.handler.onAuthenticationFailure(this.exchange, this.exception).block();
@ -94,7 +94,7 @@ public class RedirectServerAuthenticationFailureHandlerTests {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void setRedirectStrategyWhenNullThenException() { public void setRedirectStrategyWhenNullThenException() {
this.handler.setServerRedirectStrategy(null); this.handler.setRedirectStrategy(null);
} }
private WebFilterExchange createExchange() { private WebFilterExchange createExchange() {

View File

@ -50,7 +50,7 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
@Mock @Mock
private WebFilterChain chain; private WebFilterChain chain;
@Mock @Mock
private ServerRedirectStrategy serverRedirectStrategy; private ServerRedirectStrategy redirectStrategy;
@Mock @Mock
private Authentication authentication; private Authentication authentication;
@ -90,19 +90,19 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
@Test @Test
public void successWhenCustomLocationThenCustomLocationUsed() { public void successWhenCustomLocationThenCustomLocationUsed() {
PublisherProbe<Void> redirectResult = PublisherProbe.empty(); PublisherProbe<Void> redirectResult = PublisherProbe.empty();
when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono()); when(this.redirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono());
this.handler.setServerRedirectStrategy(this.serverRedirectStrategy); this.handler.setRedirectStrategy(this.redirectStrategy);
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build()); this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange, this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange,
this.chain), this.authentication).block(); this.chain), this.authentication).block();
redirectResult.assertWasSubscribed(); redirectResult.assertWasSubscribed();
verify(this.serverRedirectStrategy).sendRedirect(any(), eq(this.location)); verify(this.redirectStrategy).sendRedirect(any(), eq(this.location));
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void setRedirectStrategyWhenNullThenException() { public void setRedirectStrategyWhenNullThenException() {
this.handler.setServerRedirectStrategy(null); this.handler.setRedirectStrategy(null);
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)