01: /**
02: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * furnished to do so, subject to the following conditions:
10: *
11: * The above copyright notice and this permission notice shall be included in
12: * all copies or substantial portions of the Software.
13: *
14: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20: * SOFTWARE.
21: */package com.liferay.portal.security.auth;
22:
23: import com.liferay.portal.kernel.util.GetterUtil;
24: import com.liferay.portal.kernel.util.ParamUtil;
25: import com.liferay.portal.kernel.util.Validator;
26: import com.liferay.portal.model.Company;
27: import com.liferay.portal.model.impl.CompanyImpl;
28: import com.liferay.portal.service.UserLocalServiceUtil;
29: import com.liferay.portal.util.PortalUtil;
30:
31: import javax.servlet.http.HttpServletRequest;
32: import javax.servlet.http.HttpServletResponse;
33:
34: /**
35: * <a href="ParameterAutoLogin.java.html"><b><i>View Source</i></b></a>
36: *
37: * @author Minhchau Dang
38: *
39: */
40: public class ParameterAutoLogin implements AutoLogin {
41:
42: public String[] login(HttpServletRequest req,
43: HttpServletResponse res) throws AutoLoginException {
44:
45: try {
46: String login = ParamUtil.getString(req, getLoginParam());
47:
48: if (Validator.isNull(login)) {
49: return null;
50: }
51:
52: String password = ParamUtil.getString(req,
53: getPasswordParam());
54:
55: if (Validator.isNull(password)) {
56: return null;
57: }
58:
59: Company company = PortalUtil.getCompany(req);
60:
61: String authType = company.getAuthType();
62:
63: long userId = 0;
64:
65: if (authType.equals(CompanyImpl.AUTH_TYPE_EA)) {
66: userId = UserLocalServiceUtil.getUserIdByEmailAddress(
67: company.getCompanyId(), login);
68: } else if (authType.equals(CompanyImpl.AUTH_TYPE_SN)) {
69: userId = UserLocalServiceUtil.getUserIdByScreenName(
70: company.getCompanyId(), login);
71: } else if (authType.equals(CompanyImpl.AUTH_TYPE_ID)) {
72: userId = GetterUtil.getLong(login);
73: } else {
74: return null;
75: }
76:
77: String[] credentials = new String[] {
78: String.valueOf(userId), password,
79: Boolean.FALSE.toString() };
80:
81: return credentials;
82: } catch (Exception e) {
83: throw new AutoLoginException(e);
84: }
85: }
86:
87: protected String getLoginParam() {
88: return _LOGIN_PARAM;
89: }
90:
91: protected String getPasswordParam() {
92: return _PASSWORD_PARAM;
93: }
94:
95: private static final String _LOGIN_PARAM = "parameterAutoLoginLogin";
96:
97: private static final String _PASSWORD_PARAM = "parameterAutoLoginPassword";
98:
99: }
|