001    /**
002     * Copyright (c) 2000-2013 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.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    }