001
014
015 package com.liferay.portal.security.auth;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.ParamUtil;
020 import com.liferay.portal.kernel.util.Validator;
021 import com.liferay.portal.model.User;
022 import com.liferay.portal.security.ldap.PortalLDAPImporterUtil;
023 import com.liferay.portal.util.PortalUtil;
024 import com.liferay.portal.util.WebKeys;
025
026 import javax.servlet.http.HttpServletRequest;
027 import javax.servlet.http.HttpServletResponse;
028
029
032 public class NtlmAutoLogin implements AutoLogin {
033
034 public String[] login(
035 HttpServletRequest request, HttpServletResponse response) {
036
037 String[] credentials = null;
038
039 try {
040 long companyId = PortalUtil.getCompanyId(request);
041
042 if (!AuthSettingsUtil.isNtlmEnabled(companyId)) {
043 return credentials;
044 }
045
046 String screenName = (String)request.getAttribute(
047 WebKeys.NTLM_REMOTE_USER);
048
049 if (screenName == null) {
050 return credentials;
051 }
052
053 request.removeAttribute(WebKeys.NTLM_REMOTE_USER);
054
055 User user = PortalLDAPImporterUtil.importLDAPUserByScreenName(
056 companyId, screenName);
057
058 if (user != null) {
059 String redirect = ParamUtil.getString(request, "redirect");
060
061 if (Validator.isNotNull(redirect)) {
062 request.setAttribute(
063 AutoLogin.AUTO_LOGIN_REDIRECT_AND_CONTINUE, redirect);
064 }
065
066 credentials = new String[3];
067
068 credentials[0] = String.valueOf(user.getUserId());
069 credentials[1] = user.getPassword();
070 credentials[2] = Boolean.TRUE.toString();
071 }
072 }
073 catch (Exception e) {
074 _log.error(e, e);
075 }
076
077 return credentials;
078 }
079
080 private static Log _log = LogFactoryUtil.getLog(NtlmAutoLogin.class);
081
082 }