[gatein-commits] gatein SVN: r5107 - in portal/branches/branch-GTNPORTAL-1643: examples/extension/war/src/main/webapp/login/jsp and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Nov 16 07:49:09 EST 2010


Author: phuong_vu
Date: 2010-11-16 07:49:08 -0500 (Tue, 16 Nov 2010)
New Revision: 5107

Modified:
   portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java
   portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java
   portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/PortalLoginController.java
   portal/branches/branch-GTNPORTAL-1643/examples/extension/war/src/main/webapp/login/jsp/login.jsp
   portal/branches/branch-GTNPORTAL-1643/examples/extension/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl
   portal/branches/branch-GTNPORTAL-1643/examples/portal/war/src/main/webapp/login/jsp/login.jsp
   portal/branches/branch-GTNPORTAL-1643/examples/portal/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl
   portal/branches/branch-GTNPORTAL-1643/web/portal/src/main/webapp/login/jsp/login.jsp
Log:
GTNPORTAL-1594 Problem with session in difference war file, need to change way way to control the initialURI (now, not use HttpSession anymore)

Modified: portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java	2010-11-16 12:23:34 UTC (rev 5106)
+++ portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java	2010-11-16 12:49:08 UTC (rev 5107)
@@ -71,9 +71,33 @@
       resp.setContentType("text/html; charset=UTF-8");
       
       // This allows the customer to define another login page without changing the portal
-      context.getRequestDispatcher("/login/jsp/login.jsp").include(req, resp);
+      showLoginForm(req, resp);
    }
 
+   private void showLoginForm(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+   {
+      String initialURI = (String)req.getAttribute("javax.servlet.forward.request_uri");
+      if (initialURI == null)
+      {
+         throw new IllegalStateException("request attribute javax.servlet.forward.request_uri should not be null here");
+      }
+      int jsecurityIndex = initialURI.lastIndexOf("/j_security_check");
+      if (jsecurityIndex != -1)
+      {
+         initialURI = initialURI.substring(0, jsecurityIndex);
+      }
+
+      try
+      {
+         req.setAttribute("org.gatein.portal.login.initial_uri", initialURI);
+         getServletContext().getRequestDispatcher("/login/jsp/login.jsp").include(req, resp);
+      }
+      finally
+      {
+         req.removeAttribute("org.gatein.portal.login.initial_uri");
+      }
+   }
+
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
       doGet(req, resp);

Modified: portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java	2010-11-16 12:23:34 UTC (rev 5106)
+++ portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java	2010-11-16 12:49:08 UTC (rev 5107)
@@ -96,7 +96,7 @@
                // Send authentication request
                log.debug("Login initiated with no credentials in session but found token " + token + " with existing credentials, " +
                   "performing authentication");
-               sendAuth(resp, credentials.getUsername(), token);
+               sendAuth(req, resp, credentials.getUsername(), token);
             }
          }
          else
@@ -116,36 +116,47 @@
 
          // Send authentication request
          log.debug("Login initiated with credentials in session, performing authentication");
-         sendAuth(resp, credentials.getUsername(), token);
+         sendAuth(req, resp, credentials.getUsername(), token);
       }
    }
 
    private void showLoginForm(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
-      String initialURI = (String)req.getAttribute("javax.servlet.forward.request_uri");
-      if (initialURI == null)
-      {
-         throw new IllegalStateException("request attribute javax.servlet.forward.request_uri should not be null here");
-      }
+      String initialURI = getInitialURI(req);
       try
       {
-         req.getSession(true).setAttribute("org.gatein.portal.login.initial_uri", initialURI);
+         req.setAttribute("org.gatein.portal.login.initial_uri", initialURI);
          getServletContext().getRequestDispatcher("/login/jsp/login.jsp").include(req, resp);
       }
       finally
       {
-         req.getSession(true).removeAttribute("org.gatein.portal.login.initial_uri");
+         req.removeAttribute("org.gatein.portal.login.initial_uri");
       }
    }
 
+   private String getInitialURI(HttpServletRequest req)
+   {
+      String initialURI = (String)req.getAttribute("javax.servlet.forward.request_uri");
+      if (initialURI == null)
+      {
+         throw new IllegalStateException("request attribute javax.servlet.forward.request_uri should not be null here");
+      }
+      return initialURI;
+   }
+
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
       doGet(req, resp);
    }
 
