1
19
20 package com.liferay.portal.security.auth;
21
22 import com.liferay.portal.NoSuchUserException;
23 import com.liferay.portal.kernel.log.Log;
24 import com.liferay.portal.kernel.log.LogFactoryUtil;
25 import com.liferay.portal.kernel.util.Validator;
26 import com.liferay.portal.model.User;
27 import com.liferay.portal.security.ldap.PortalLDAPUtil;
28 import com.liferay.portal.service.UserLocalServiceUtil;
29 import com.liferay.portal.util.PortalUtil;
30 import com.liferay.portal.util.PrefsPropsUtil;
31 import com.liferay.portal.util.PropsKeys;
32 import com.liferay.portal.util.PropsValues;
33
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
36
37
43 public class SiteMinderAutoLogin extends CASAutoLogin {
44
45 public String[] login(
46 HttpServletRequest request, HttpServletResponse response)
47 throws AutoLoginException {
48
49 String[] credentials = null;
50
51 try {
52 long companyId = PortalUtil.getCompanyId(request);
53
54 if (!PortalLDAPUtil.isSiteMinderEnabled(companyId)) {
55 return credentials;
56 }
57
58 String screenName = request.getHeader(
59 PrefsPropsUtil.getString(
60 companyId, PropsKeys.SITEMINDER_USER_HEADER,
61 PropsValues.SITEMINDER_USER_HEADER));
62
63 if (Validator.isNull(screenName)) {
64 return credentials;
65 }
66
67 User user = null;
68
69 try {
70 user = UserLocalServiceUtil.getUserByScreenName(
71 companyId, screenName);
72 }
73 catch (NoSuchUserException nsue) {
74 if (PrefsPropsUtil.getBoolean(
75 companyId, PropsKeys.SITEMINDER_IMPORT_FROM_LDAP,
76 PropsValues.SITEMINDER_IMPORT_FROM_LDAP)) {
77
78 user = addUser(companyId, screenName);
79 }
80 else {
81 throw nsue;
82 }
83 }
84
85 credentials = new String[3];
86
87 credentials[0] = String.valueOf(user.getUserId());
88 credentials[1] = user.getPassword();
89 credentials[2] = Boolean.TRUE.toString();
90
91 return credentials;
92 }
93 catch (Exception e) {
94 _log.error(e, e);
95 }
96
97 return credentials;
98 }
99
100 private static Log _log = LogFactoryUtil.getLog(SiteMinderAutoLogin.class);
101
102 }