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            public String[] handleException(
029                            HttpServletRequest request, HttpServletResponse response,
030                            Exception e)
031                    throws AutoLoginException {
032    
033                    return doHandleException(request, response, e);
034            }
035    
036            public String[] login(
037                            HttpServletRequest request, HttpServletResponse response)
038                    throws AutoLoginException {
039    
040                    try {
041                            return doLogin(request, response);
042                    }
043                    catch (Exception e) {
044                            return handleException(request, response, e);
045                    }
046            }
047    
048            protected String[] doHandleException(
049                            HttpServletRequest request, HttpServletResponse response,
050                            Exception e)
051                    throws AutoLoginException {
052    
053                    if (request.getAttribute(AutoLogin.AUTO_LOGIN_REDIRECT) == null) {
054                            throw new AutoLoginException(e);
055                    }
056    
057                    _log.error(e, e);
058    
059                    return null;
060            }
061    
062            protected abstract String[] doLogin(
063                            HttpServletRequest request, HttpServletResponse response)
064                    throws Exception;
065    
066            private static Log _log = LogFactoryUtil.getLog(BaseAutoLogin.class);
067    
068    }