1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }