@@ -18,13 +18,11 @@ package org.springframework.web.server.session;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.http.HttpCookie;
|
||||
import org.springframework.http.ServerHttpCookie;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
@@ -77,10 +75,13 @@ public class CookieWebSessionIdResolver implements WebSessionIdResolver {
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<String> resolveSessionId(ServerWebExchange exchange) {
|
||||
public List<String> resolveSessionId(ServerWebExchange exchange) {
|
||||
MultiValueMap<String, HttpCookie> cookieMap = exchange.getRequest().getCookies();
|
||||
HttpCookie cookie = cookieMap.getFirst(getCookieName());
|
||||
return (cookie != null ? Optional.of(cookie.getValue()) : Optional.empty());
|
||||
List<HttpCookie> cookies = cookieMap.get(getCookieName());
|
||||
if (cookies == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return cookies.stream().map(HttpCookie::getValue).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,9 +17,10 @@ package org.springframework.web.server.session;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
@@ -98,9 +99,8 @@ public class DefaultWebSessionManager implements WebSessionManager {
|
||||
|
||||
@Override
|
||||
public Mono<WebSession> getSession(ServerWebExchange exchange) {
|
||||
return Mono.fromCallable(() -> getSessionIdResolver().resolveSessionId(exchange))
|
||||
.where(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
return Flux.fromIterable(getSessionIdResolver().resolveSessionId(exchange))
|
||||
.next()
|
||||
.then(this.sessionStore::retrieveSession)
|
||||
.then(session -> validateSession(exchange, session))
|
||||
.otherwiseIfEmpty(createSession(exchange))
|
||||
@@ -147,8 +147,8 @@ public class DefaultWebSessionManager implements WebSessionManager {
|
||||
// Force explicit start
|
||||
session.start();
|
||||
|
||||
Optional<String> requestedId = getSessionIdResolver().resolveSessionId(exchange);
|
||||
if (!requestedId.isPresent() || !session.getId().equals(requestedId.get())) {
|
||||
List<String> requestedIds = getSessionIdResolver().resolveSessionId(exchange);
|
||||
if (requestedIds.isEmpty() || !session.getId().equals(requestedIds.get(0))) {
|
||||
this.sessionIdResolver.setSessionId(exchange, session.getId());
|
||||
}
|
||||
return this.sessionStore.storeSession(session);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.web.server.session;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
@@ -31,11 +31,11 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
public interface WebSessionIdResolver {
|
||||
|
||||
/**
|
||||
* Resolve the session id associated with the request.
|
||||
* Resolve the session id's associated with the request.
|
||||
* @param exchange the current exchange
|
||||
* @return the session id if present
|
||||
* @return the session id's or an empty list
|
||||
*/
|
||||
Optional<String> resolveSessionId(ServerWebExchange exchange);
|
||||
List<String> resolveSessionId(ServerWebExchange exchange);
|
||||
|
||||
/**
|
||||
* Send the given session id to the client or if the session id is "null"
|
||||
|
||||
Reference in New Issue
Block a user