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
56 public class LoginAction extends Action {
57
58 public ActionForward execute(
59 ActionMapping mapping, ActionForm form, HttpServletRequest request,
60 HttpServletResponse response)
61 throws Exception {
62
63 HttpSession session = request.getSession();
64
65 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
66 WebKeys.THEME_DISPLAY);
67
68 if (session.getAttribute("j_username") != null &&
69 session.getAttribute("j_password") != null) {
70
71 if (PropsValues.PORTAL_JAAS_ENABLE) {
72 return mapping.findForward("/portal/touch_protected.jsp");
73 }
74 else {
75 response.sendRedirect(themeDisplay.getPathMain());
76
77 return null;
78 }
79 }
80
81 String redirect = PortalUtil.getCommunityLoginURL(themeDisplay);
82
83 if (Validator.isNull(redirect)) {
84 redirect = PropsValues.AUTH_LOGIN_URL;
85 }
86
87 if (Validator.isNull(redirect)) {
88 PortletURL portletURL = new PortletURLImpl(
89 request, PortletKeys.LOGIN, themeDisplay.getPlid(),
90 PortletRequest.RENDER_PHASE);
91
92 portletURL.setWindowState(WindowState.MAXIMIZED);
93 portletURL.setPortletMode(PortletMode.VIEW);
94
95 portletURL.setParameter("saveLastPath", "0");
96 portletURL.setParameter("struts_action", "/login/login");
97
98 redirect = portletURL.toString();
99 }
100
101 if (PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS) {
102 redirect = HttpUtil.protocolize(redirect, true);
103 }
104
105 String loginRedirect = ParamUtil.getString(request, "redirect");
106
107 if (Validator.isNotNull(loginRedirect)) {
108 String loginPortletNamespace = PortalUtil.getPortletNamespace(
109 PropsValues.AUTH_LOGIN_PORTLET_NAME);
110
111 String loginRedirectParameter = loginPortletNamespace + "redirect";
112
113 redirect = HttpUtil.setParameter(
114 redirect, "p_p_id", PropsValues.AUTH_LOGIN_PORTLET_NAME);
115 redirect = HttpUtil.setParameter(redirect, "p_p_lifecycle", "0");
116 redirect = HttpUtil.setParameter(
117 redirect, loginRedirectParameter, loginRedirect);
118 }
119
120 response.sendRedirect(redirect);
121
122 return null;
123 }
124
125 }