1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.events;
24  
25  import com.liferay.portal.kernel.events.Action;
26  import com.liferay.portal.kernel.events.ActionException;
27  import com.liferay.portal.model.Group;
28  import com.liferay.portal.model.Layout;
29  import com.liferay.portal.model.LayoutTypePortlet;
30  import com.liferay.portal.model.ReverseAjax;
31  import com.liferay.portal.service.GroupLocalServiceUtil;
32  import com.liferay.portal.service.LayoutLocalServiceUtil;
33  import com.liferay.portal.util.LiveUsers;
34  import com.liferay.portal.util.PortalUtil;
35  import com.liferay.portal.util.PropsValues;
36  import com.liferay.portal.util.WebKeys;
37  import com.liferay.portlet.messaging.util.MessagingUtil;
38  
39  import java.util.Iterator;
40  
41  import javax.servlet.http.HttpServletRequest;
42  import javax.servlet.http.HttpServletResponse;
43  import javax.servlet.http.HttpSession;
44  
45  import org.apache.commons.logging.Log;
46  import org.apache.commons.logging.LogFactory;
47  import org.apache.struts.Globals;
48  
49  /**
50   * <a href="LoginPostAction.java.html"><b><i>View Source</i></b></a>
51   *
52   * @author Brian Wing Shun Chan
53   *
54   */
55  public class LoginPostAction extends Action {
56  
57      public void run(HttpServletRequest req, HttpServletResponse res)
58          throws ActionException {
59  
60          try {
61              if (_log.isDebugEnabled()) {
62                  _log.debug("Running " + req.getRemoteUser());
63              }
64  
65              HttpSession ses = req.getSession();
66  
67              long companyId = PortalUtil.getCompanyId(req);
68              long userId = PortalUtil.getUserId(req);
69  
70              if (PropsValues.REVERSE_AJAX_ENABLED) {
71                  ses.setAttribute(WebKeys.REVERSE_AJAX, new ReverseAjax());
72              }
73  
74              MessagingUtil.createXMPPConnection(ses, userId);
75  
76              LiveUsers.signIn(req);
77  
78              if (!PropsValues.LAYOUT_REMEMBER_SESSION_WINDOW_STATE_MAXIMIZED) {
79                  Group group = GroupLocalServiceUtil.getUserGroup(
80                      companyId, userId);
81  
82                  Iterator itr = LayoutLocalServiceUtil.getLayouts(
83                      group.getGroupId(), true).iterator();
84  
85                  while (itr.hasNext()) {
86                      Layout layout = (Layout)itr.next();
87  
88                      LayoutTypePortlet layoutType =
89                          (LayoutTypePortlet)layout.getLayoutType();
90  
91                      if (layoutType.hasStateMax()) {
92  
93                          // Set the window state to normal for the maximized
94                          // portlet
95  
96                          layoutType.resetStates();
97  
98                          // Set the portlet mode to view because other modes may
99                          // require a maximized window state
100 
101                         layoutType.resetModes();
102 
103                         LayoutLocalServiceUtil.updateLayout(
104                             layout.getGroupId(), layout.isPrivateLayout(),
105                             layout.getLayoutId(), layout.getTypeSettings());
106                     }
107                 }
108             }
109 
110             // Reset the locale
111 
112             ses.removeAttribute(Globals.LOCALE_KEY);
113         }
114         catch (Exception e) {
115             throw new ActionException(e);
116         }
117     }
118 
119     private static Log _log = LogFactory.getLog(LoginPostAction.class);
120 
121 }