1 package org.apache.turbine.services.session;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collection;
23 import javax.servlet.http.HttpSession;
24
25 import org.apache.turbine.om.security.User;
26 import org.apache.turbine.services.pull.ApplicationTool;
27
28 /***
29 * A pull tool for accessing the SessionService from a velocity template.
30 *
31 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
32 * @version $Id: SessionTool.java 534527 2007-05-02 16:10:59Z tv $
33 */
34 public class SessionTool
35 implements ApplicationTool
36 {
37 public void init(Object o)
38 {
39 }
40
41 public void refresh()
42 {
43 }
44
45 /***
46 * Gets a list of the active sessions
47 *
48 * @return List of HttpSession objects
49 */
50 public Collection getActiveSessions()
51 {
52 return TurbineSession.getActiveSessions();
53 }
54
55 /***
56 * Adds a session to the current list. This method should only be
57 * called by the listener.
58 *
59 * @param session Session to add
60 */
61 public void addSession(HttpSession session)
62 {
63 TurbineSession.addSession(session);
64 }
65
66 /***
67 * Removes a session from the current list. This method should only be
68 * called by the listener.
69 *
70 * @param session Session to remove
71 */
72 public void removeSession(HttpSession session)
73 {
74 TurbineSession.removeSession(session);
75 }
76
77 /***
78 * Determines if a given user is currently logged in. The actual
79 * implementation of the User object must implement the equals()
80 * method. By default, Torque based objects (liek TurbineUser)
81 * have an implementation of equals() that will compare the
82 * result of getPrimaryKey().
83 *
84 * @param user User to check for
85 * @return true if the user is logged in on one of the
86 * active sessions.
87 */
88 public boolean isUserLoggedIn(User user)
89 {
90 return TurbineSession.isUserLoggedIn(user);
91 }
92
93 /***
94 * Gets a collection of all user objects representing the users currently
95 * logged in. This will exclude any instances of anonymous user that
96 * Turbine will use before the user actually logs on.
97 *
98 * @return collection of org.apache.turbine.om.security.User objects
99 */
100 public Collection getActiveUsers()
101 {
102 return TurbineSession.getActiveUsers();
103 }
104
105 /***
106 * Gets the User object of the the specified HttpSession.
107 *
108 * @param session
109 * @return
110 */
111 public User getUserFromSession(HttpSession session)
112 {
113 return TurbineSession.getUserFromSession(session);
114 }
115
116 /***
117 * Get a collection of all session on which the given user
118 * is logged in.
119 *
120 * @param user the user
121 * @return Collection of HtttSession objects
122 */
123 public Collection getSessionsForUser(User user)
124 {
125 return TurbineSession.getSessionsForUser(user);
126 }
127 }