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.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    }