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.tunnel;
016    
017    import com.liferay.portal.security.auth.AuthException;
018    import com.liferay.registry.Registry;
019    import com.liferay.registry.RegistryUtil;
020    import com.liferay.registry.ServiceTracker;
021    
022    import java.net.HttpURLConnection;
023    
024    import javax.servlet.http.HttpServletRequest;
025    
026    /**
027     * @author Tomas Polesovsky
028     */
029    public class TunnelAuthenticationManagerUtil {
030    
031            public static long getUserId(HttpServletRequest httpServletRequest)
032                    throws AuthException {
033    
034                    return getTunnelManagerUtil().getUserId(httpServletRequest);
035            }
036    
037            public static void setCredentials(
038                            String login, HttpURLConnection httpURLConnection)
039                    throws Exception {
040    
041                    getTunnelManagerUtil().setCredentials(login, httpURLConnection);
042            }
043    
044            private static TunnelAuthenticationManager getTunnelManagerUtil() {
045                    return _instance._serviceTracker.getService();
046            }
047    
048            private TunnelAuthenticationManagerUtil() {
049                    Registry registry = RegistryUtil.getRegistry();
050    
051                    _serviceTracker = registry.trackServices(
052                            TunnelAuthenticationManager.class);
053    
054                    _serviceTracker.open();
055            }
056    
057            private static final TunnelAuthenticationManagerUtil _instance =
058                    new TunnelAuthenticationManagerUtil();
059    
060            private final ServiceTracker<?, TunnelAuthenticationManager>
061                    _serviceTracker;
062    
063    }