private Mono<Void> save(ServerWebExchange exchange, WebSession session) { List<String> ids = getSessionIdResolver().resolveSessionIds(exchange); if (!session.isStarted() || session.isExpired()) { if (!ids.isEmpty()) { // Expired on retrieve or while processing request, or invalidated.. this.sessionIdResolver.expireSession(exchange); } return Mono.empty(); } if (ids.isEmpty() || !session.getId().equals(ids.get(0))) { this.sessionIdResolver.setSessionId(exchange, session.getId()); } return session.save(); }
private Mono<WebSession> retrieveSession(ServerWebExchange exchange) { return Flux.fromIterable(getSessionIdResolver().resolveSessionIds(exchange)) .concatMap(this.sessionStore::retrieveSession) .next(); }
private Mono<Void> save(ServerWebExchange exchange, WebSession session) { List<String> ids = getSessionIdResolver().resolveSessionIds(exchange); if (!session.isStarted() || session.isExpired()) { if (!ids.isEmpty()) { // Expired on retrieve or while processing request, or invalidated.. this.sessionIdResolver.expireSession(exchange); } return Mono.empty(); } if (ids.isEmpty() || !session.getId().equals(ids.get(0))) { this.sessionIdResolver.setSessionId(exchange, session.getId()); } return session.save(); }
@Test public void multipleSessionIds() { List<String> ids = Arrays.asList("not-this", "not-that", this.updateSession.getId()); when(this.sessionStore.retrieveSession("not-this")).thenReturn(Mono.empty()); when(this.sessionStore.retrieveSession("not-that")).thenReturn(Mono.empty()); when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(ids); WebSession actual = this.sessionManager.getSession(this.exchange).block(); assertNotNull(actual); assertEquals(this.updateSession.getId(), actual.getId()); } }
@Test public void getSessionSaveWhenCreatedAndStartedThenSavesAndSetsId() { when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(Collections.emptyList()); WebSession session = this.sessionManager.getSession(this.exchange).block(); assertSame(this.createSession, session); String sessionId = this.createSession.getId(); when(this.createSession.isStarted()).thenReturn(true); this.exchange.getResponse().setComplete().block(); verify(this.sessionStore).createWebSession(); verify(this.sessionIdResolver).setSessionId(any(), eq(sessionId)); verify(this.createSession).save(); }
@Test public void getSessionSaveWhenCreatedAndNotStartedThenNotSaved() { when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(Collections.emptyList()); WebSession session = this.sessionManager.getSession(this.exchange).block(); this.exchange.getResponse().setComplete().block(); assertSame(this.createSession, session); assertFalse(session.isStarted()); assertFalse(session.isExpired()); verify(this.createSession, never()).save(); verify(this.sessionIdResolver, never()).setSessionId(any(), any()); }
@Test public void existingSession() { String sessionId = this.updateSession.getId(); when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(Collections.singletonList(sessionId)); WebSession actual = this.sessionManager.getSession(this.exchange).block(); assertNotNull(actual); assertEquals(sessionId, actual.getId()); }
private Mono<WebSession> retrieveSession(ServerWebExchange exchange) { return Flux.fromIterable(getSessionIdResolver().resolveSessionIds(exchange)) .concatMap(this.sessionStore::retrieveSession) .next(); }
private Mono<Void> save(ServerWebExchange exchange, WebSession session) { List<String> ids = getSessionIdResolver().resolveSessionIds(exchange); if (!session.isStarted() || session.isExpired()) { if (!ids.isEmpty()) { // Expired on retrieve or while processing request, or invalidated.. this.sessionIdResolver.expireSession(exchange); } return Mono.empty(); } if (ids.isEmpty() || !session.getId().equals(ids.get(0))) { this.sessionIdResolver.setSessionId(exchange, session.getId()); } return session.save(); }
private Mono<Void> save(ServerWebExchange exchange, WebSession session) { List<String> ids = getSessionIdResolver().resolveSessionIds(exchange); if (!session.isStarted() || session.isExpired()) { if (!ids.isEmpty()) { // Expired on retrieve or while processing request, or invalidated.. this.sessionIdResolver.expireSession(exchange); } return Mono.empty(); } if (ids.isEmpty() || !session.getId().equals(ids.get(0))) { this.sessionIdResolver.setSessionId(exchange, session.getId()); } return session.save(); }
private Mono<WebSession> retrieveSession(ServerWebExchange exchange) { return Flux.fromIterable(getSessionIdResolver().resolveSessionIds(exchange)) .concatMap(this.sessionStore::retrieveSession) .next(); }
private Mono<WebSession> retrieveSession(ServerWebExchange exchange) { return Flux.fromIterable(getSessionIdResolver().resolveSessionIds(exchange)) .concatMap(this.sessionStore::retrieveSession) .next(); }