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.model.User;
018    import com.liferay.portal.service.UserLocalServiceUtil;
019    import com.liferay.portal.util.OpenIdUtil;
020    import com.liferay.portal.util.PortalUtil;
021    import com.liferay.portal.util.WebKeys;
022    
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.http.HttpServletResponse;
025    import javax.servlet.http.HttpSession;
026    
027    /**
028     * @author Jorge Ferrer
029     */
030    public class OpenIdAutoLogin extends BaseAutoLogin {
031    
032            @Override
033            protected String[] doLogin(
034                            HttpServletRequest request, HttpServletResponse response)
035                    throws Exception {
036    
037                    long companyId = PortalUtil.getCompanyId(request);
038    
039                    if (!OpenIdUtil.isEnabled(companyId)) {
040                            return null;
041                    }
042    
043                    HttpSession session = request.getSession();
044    
045                    Long userId = (Long)session.getAttribute(WebKeys.OPEN_ID_LOGIN);
046    
047                    if (userId == null) {
048                            return null;
049                    }
050    
051                    session.removeAttribute(WebKeys.OPEN_ID_LOGIN);
052    
053                    User user = UserLocalServiceUtil.getUserById(userId);
054    
055                    String[] credentials = new String[3];
056    
057                    credentials[0] = String.valueOf(user.getUserId());
058                    credentials[1] = user.getPassword();
059                    credentials[2] = Boolean.TRUE.toString();
060    
061                    return credentials;
062            }
063    
064    }