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 @Override
035 public String[] login(
036 HttpServletRequest request, HttpServletResponse response) {
037
038 String[] credentials = null;
039
040 try {
041 long companyId = PortalUtil.getCompanyId(request);
042
043 if (!AuthSettingsUtil.isNtlmEnabled(companyId)) {
044 return credentials;
045 }
046
047 String screenName = (String)request.getAttribute(
048 WebKeys.NTLM_REMOTE_USER);
049
050 if (screenName == null) {
051 return credentials;
052 }
053
054 request.removeAttribute(WebKeys.NTLM_REMOTE_USER);
055
056 User user = PortalLDAPImporterUtil.importLDAPUserByScreenName(
057 companyId, screenName);
058
059 if (user != null) {
060 String redirect = ParamUtil.getString(request, "redirect");
061
062 if (Validator.isNotNull(redirect)) {
063 request.setAttribute(
064 AutoLogin.AUTO_LOGIN_REDIRECT_AND_CONTINUE, redirect);
065 }
066
067 credentials = new String[3];
068
069 credentials[0] = String.valueOf(user.getUserId());
070 credentials[1] = user.getPassword();
071 credentials[2] = Boolean.TRUE.toString();
072 }
073 }
074 catch (Exception e) {
075 _log.error(e, e);
076 }
077
078 return credentials;
079 }
080
081 private static Log _log = LogFactoryUtil.getLog(NtlmAutoLogin.class);
082
083 }