1
22
23 package com.liferay.portal.security.auth;
24
25 import com.liferay.portal.NoSuchUserException;
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 = UserLocalServiceUtil.getUserByScreenName(
64 companyId, screenName);
65 }
66 catch (NoSuchUserException nsue) {
67 user = addUser(companyId, screenName);
68 }
69
70 credentials = new String[3];
71
72 credentials[0] = String.valueOf(user.getUserId());
73 credentials[1] = user.getPassword();
74 credentials[2] = Boolean.TRUE.toString();
75
76 return credentials;
77 }
78 catch (Exception e) {
79 _log.error(e, e);
80 }
81
82 return credentials;
83 }
84
85 private static Log _log =
86 LogFactoryUtil.getLog(RequestHeaderAutoLogin.class);
87
88 }