1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 module hunt.shiro.session.mgt.SessionManager;
20 
21 import hunt.shiro.session.mgt.SessionContext;
22 import hunt.shiro.session.mgt.SessionKey;
23 import hunt.shiro.session.Session;
24 import hunt.shiro.Exceptions;
25 
26 /**
27  * A SessionManager manages the creation, maintenance, and clean-up of all application
28  * {@link hunt.shiro.session.Session Session}s.
29  *
30  */
31 interface SessionManager {
32 
33     /**
34      * Starts a new session based on the specified contextual initialization data, which can be used by the underlying
35      * implementation to determine how exactly to create the internal Session instance.
36      * <p/>
37      * This method is mainly used in framework development, as the implementation will often relay the argument
38      * to an underlying {@link SessionFactory} which could use the context to construct the internal Session
39      * instance in a specific manner.  This allows pluggable {@link hunt.shiro.session.Session Session} creation
40      * logic by simply injecting a {@code SessionFactory} into the {@code SessionManager} instance.
41      *
42      * @param context the contextual initialization data that can be used by the implementation or underlying
43      *                {@link SessionFactory} when instantiating the internal {@code Session} instance.
44      * @return the newly created session.
45      * @see SessionFactory#createSession(SessionContext)
46      */
47     Session start(SessionContext context);
48 
49     /**
50      * Retrieves the session corresponding to the specified contextual data (such as a session ID if applicable), or
51      * {@code null} if no Session could be found.  If a session is found but invalid (stopped or expired), a
52      * {@link SessionException} will be thrown.
53      *
54      * @param key the Session key to use to look-up the Session
55      * @return the {@code Session} instance corresponding to the given lookup key or {@code null} if no session
56      *         could be acquired.
57      * @throws SessionException if a session was found but it was invalid (stopped/expired).
58      */
59     Session getSession(SessionKey key);
60 }