001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.security.auth;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    
020    import javax.servlet.http.HttpServletRequest;
021    import javax.servlet.http.HttpServletResponse;
022    
023    /**
024     * @author Mate Thurzo
025     */
026    public abstract class BaseAutoLogin implements AutoLogin {
027    
028            @Override
029            public String[] handleException(
030                            HttpServletRequest request, HttpServletResponse response,
031                            Exception e)
032                    throws AutoLoginException {
033    
034                    return doHandleException(request, response, e);
035            }
036    
037            @Override
038            public String[] login(
039                            HttpServletRequest request, HttpServletResponse response)
040                    throws AutoLoginException {
041    
042                    try {
043                            return doLogin(request, response);
044                    }
045                    catch (Exception e) {
046                            return handleException(request, response, e);
047                    }
048            }
049    
050            protected String[] doHandleException(
051                            HttpServletRequest request, HttpServletResponse response,
052                            Exception e)
053                    throws AutoLoginException {
054    
055                    if (request.getAttribute(AutoLogin.AUTO_LOGIN_REDIRECT) == null) {
056                            throw new AutoLoginException(e);
057                    }
058    
059                    _log.error(e, e);
060    
061                    return null;
062            }
063    
064            protected abstract String[] doLogin(
065                            HttpServletRequest request, HttpServletResponse response)
066                    throws Exception;
067    
068            private static Log _log = LogFactoryUtil.getLog(BaseAutoLogin.class);
069    
070    }