001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2014-2015 ForgeRock AS.
015 */
016
017package org.forgerock.http.session;
018
019import java.io.IOException;
020
021import org.forgerock.http.protocol.Request;
022import org.forgerock.http.protocol.Response;
023
024/**
025 * A SessionFactory is responsible to create a new type of {@link Session}.
026 *
027 * <p>This allows users to extends the default OpenIG behaviour quite easily.</p>
028 */
029public interface SessionManager {
030
031    /**
032     * Loads a new Session for the given {@link Request}. The implementations
033     * are free to keep a reference to the {@code Request}.
034     *
035     * <p>The session object is scoped by the {@code Request}'s own lifecycle.</p>
036     *
037     * @param request Request to create a session for.
038     * @return a new Session instance.
039     */
040    Session load(Request request);
041
042    /**
043     * Saves the {@literal session} into the provided {@literal response}.
044     *
045     * @param session The session to save.
046     * @param response The response to save the session to.
047     * @throws IOException If the {@literal session} could not be saved to the
048     * {@literal response}.
049     */
050    void save(Session session, Response response) throws IOException;
051}