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