    001    package 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
    024    import java.util.Collection;
    025    import javax.servlet.http.HttpSession;
    026
    027    import org.apache.turbine.om.security.User;
    028    import org.apache.turbine.services.Service;
    029
    030    /**
    031     * The SessionService allows access to the current sessions of the current context.
    032     * The session objects that are cached by this service are obtained through
    033     * a listener.  The listener must be configured in your web.xml file.
    034     *
    035     * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
    036     * @since 2.3
    037     * @see org.apache.turbine.services.session.SessionListener
    038     * @version $Id: SessionService.java 1066925 2011-02-03 19:44:37Z ludwig $
    039     */
    040    public interface SessionService extends Service
    041    {
    042
    043        /**
    044         * The key under which this service is stored in TurbineServices.
    045         */
    046        static final String SERVICE_NAME = "SessionService";
    047
    048        /**
    049         * Gets all active sessions
    050         *
    051         * @return Collection of HttpSession objects
    052         */
    053        Collection<HttpSession> getActiveSessions();
    054
    055        /**
    056         * Adds a session to the current list.  This method should only be
    057         * called by the listener.
    058         *
    059         * @param session Session to add
    060         */
    061        void addSession(HttpSession session);
    062
    063        /**
    064         * Removes a session from the current list.  This method should only be
    065         * called by the listener.
    066         *
    067         * @param session Session to remove
    068         */
    069        void removeSession(HttpSession session);
    070
    071        /**
    072         * Determines if a given user is currently logged in.  The actual
    073         * implementation of the User object must implement the equals()
    074         * method.  By default, Torque based objects (liek TurbineUser)
    075         * have an implementation of equals() that will compare the
    076         * result of getPrimaryKey().
    077         *
    078         * @param user User to check for
    079         * @return true if the user is logged in on one of the
    080         * active sessions.
    081         */
    082        boolean isUserLoggedIn(User user);
    083
    084        /**
    085         * Gets a collection of all user objects representing the users currently
    086         * logged in.  This will exclude any instances of anonymous user that
    087         * Turbine will use before the user actually logs on.
    088         *
    089         * @return collection of org.apache.turbine.om.security.User objects
    090         */
    091        Collection<User> getActiveUsers();
    092
    093        /**
    094         * Gets the User object of the the specified HttpSession.
    095         *
    096         * @param session The session from which to extract a user.
    097         * @return The Turbine User object.
    098         */
    099        User getUserFromSession(HttpSession session);
    100
    101        /**
    102         * Gets the HttpSession by the session identifier
    103         *
    104         * @param sessionId The unique session identifier.
    105         * @return The session keyed by the specified identifier.
    106         */
    107        HttpSession getSession(String sessionId);
    108
    109        /**
    110         * Get a collection of all session on which the given user
    111         * is logged in.
    112         *
    113         * @param user the user
    114         * @return Collection of HtttSession objects
    115         */
    116        Collection<HttpSession> getSessionsForUser(User user);
    117
    118    }