-   private void sendAuth(HttpServletResponse resp, String jUsername, String jPassword) throws IOException
+   private void sendAuth(HttpServletRequest req, HttpServletResponse resp, String jUsername, String jPassword) throws IOException
    {
-      String url = "j_security_check?j_username=" + jUsername + "&j_password=" + jPassword;
+      String initialURI = getInitialURI(req);
+      if (!initialURI.endsWith("/"))
+      {
+         initialURI += "/";
+      }
+      String url = initialURI + "j_security_check?j_username=" + jUsername + "&j_password=" + jPassword;
       url = resp.encodeRedirectURL(url);
       resp.sendRedirect(url);
    }

Modified: portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/PortalLoginController.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/PortalLoginController.java	2010-11-16 12:23:34 UTC (rev 5106)
+++ portal/branches/branch-GTNPORTAL-1643/component/web/security/src/main/java/org/exoplatform/web/login/PortalLoginController.java	2010-11-16 12:49:08 UTC (rev 5107)
@@ -79,7 +79,6 @@
       else
       {
          log.debug("Found initial URI " + uri);
-         req.getSession(true).setAttribute("org.gatein.portal.login.initial_uri", uri);
       }
 
       // if we do have a remember me

Modified: portal/branches/branch-GTNPORTAL-1643/examples/extension/war/src/main/webapp/login/jsp/login.jsp
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/examples/extension/war/src/main/webapp/login/jsp/login.jsp	2010-11-16 12:23:34 UTC (rev 5106)
+++ portal/branches/branch-GTNPORTAL-1643/examples/extension/war/src/main/webapp/login/jsp/login.jsp	2010-11-16 12:49:08 UTC (rev 5107)
@@ -26,7 +26,6 @@
 <%@ page import="java.util.ResourceBundle"%>
 <%@ page import="org.exoplatform.web.login.InitiateLoginServlet"%>
 <%@ page import="org.gatein.common.text.EntityEncoder"%>
-<%@ page import="javax.servlet.http.HttpSession"%>
 <%@ page language="java" %>
 <%@ page contentType="text/html; charset=utf-8" %>
 <%
@@ -41,9 +40,7 @@
   ResourceBundleService service = (ResourceBundleService) portalContainer.getComponentInstanceOfType(ResourceBundleService.class);
   ResourceBundle res = service.getResourceBundle(service.getSharedResourceBundleNames(), request.getLocale()) ;
   
-   HttpSession httpSession = request.getSession(true);
-   String uri = (String)httpSession.getAttribute("org.gatein.portal.login.initial_uri");
-   httpSession.removeAttribute("org.gatein.portal.login.initial_uri");
+  String uri = (String)request.getAttribute("org.gatein.portal.login.initial_uri");
 
   Cookie cookie = new Cookie(InitiateLoginServlet.COOKIE_NAME, "");
 	cookie.setPath(request.getContextPath());

Modified: portal/branches/branch-GTNPORTAL-1643/examples/extension/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/examples/extension/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl	2010-11-16 12:23:34 UTC (rev 5106)
+++ portal/branches/branch-GTNPORTAL-1643/examples/extension/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl	2010-11-16 12:49:08 UTC (rev 5107)
@@ -1,3 +1,6 @@
+<%
+	String initialURI = _ctx.getRequestContext().getParentAppRequestContext().getRequestContextPath() + "/private/" + _ctx.getRequestContext().getParentAppRequestContext().getPortalOwner();
+%>
 <div class="UIHomePagePortlet" id="$uicomponent.id">
 	<div class="TRContainer">
 		<div class="PortletDecoration">					
@@ -28,7 +31,7 @@
 							<div class="AccountsContainerDeco">
 								<div class="AccountBlock AdministratorUser">
 									<div class="AccountInfos">
-										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=root&amp;password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Administrator")%></a></div>
+										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=root&amp;password=gtn&amp;initialURI=<%=initialURI%>"><%=_ctx.appRes("UIHomePagePortlet.Label.Administrator")%></a></div>
 										<div class="Username">
 											<div class="Lable"><%=_ctx.appRes("UIHomePagePortlet.Label.Username")%></div><span>root</span>
 											<div class="ClearBoth"><span></span></div>
