ServerRedirectCache.getRequest->getRedirectUri

Issue: gh-4789
This commit is contained in:
Rob Winch 2017-11-15 13:21:25 -06:00
parent 4039cd285e
commit 64ad08e96d
5 changed files with 11 additions and 11 deletions

View File

@ -55,7 +55,7 @@ public class RedirectServerAuthenticationSuccessHandler
public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange, public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange,
Authentication authentication) { Authentication authentication) {
ServerWebExchange exchange = webFilterExchange.getExchange(); ServerWebExchange exchange = webFilterExchange.getExchange();
return this.requestCache.getRequest(exchange) return this.requestCache.getRedirectUri(exchange)
.defaultIfEmpty(this.location) .defaultIfEmpty(this.location)
.flatMap(location -> this.redirectStrategy.sendRedirect(exchange, location)); .flatMap(location -> this.redirectStrategy.sendRedirect(exchange, location));
} }

View File

@ -33,7 +33,7 @@ public class NoOpServerRequestCache implements ServerRequestCache {
} }
@Override @Override
public Mono<URI> getRequest(ServerWebExchange exchange) { public Mono<URI> getRedirectUri(ServerWebExchange exchange) {
return Mono.empty(); return Mono.empty();
} }

View File

@ -40,11 +40,11 @@ public interface ServerRequestCache {
Mono<Void> saveRequest(ServerWebExchange exchange); Mono<Void> saveRequest(ServerWebExchange exchange);
/** /**
* Get the saved {@link ServerHttpRequest} * Get the URI that can be redirected to trigger the saved request to be used
* @param exchange the exchange to obtain the saved {@link ServerHttpRequest} from * @param exchange the exchange to obtain the saved {@link ServerHttpRequest} from
* @return the {@link ServerHttpRequest} * @return the URI that can be redirected to trigger the saved request to be used
*/ */
Mono<URI> getRequest(ServerWebExchange exchange); Mono<URI> getRedirectUri(ServerWebExchange exchange);
/** /**
* If the provided {@link ServerWebExchange} matches the saved {@link ServerHttpRequest} * If the provided {@link ServerWebExchange} matches the saved {@link ServerHttpRequest}

View File

@ -70,7 +70,7 @@ public class WebSessionServerRequestCache implements ServerRequestCache {
} }
@Override @Override
public Mono<URI> getRequest(ServerWebExchange exchange) { public Mono<URI> getRedirectUri(ServerWebExchange exchange) {
return exchange.getSession() return exchange.getSession()
.flatMap(session -> Mono.justOrEmpty(session.<String>getAttribute(this.sessionAttrName))) .flatMap(session -> Mono.justOrEmpty(session.<String>getAttribute(this.sessionAttrName)))
.map(URI::create); .map(URI::create);
@ -79,7 +79,7 @@ public class WebSessionServerRequestCache implements ServerRequestCache {
@Override @Override
public Mono<ServerHttpRequest> getMatchingRequest( public Mono<ServerHttpRequest> getMatchingRequest(
ServerWebExchange exchange) { ServerWebExchange exchange) {
return getRequest(exchange) return getRedirectUri(exchange)
.map(URI::toASCIIString) .map(URI::toASCIIString)
.map(path -> exchange.getRequest().mutate().path(path).build()) .map(path -> exchange.getRequest().mutate().path(path).build())
.filter( request -> pathInApplication(request).equals( .filter( request -> pathInApplication(request).equals(

View File

@ -38,7 +38,7 @@ public class WebSessionServerRequestCacheTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/secured/")); MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/secured/"));
this.cache.saveRequest(exchange).block(); this.cache.saveRequest(exchange).block();
URI saved = this.cache.getRequest(exchange).block(); URI saved = this.cache.getRedirectUri(exchange).block();
assertThat(saved).isEqualTo(exchange.getRequest().getURI()); assertThat(saved).isEqualTo(exchange.getRequest().getURI());
} }
@ -48,7 +48,7 @@ public class WebSessionServerRequestCacheTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/secured/")); MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/secured/"));
this.cache.saveRequest(exchange).block(); this.cache.saveRequest(exchange).block();
assertThat(this.cache.getRequest(exchange).block()).isNull(); assertThat(this.cache.getRedirectUri(exchange).block()).isNull();
} }
@Test @Test
@ -57,7 +57,7 @@ public class WebSessionServerRequestCacheTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/secured/")); MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/secured/"));
this.cache.saveRequest(exchange).block(); this.cache.saveRequest(exchange).block();
URI saved = this.cache.getRequest(exchange).block(); URI saved = this.cache.getRedirectUri(exchange).block();
assertThat(saved).isEqualTo(exchange.getRequest().getURI()); assertThat(saved).isEqualTo(exchange.getRequest().getURI());
} }
@ -79,6 +79,6 @@ public class WebSessionServerRequestCacheTests {
this.cache.removeRequest(exchange).block(); this.cache.removeRequest(exchange).block();
assertThat(this.cache.getRequest(exchange).block()).isNull(); assertThat(this.cache.getRedirectUri(exchange).block()).isNull();
} }
} }