1
22
23 package com.liferay.portal.security.auth;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.log.Log;
27 import com.liferay.portal.kernel.log.LogFactoryUtil;
28 import com.liferay.portal.kernel.servlet.HttpHeaders;
29 import com.liferay.portal.kernel.util.Validator;
30 import com.liferay.portal.model.User;
31 import com.liferay.portal.service.UserLocalServiceUtil;
32 import com.liferay.portal.util.PortalUtil;
33
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
36
37
43 public class RequestHeaderAutoLogin extends CASAutoLogin {
44
45 public String[] login(
46 HttpServletRequest request, HttpServletResponse response) {
47
48 String[] credentials = null;
49
50 try {
51 long companyId = PortalUtil.getCompanyId(request);
52
53 String screenName = request.getHeader(
54 HttpHeaders.LIFERAY_SCREEN_NAME);
55
56 if (Validator.isNull(screenName)) {
57 return credentials;
58 }
59
60 User user = null;
61
62 try {
63 user = importLDAPUser(companyId, screenName);
64 }
65 catch (SystemException se) {
66 }
67
68 if (user == null) {
69 user = UserLocalServiceUtil.getUserByScreenName(
70 companyId, screenName);
71 }
72
73 credentials = new String[3];
74
75 credentials[0] = String.valueOf(user.getUserId());
76 credentials[1] = user.getPassword();
77 credentials[2] = Boolean.TRUE.toString();
78
79 return credentials;
80 }
81 catch (Exception e) {
82 _log.error(e, e);
83 }
84
85 return credentials;
86 }
87
88 private static Log _log =
89 LogFactoryUtil.getLog(RequestHeaderAutoLogin.class);
90
91 }