001/*
002 * Copyright 2002-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.server.session;
018
019import reactor.core.publisher.Mono;
020
021import org.springframework.web.server.WebSession;
022
023/**
024 * Strategy for {@link WebSession} persistence.
025 *
026 * @author Rossen Stoyanchev
027 * @author Rob Winch
028 * @since 5.0
029 */
030public interface WebSessionStore {
031
032        /**
033         * Create a new WebSession.
034         * <p>Note that this does nothing more than create a new instance.
035         * The session can later be started explicitly via {@link WebSession#start()}
036         * or implicitly by adding attributes -- and then persisted via
037         * {@link WebSession#save()}.
038         * @return the created session instance
039         */
040        Mono<WebSession> createWebSession();
041
042        /**
043         * Return the WebSession for the given id.
044         * <p><strong>Note:</strong> This method should perform an expiration check,
045         * and if it has expired remove the session and return empty. This method
046         * should also update the lastAccessTime of retrieved sessions.
047         * @param sessionId the session to load
048         * @return the session, or an empty {@code Mono} .
049         */
050        Mono<WebSession> retrieveSession(String sessionId);
051
052        /**
053         * Remove the WebSession for the specified id.
054         * @param sessionId the id of the session to remove
055         * @return a completion notification (success or error)
056         */
057        Mono<Void> removeSession(String sessionId);
058
059        /**
060         * Update the last accessed timestamp to "now".
061         * @param webSession the session to update
062         * @return the session with the updated last access time
063         */
064        Mono<WebSession> updateLastAccessTime(WebSession webSession);
065
066}