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