001
014
015 package com.liferay.portal.security.auth;
016
017 import com.liferay.portal.kernel.exception.SystemException;
018 import com.liferay.portal.kernel.util.PropsKeys;
019 import com.liferay.portal.kernel.util.StringPool;
020 import com.liferay.portal.kernel.util.Validator;
021 import com.liferay.portal.model.Company;
022 import com.liferay.portal.model.CompanyConstants;
023 import com.liferay.portal.model.User;
024 import com.liferay.portal.security.ldap.PortalLDAPImporterUtil;
025 import com.liferay.portal.service.UserLocalServiceUtil;
026 import com.liferay.portal.util.PortalUtil;
027 import com.liferay.portal.util.PrefsPropsUtil;
028 import com.liferay.portal.util.PropsValues;
029
030 import javax.servlet.http.HttpServletRequest;
031 import javax.servlet.http.HttpServletResponse;
032
033
037 public class SiteMinderAutoLogin extends BaseAutoLogin {
038
039 @Override
040 protected String[] doLogin(
041 HttpServletRequest request, HttpServletResponse response)
042 throws Exception {
043
044 Company company = PortalUtil.getCompany(request);
045
046 long companyId = company.getCompanyId();
047
048 if (!AuthSettingsUtil.isSiteMinderEnabled(companyId)) {
049 return null;
050 }
051
052 String siteMinderUserHeader = request.getHeader(
053 PrefsPropsUtil.getString(
054 companyId, PropsKeys.SITEMINDER_USER_HEADER,
055 PropsValues.SITEMINDER_USER_HEADER));
056
057 if (Validator.isNull(siteMinderUserHeader)) {
058 return null;
059 }
060
061 String authType = company.getAuthType();
062
063 User user = null;
064
065 if (PrefsPropsUtil.getBoolean(
066 companyId, PropsKeys.SITEMINDER_IMPORT_FROM_LDAP,
067 PropsValues.SITEMINDER_IMPORT_FROM_LDAP)) {
068
069 try {
070 if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
071 user = PortalLDAPImporterUtil.importLDAPUser(
072 companyId, siteMinderUserHeader, StringPool.BLANK);
073 }
074 else {
075 user = PortalLDAPImporterUtil.importLDAPUser(
076 companyId, StringPool.BLANK, siteMinderUserHeader);
077 }
078 }
079 catch (SystemException se) {
080 }
081 }
082
083 if (user == null) {
084 if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
085 user = UserLocalServiceUtil.fetchUserByEmailAddress(
086 companyId, siteMinderUserHeader);
087 }
088 else {
089 user = UserLocalServiceUtil.fetchUserByScreenName(
090 companyId, siteMinderUserHeader);
091 }
092 }
093
094 String[] credentials = new String[3];
095
096 credentials[0] = String.valueOf(user.getUserId());
097 credentials[1] = user.getPassword();
098 credentials[2] = Boolean.TRUE.toString();
099
100 return credentials;
101 }
102
103 }