1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.security.auth;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.model.User;
20  import com.liferay.portal.service.UserLocalServiceUtil;
21  import com.liferay.portal.util.OpenIdUtil;
22  import com.liferay.portal.util.PortalUtil;
23  import com.liferay.portal.util.WebKeys;
24  
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.http.HttpServletResponse;
27  import javax.servlet.http.HttpSession;
28  
29  /**
30   * <a href="OpenIdAutoLogin.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Jorge Ferrer
33   */
34  public class OpenIdAutoLogin implements AutoLogin {
35  
36      public String[] login(
37          HttpServletRequest request, HttpServletResponse response) {
38  
39          String[] credentials = null;
40  
41          try {
42              long companyId = PortalUtil.getCompanyId(request);
43  
44              if (!OpenIdUtil.isEnabled(companyId)) {
45                  return credentials;
46              }
47  
48              HttpSession session = request.getSession();
49  
50              Long userId = (Long)session.getAttribute(WebKeys.OPEN_ID_LOGIN);
51  
52              if (userId == null) {
53                  return credentials;
54              }
55  
56              session.removeAttribute(WebKeys.OPEN_ID_LOGIN);
57  
58              User user = UserLocalServiceUtil.getUserById(userId);
59  
60              credentials = new String[3];
61  
62              credentials[0] = String.valueOf(user.getUserId());
63              credentials[1] = user.getPassword();
64              credentials[2] = Boolean.TRUE.toString();
65          }
66          catch (Exception e) {
67              _log.error(e, e);
68          }
69  
70          return credentials;
71      }
72  
73      private static Log _log = LogFactoryUtil.getLog(OpenIdAutoLogin.class);
74  
75  }