1
22
23 package com.liferay.portal.action;
24
25 import com.liferay.portal.kernel.util.HttpUtil;
26 import com.liferay.portal.kernel.util.ParamUtil;
27 import com.liferay.portal.kernel.util.Validator;
28 import com.liferay.portal.theme.ThemeDisplay;
29 import com.liferay.portal.util.PortalUtil;
30 import com.liferay.portal.util.PortletKeys;
31 import com.liferay.portal.util.PropsValues;
32 import com.liferay.portal.util.WebKeys;
33 import com.liferay.portlet.PortletURLImpl;
34
35 import javax.portlet.PortletMode;
36 import javax.portlet.PortletRequest;
37 import javax.portlet.PortletURL;
38 import javax.portlet.WindowState;
39
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpServletResponse;
42 import javax.servlet.http.HttpSession;
43
44 import org.apache.struts.action.Action;
45 import org.apache.struts.action.ActionForm;
46 import org.apache.struts.action.ActionForward;
47 import org.apache.struts.action.ActionMapping;
48
49
55 public class LoginAction extends Action {
56
57 public ActionForward execute(
58 ActionMapping mapping, ActionForm form, HttpServletRequest request,
59 HttpServletResponse response)
60 throws Exception {
61
62 HttpSession session = request.getSession();
63
64 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
65 WebKeys.THEME_DISPLAY);
66
67 if (session.getAttribute("j_username") != null &&
68 session.getAttribute("j_password") != null) {
69
70 if (PropsValues.PORTAL_JAAS_ENABLE) {
71 return mapping.findForward("/portal/touch_protected.jsp");
72 }
73 else {
74 response.sendRedirect(themeDisplay.getPathMain());
75
76 return null;
77 }
78 }
79
80 String redirect = PortalUtil.getCommunityLoginURL(themeDisplay);
81
82 if (Validator.isNull(redirect)) {
83 redirect = PropsValues.AUTH_LOGIN_URL;
84 }
85
86 if (Validator.isNull(redirect)) {
87 PortletURL portletURL = new PortletURLImpl(
88 request, PortletKeys.LOGIN, themeDisplay.getPlid(),
89 PortletRequest.RENDER_PHASE);
90
91 portletURL.setWindowState(WindowState.MAXIMIZED);
92 portletURL.setPortletMode(PortletMode.VIEW);
93
94 portletURL.setParameter("saveLastPath", "0");
95 portletURL.setParameter("struts_action", "/login/login");
96
97 redirect = portletURL.toString();
98 }
99
100 if (PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS) {
101 redirect = HttpUtil.protocolize(redirect, true);
102 }
103
104 String loginRedirect = ParamUtil.getString(request, "redirect");
105
106 if (Validator.isNotNull(loginRedirect)) {
107 String loginPortletNamespace = PortalUtil.getPortletNamespace(
108 PropsValues.AUTH_LOGIN_PORTLET_NAME);
109
110 String loginRedirectParameter = loginPortletNamespace + "redirect";
111
112 redirect = HttpUtil.setParameter(
113 redirect, "p_p_id", PropsValues.AUTH_LOGIN_PORTLET_NAME);
114 redirect = HttpUtil.setParameter(redirect, "p_p_lifecycle", "0");
115 redirect = HttpUtil.setParameter(
116 redirect, loginRedirectParameter, loginRedirect);
117 }
118
119 response.sendRedirect(redirect);
120
121 return null;
122 }
123
124 }