1 package org.apache.turbine.services.session;
2
3
4 /*
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 */
22
23
24 import java.util.Collection;
25
26 import javax.servlet.http.HttpSession;
27
28 import org.apache.turbine.om.security.User;
29 import org.apache.turbine.services.Service;
30
31 /**
32 * The SessionService allows access to the current sessions of the current context.
33 * The session objects that are cached by this service are obtained through
34 * a listener. The listener must be configured in your web.xml file.
35 *
36 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
37 * @since 2.3
38 * @see org.apache.turbine.services.session.SessionListener
39 * @version $Id: SessionService.java 1854787 2019-03-04 18:30:25Z tv $
40 */
41 public interface SessionService extends Service
42 {
43
44 /**
45 * The key under which this service is stored in TurbineServices.
46 */
47 String SERVICE_NAME = "SessionService";
48
49 /**
50 * Gets all active sessions
51 *
52 * @return Collection of HttpSession objects
53 */
54 Collection<HttpSession> getActiveSessions();
55
56 /**
57 * Adds a session to the current list. This method should only be
58 * called by the listener.
59 *
60 * @param session Session to add
61 */
62 void addSession(HttpSession session);
63
64 /**
65 * Removes a session from the current list. This method should only be
66 * called by the listener.
67 *
68 * @param session Session to remove
69 */
70 void removeSession(HttpSession session);
71
72 /**
73 * Determines if a given user is currently logged in. The actual
74 * implementation of the User object must implement the equals()
75 * method. By default, Torque based objects (liek TurbineUser)
76 * have an implementation of equals() that will compare the
77 * result of getPrimaryKey().
78 *
79 * @param user User to check for
80 * @return true if the user is logged in on one of the
81 * active sessions.
82 */
83 boolean isUserLoggedIn(User user);
84
85 /**
86 * Gets a collection of all user objects representing the users currently
87 * logged in. This will exclude any instances of anonymous user that
88 * Turbine will use before the user actually logs on.
89 *
90 * @return collection of org.apache.turbine.om.security.User objects
91 */
92 Collection<User> getActiveUsers();
93
94 /**
95 * Gets the User object of the the specified HttpSession.
96 *
97 * @param session The session from which to extract a user.
98 * @return The Turbine User object.
99 */
100 User getUserFromSession(HttpSession session);
101
102 /**
103 * Gets the HttpSession by the session identifier
104 *
105 * @param sessionId The unique session identifier.
106 * @return The session keyed by the specified identifier.
107 */
108 HttpSession getSession(String sessionId);
109
110 /**
111 * Get a collection of all session on which the given user
112 * is logged in.
113 *
114 * @param user the user
115 * @return Collection of HtttSession objects
116 */
117 Collection<HttpSession> getSessionsForUser(User user);
118 }