@@ -42,7 +45,7 @@
 								<div class="SeparatorLine"><span></span></div>
 								<div class="AccountBlock ManagerUser">
 									<div class="AccountInfos">
-										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=john&amp;password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Manager")%></a></div>
+										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=john&amp;password=gtn&amp;initialURI=<%=initialURI%>"><%=_ctx.appRes("UIHomePagePortlet.Label.Manager")%></a></div>
 										<div class="Username">
 											<div class="Lable"><%=_ctx.appRes("UIHomePagePortlet.Label.Username")%></div><span>john</span>
 											<div class="ClearBoth"><span></span></div>
@@ -56,7 +59,7 @@
 								<div class="SeparatorLine"><span></span></div>
 								<div class="AccountBlock NormalUser">
 									<div class="AccountInfos">
-										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=mary&amp;password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.User")%></a></div>
+										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=mary&amp;password=gtn&amp;initialURI=<%=initialURI%>"><%=_ctx.appRes("UIHomePagePortlet.Label.User")%></a></div>
 										<div class="Username">
 											<div class="Lable"><%=_ctx.appRes("UIHomePagePortlet.Label.Username")%></div><span>mary</span>
 											<div class="ClearBoth"><span></span></div>
@@ -70,7 +73,7 @@
 								<div class="SeparatorLine"><span></span></div>
 								<div class="AccountBlock DemoUser" style="margin-right: 0px;">
 									<div class="AccountInfos">
-										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=demo&amp;password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Demo")%></a></div>
+										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=demo&amp;password=gtn&amp;initialURI=<%=initialURI%>"><%=_ctx.appRes("UIHomePagePortlet.Label.Demo")%></a></div>
 										<div class="Username">
 											<div class="Lable"><%=_ctx.appRes("UIHomePagePortlet.Label.Username")%></div><span>demo</span>
 											<div class="ClearBoth"><span></span></div>

Modified: portal/branches/branch-GTNPORTAL-1643/examples/portal/war/src/main/webapp/login/jsp/login.jsp
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/examples/portal/war/src/main/webapp/login/jsp/login.jsp	2010-11-16 12:23:34 UTC (rev 5106)
+++ portal/branches/branch-GTNPORTAL-1643/examples/portal/war/src/main/webapp/login/jsp/login.jsp	2010-11-16 12:49:08 UTC (rev 5107)
@@ -26,7 +26,6 @@
 <%@ page import="java.util.ResourceBundle"%>
 <%@ page import="org.exoplatform.web.login.InitiateLoginServlet"%>
 <%@ page import="org.gatein.common.text.EntityEncoder"%>
-<%@ page import="javax.servlet.http.HttpSession"%>
 <%@ page language="java" %>
 <%@ page contentType="text/html; charset=utf-8" %>
 <%
@@ -41,9 +40,7 @@
   ResourceBundleService service = (ResourceBundleService) portalContainer.getComponentInstanceOfType(ResourceBundleService.class);
   ResourceBundle res = service.getResourceBundle(service.getSharedResourceBundleNames(), request.getLocale()) ;
   
-   HttpSession httpSession = request.getSession(true);
-   String uri = (String)httpSession.getAttribute("org.gatein.portal.login.initial_uri");
-   httpSession.removeAttribute("org.gatein.portal.login.initial_uri");
+  String uri = (String)request.getAttribute("org.gatein.portal.login.initial_uri");
 
   Cookie cookie = new Cookie(InitiateLoginServlet.COOKIE_NAME, "");
 	cookie.setPath(request.getContextPath());

Modified: portal/branches/branch-GTNPORTAL-1643/examples/portal/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/examples/portal/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl	2010-11-16 12:23:34 UTC (rev 5106)
+++ portal/branches/branch-GTNPORTAL-1643/examples/portal/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl	2010-11-16 12:49:08 UTC (rev 5107)
@@ -1,3 +1,6 @@
+<%
+	String initialURI = _ctx.getRequestContext().getParentAppRequestContext().getRequestContextPath() + "/private/" + _ctx.getRequestContext().getParentAppRequestContext().getPortalOwner();
+%>
 <div class="UIHomePagePortlet" id="$uicomponent.id">
 	<div class="TRContainer">
 		<div class="PortletDecoration">					
