001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.security.auth.session;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
019    import com.liferay.registry.Registry;
020    import com.liferay.registry.RegistryUtil;
021    import com.liferay.registry.ServiceTracker;
022    
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.http.HttpServletResponse;
025    import javax.servlet.http.HttpSession;
026    
027    /**
028     * @author Tomas Polesovsky
029     */
030    public class AuthenticatedSessionManagerUtil {
031    
032            public static AuthenticatedSessionManager getAuthenticatedSessionManager() {
033                    PortalRuntimePermission.checkGetBeanProperty(
034                            AuthenticatedSessionManagerUtil.class);
035    
036                    return _instance._serviceTracker.getService();
037            }
038    
039            public static long getAuthenticatedUserId(
040                            HttpServletRequest request, String login, String password,
041                            String authType)
042                    throws PortalException {
043    
044                    return getAuthenticatedSessionManager().getAuthenticatedUserId(
045                            request, login, password, authType);
046            }
047    
048            public static void login(
049                            HttpServletRequest request, HttpServletResponse response,
050                            String login, String password, boolean rememberMe, String authType)
051                    throws Exception {
052    
053                    getAuthenticatedSessionManager().login(
054                            request, response, login, password, rememberMe, authType);
055            }
056    
057            public static void logout(
058                            HttpServletRequest request, HttpServletResponse response)
059                    throws Exception {
060    
061                    getAuthenticatedSessionManager().logout(request, response);
062            }
063    
064            public static HttpSession renewSession(
065                            HttpServletRequest request, HttpSession session)
066                    throws Exception {
067    
068                    return getAuthenticatedSessionManager().renewSession(request, session);
069            }
070    
071            public static void signOutSimultaneousLogins(long userId) throws Exception {
072                    getAuthenticatedSessionManager().signOutSimultaneousLogins(userId);
073            }
074    
075            private AuthenticatedSessionManagerUtil() {
076                    Registry registry = RegistryUtil.getRegistry();
077    
078                    _serviceTracker = registry.trackServices(
079                            AuthenticatedSessionManager.class);
080    
081                    _serviceTracker.open();
082            }
083    
084            private static final AuthenticatedSessionManagerUtil _instance =
085                    new AuthenticatedSessionManagerUtil();
086    
087            private final ServiceTracker<?, AuthenticatedSessionManager>
088                    _serviceTracker;
089    
090    }