001package org.apache.turbine.services.session; 002 003 004/* 005 * Licensed to the Apache Software Foundation (ASF) under one 006 * or more contributor license agreements. See the NOTICE file 007 * distributed with this work for additional information 008 * regarding copyright ownership. The ASF licenses this file 009 * to you under the Apache License, Version 2.0 (the 010 * "License"); you may not use this file except in compliance 011 * with the License. You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, 016 * software distributed under the License is distributed on an 017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 018 * KIND, either express or implied. See the License for the 019 * specific language governing permissions and limitations 020 * under the License. 021 */ 022 023 024import java.util.Collection; 025 026import javax.servlet.http.HttpSession; 027 028import org.apache.turbine.om.security.User; 029import org.apache.turbine.services.Service; 030 031/** 032 * The SessionService allows access to the current sessions of the current context. 033 * The session objects that are cached by this service are obtained through 034 * a listener. The listener must be configured in your web.xml file. 035 * 036 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a> 037 * @since 2.3 038 * @see org.apache.turbine.services.session.SessionListener 039 * @version $Id: SessionService.java 1854787 2019-03-04 18:30:25Z tv $ 040 */ 041public interface SessionService extends Service 042{ 043 044 /** 045 * The key under which this service is stored in TurbineServices. 046 */ 047 String SERVICE_NAME = "SessionService"; 048 049 /** 050 * Gets all active sessions 051 * 052 * @return Collection of HttpSession objects 053 */ 054 Collection<HttpSession> getActiveSessions(); 055 056 /** 057 * Adds a session to the current list. This method should only be 058 * called by the listener. 059 * 060 * @param session Session to add 061 */ 062 void addSession(HttpSession session); 063 064 /** 065 * Removes a session from the current list. This method should only be 066 * called by the listener. 067 * 068 * @param session Session to remove 069 */ 070 void removeSession(HttpSession session); 071 072 /** 073 * Determines if a given user is currently logged in. The actual 074 * implementation of the User object must implement the equals() 075 * method. By default, Torque based objects (liek TurbineUser) 076 * have an implementation of equals() that will compare the 077 * result of getPrimaryKey(). 078 * 079 * @param user User to check for 080 * @return true if the user is logged in on one of the 081 * active sessions. 082 */ 083 boolean isUserLoggedIn(User user); 084 085 /** 086 * Gets a collection of all user objects representing the users currently 087 * logged in. This will exclude any instances of anonymous user that 088 * Turbine will use before the user actually logs on. 089 * 090 * @return collection of org.apache.turbine.om.security.User objects 091 */ 092 Collection<User> getActiveUsers(); 093 094 /** 095 * Gets the User object of the the specified HttpSession. 096 * 097 * @param session The session from which to extract a user. 098 * @return The Turbine User object. 099 */ 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}