1
22
23 package com.liferay.portlet.login.action;
24
25 import com.liferay.portal.CookieNotSupportedException;
26 import com.liferay.portal.NoSuchUserException;
27 import com.liferay.portal.PasswordExpiredException;
28 import com.liferay.portal.UserEmailAddressException;
29 import com.liferay.portal.UserIdException;
30 import com.liferay.portal.UserLockoutException;
31 import com.liferay.portal.UserPasswordException;
32 import com.liferay.portal.UserScreenNameException;
33 import com.liferay.portal.action.LoginAction;
34 import com.liferay.portal.kernel.util.Constants;
35 import com.liferay.portal.kernel.util.ParamUtil;
36 import com.liferay.portal.kernel.util.Validator;
37 import com.liferay.portal.security.auth.AuthException;
38 import com.liferay.portal.struts.ActionConstants;
39 import com.liferay.portal.struts.PortletAction;
40 import com.liferay.portal.theme.ThemeDisplay;
41 import com.liferay.portal.util.PortalUtil;
42 import com.liferay.portal.util.PropsValues;
43 import com.liferay.portal.util.WebKeys;
44 import com.liferay.util.servlet.SessionErrors;
45
46 import javax.portlet.ActionRequest;
47 import javax.portlet.ActionResponse;
48 import javax.portlet.PortletConfig;
49 import javax.portlet.RenderRequest;
50 import javax.portlet.RenderResponse;
51
52 import javax.servlet.http.HttpServletRequest;
53 import javax.servlet.http.HttpServletResponse;
54 import javax.servlet.jsp.PageContext;
55
56 import org.apache.struts.action.ActionForm;
57 import org.apache.struts.action.ActionForward;
58 import org.apache.struts.action.ActionMapping;
59
60
66 public class ViewAction extends PortletAction {
67
68 public void processAction(
69 ActionMapping mapping, ActionForm form, PortletConfig config,
70 ActionRequest req, ActionResponse res)
71 throws Exception {
72
73 String cmd = req.getParameter(Constants.CMD);
74
75 ThemeDisplay themeDisplay =
76 (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
77
78 if (req.getRemoteUser() != null) {
79 res.sendRedirect(themeDisplay.getPathMain());
80 }
81 else if (Validator.isNotNull(cmd)) {
82 try {
83 login(themeDisplay, req, res);
84 }
85 catch (Exception e) {
86 if (e instanceof AuthException) {
87 Throwable cause = e.getCause();
88
89 if (cause instanceof PasswordExpiredException ||
90 cause instanceof UserLockoutException) {
91
92 SessionErrors.add(req, cause.getClass().getName());
93 }
94 else {
95 SessionErrors.add(req, e.getClass().getName());
96 }
97 }
98 else if (e instanceof CookieNotSupportedException ||
99 e instanceof NoSuchUserException ||
100 e instanceof PasswordExpiredException ||
101 e instanceof UserEmailAddressException ||
102 e instanceof UserIdException ||
103 e instanceof UserLockoutException ||
104 e instanceof UserPasswordException ||
105 e instanceof UserScreenNameException) {
106
107 SessionErrors.add(req, e.getClass().getName());
108 }
109 else {
110 req.setAttribute(PageContext.EXCEPTION, e);
111
112 setForward(req, ActionConstants.COMMON_ERROR);
113 }
114 }
115 }
116 }
117
118 public ActionForward render(
119 ActionMapping mapping, ActionForm form, PortletConfig config,
120 RenderRequest req, RenderResponse res)
121 throws Exception {
122
123 return mapping.findForward("portlet.login.view");
124 }
125
126 protected void login(
127 ThemeDisplay themeDisplay, ActionRequest req, ActionResponse res)
128 throws Exception {
129
130 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
131 HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(res);
132
133 String login = ParamUtil.getString(req, "login");
134 String password = ParamUtil.getString(req, "password");
135 boolean rememberMe = ParamUtil.getBoolean(req, "rememberMe");
136
137 LoginAction.login(httpReq, httpRes, login, password, rememberMe);
138
139 if (PropsValues.PORTAL_JAAS_ENABLE) {
140 res.sendRedirect(themeDisplay.getPathMain() + "/portal/protected");
141 }
142 else {
143 String redirect = ParamUtil.getString(req, "redirect");
144
145 if (Validator.isNotNull(redirect)) {
146 res.sendRedirect(redirect);
147 }
148 else {
149 res.sendRedirect(themeDisplay.getPathMain());
150 }
151 }
152 }
153
154 }