@@ -33,7 +36,7 @@
 							<div class="AccountsContainerDeco">
 								<div class="AccountBlock AdministratorUser">
 									<div class="AccountInfos">
-										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=root&amp;password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Administrator")%></a></div>
+										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=root&amp;password=gtn&amp;initialURI=<%=initialURI%>"><%=_ctx.appRes("UIHomePagePortlet.Label.Administrator")%></a></div>
 										<div class="Username">
 											<div class="Lable"><%=_ctx.appRes("UIHomePagePortlet.Label.Username")%></div><span>root</span>
 											<div class="ClearBoth"><span></span></div>
@@ -47,7 +50,7 @@
 								<div class="SeparatorLine"><span></span></div>
 								<div class="AccountBlock ManagerUser">
 									<div class="AccountInfos">
-										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=john&amp;password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Manager")%></a></div>
+										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=john&amp;password=gtn&amp;initialURI=<%=initialURI%>"><%=_ctx.appRes("UIHomePagePortlet.Label.Manager")%></a></div>
 										<div class="Username">
 											<div class="Lable"><%=_ctx.appRes("UIHomePagePortlet.Label.Username")%></div><span>john</span>
 											<div class="ClearBoth"><span></span></div>
@@ -61,7 +64,7 @@
 								<div class="SeparatorLine"><span></span></div>
 								<div class="AccountBlock NormalUser">
 									<div class="AccountInfos">
-										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=mary&amp;password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.User")%></a></div>
+										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=mary&amp;password=gtn&amp;initialURI=<%=initialURI%>"><%=_ctx.appRes("UIHomePagePortlet.Label.User")%></a></div>
 										<div class="Username">
 											<div class="Lable"><%=_ctx.appRes("UIHomePagePortlet.Label.Username")%></div><span>mary</span>
 											<div class="ClearBoth"><span></span></div>
@@ -75,7 +78,7 @@
 								<div class="SeparatorLine"><span></span></div>
 								<div class="AccountBlock DemoUser" style="margin-right: 0px;">
 									<div class="AccountInfos">
-										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=demo&amp;password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Demo")%></a></div>
+										<div class="AccountTitle"><a href="${_ctx.getPortalContextPath()}/login?username=demo&amp;password=gtn&amp;initialURI=<%=initialURI%>"><%=_ctx.appRes("UIHomePagePortlet.Label.Demo")%></a></div>
 										<div class="Username">
 											<div class="Lable"><%=_ctx.appRes("UIHomePagePortlet.Label.Username")%></div><span>demo</span>
 											<div class="ClearBoth"><span></span></div>

Modified: portal/branches/branch-GTNPORTAL-1643/web/portal/src/main/webapp/login/jsp/login.jsp
===================================================================
--- portal/branches/branch-GTNPORTAL-1643/web/portal/src/main/webapp/login/jsp/login.jsp	2010-11-16 12:23:34 UTC (rev 5106)
+++ portal/branches/branch-GTNPORTAL-1643/web/portal/src/main/webapp/login/jsp/login.jsp	2010-11-16 12:49:08 UTC (rev 5107)
@@ -26,7 +26,6 @@
 <%@ page import="java.util.ResourceBundle"%>
 <%@ page import="org.exoplatform.web.login.InitiateLoginServlet"%>
 <%@ page import="org.gatein.common.text.EntityEncoder"%>
-<%@ page import="javax.servlet.http.HttpSession"%>
 <%@ page language="java" %>
 <%
   String contextPath = request.getContextPath() ;
@@ -45,9 +44,7 @@
 	cookie.setMaxAge(0);
 	response.addCookie(cookie);
 
-  HttpSession httpSession = request.getSession(true);
-  String uri = (String)httpSession.getAttribute("org.gatein.portal.login.initial_uri");
-  httpSession.removeAttribute("org.gatein.portal.login.initial_uri");
+  String uri = (String)request.getAttribute("org.gatein.portal.login.initial_uri");
 
   response.setCharacterEncoding("UTF-8"); 
   response.setContentType("text/html; charset=UTF-8");



More information about the gatein-commits mailing list