001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.login.action;
022:
023: import com.liferay.portal.CookieNotSupportedException;
024: import com.liferay.portal.NoSuchUserException;
025: import com.liferay.portal.PasswordExpiredException;
026: import com.liferay.portal.UserEmailAddressException;
027: import com.liferay.portal.UserIdException;
028: import com.liferay.portal.UserLockoutException;
029: import com.liferay.portal.UserPasswordException;
030: import com.liferay.portal.UserScreenNameException;
031: import com.liferay.portal.action.LoginAction;
032: import com.liferay.portal.kernel.util.Constants;
033: import com.liferay.portal.kernel.util.ParamUtil;
034: import com.liferay.portal.kernel.util.Validator;
035: import com.liferay.portal.security.auth.AuthException;
036: import com.liferay.portal.struts.ActionConstants;
037: import com.liferay.portal.struts.PortletAction;
038: import com.liferay.portal.theme.ThemeDisplay;
039: import com.liferay.portal.util.PortalUtil;
040: import com.liferay.portal.util.PropsValues;
041: import com.liferay.portal.util.WebKeys;
042: import com.liferay.util.servlet.SessionErrors;
043:
044: import javax.portlet.ActionRequest;
045: import javax.portlet.ActionResponse;
046: import javax.portlet.PortletConfig;
047: import javax.portlet.RenderRequest;
048: import javax.portlet.RenderResponse;
049:
050: import javax.servlet.http.HttpServletRequest;
051: import javax.servlet.http.HttpServletResponse;
052: import javax.servlet.jsp.PageContext;
053:
054: import org.apache.struts.action.ActionForm;
055: import org.apache.struts.action.ActionForward;
056: import org.apache.struts.action.ActionMapping;
057:
058: /**
059: * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
060: *
061: * @author Brian Wing Shun Chan
062: *
063: */
064: public class ViewAction extends PortletAction {
065:
066: public void processAction(ActionMapping mapping, ActionForm form,
067: PortletConfig config, ActionRequest req, ActionResponse res)
068: throws Exception {
069:
070: String cmd = req.getParameter(Constants.CMD);
071:
072: ThemeDisplay themeDisplay = (ThemeDisplay) req
073: .getAttribute(WebKeys.THEME_DISPLAY);
074:
075: if (req.getRemoteUser() != null) {
076: res.sendRedirect(themeDisplay.getPathMain());
077: } else if (Validator.isNotNull(cmd)) {
078: try {
079: login(themeDisplay, req, res);
080: } catch (Exception e) {
081: if (e instanceof AuthException) {
082: Throwable cause = e.getCause();
083:
084: if (cause instanceof PasswordExpiredException
085: || cause instanceof UserLockoutException) {
086:
087: SessionErrors.add(req, cause.getClass()
088: .getName());
089: } else {
090: SessionErrors.add(req, e.getClass().getName());
091: }
092: } else if (e instanceof CookieNotSupportedException
093: || e instanceof NoSuchUserException
094: || e instanceof PasswordExpiredException
095: || e instanceof UserEmailAddressException
096: || e instanceof UserIdException
097: || e instanceof UserLockoutException
098: || e instanceof UserPasswordException
099: || e instanceof UserScreenNameException) {
100:
101: SessionErrors.add(req, e.getClass().getName());
102: } else {
103: req.setAttribute(PageContext.EXCEPTION, e);
104:
105: setForward(req, ActionConstants.COMMON_ERROR);
106: }
107: }
108: }
109: }
110:
111: public ActionForward render(ActionMapping mapping, ActionForm form,
112: PortletConfig config, RenderRequest req, RenderResponse res)
113: throws Exception {
114:
115: return mapping.findForward("portlet.login.view");
116: }
117:
118: protected void login(ThemeDisplay themeDisplay, ActionRequest req,
119: ActionResponse res) throws Exception {
120:
121: HttpServletRequest httpReq = PortalUtil
122: .getHttpServletRequest(req);
123: HttpServletResponse httpRes = PortalUtil
124: .getHttpServletResponse(res);
125:
126: String login = ParamUtil.getString(req, "login");
127: String password = ParamUtil.getString(req, "password");
128: boolean rememberMe = ParamUtil.getBoolean(req, "rememberMe");
129:
130: LoginAction
131: .login(httpReq, httpRes, login, password, rememberMe);
132:
133: if (PropsValues.PORTAL_JAAS_ENABLE) {
134: res.sendRedirect(themeDisplay.getPathMain()
135: + "/portal/protected");
136: } else {
137: res.sendRedirect(themeDisplay.getPathMain());
138: }
139: }
140:
141: }
|