Author: phuong_vu
Date: 2010-11-16 06:29:42 -0500 (Tue, 16 Nov 2010)
New Revision: 5104
Modified:
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java
exo/portal/branches/3.1.x/examples/extension/war/src/main/webapp/login/jsp/login.jsp
exo/portal/branches/3.1.x/examples/extension/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl
exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/login/jsp/login.jsp
exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl
exo/portal/branches/3.1.x/web/portal/src/main/webapp/login/jsp/login.jsp
Log:
EXOGTN-86 Problem with session in difference war file, need to change way way to redirect
to initialURI (now, not use HttpSession anymore)
Modified:
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java
===================================================================
---
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java 2010-11-16
10:27:49 UTC (rev 5103)
+++
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java 2010-11-16
11:29:42 UTC (rev 5104)
@@ -69,8 +69,32 @@
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
{
Modified:
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java
===================================================================
---
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java 2010-11-16
10:27:49 UTC (rev 5103)
+++
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java 2010-11-16
11:29:42 UTC (rev 5104)
@@ -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:
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java
===================================================================
---
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java 2010-11-16
10:27:49 UTC (rev 5103)
+++
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java 2010-11-16
11:29:42 UTC (rev 5104)
@@ -19,13 +19,6 @@
package org.exoplatform.web.login;
-import org.exoplatform.container.web.AbstractHttpServlet;
-import org.exoplatform.web.security.Credentials;
-import org.exoplatform.web.security.security.AbstractTokenService;
-import org.exoplatform.web.security.security.CookieTokenService;
-import org.gatein.common.logging.Logger;
-import org.gatein.common.logging.LoggerFactory;
-
import java.io.IOException;
import javax.servlet.ServletException;
@@ -33,6 +26,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.exoplatform.container.web.AbstractHttpServlet;
+import org.exoplatform.web.security.Credentials;
+import org.exoplatform.web.security.security.AbstractTokenService;
+import org.exoplatform.web.security.security.CookieTokenService;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+
/**
* @author <a href="mailto:trong.tran@exoplatform.com">Tran The
Trong</a>
* @version $Revision$
@@ -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:
exo/portal/branches/3.1.x/examples/extension/war/src/main/webapp/login/jsp/login.jsp
===================================================================
---
exo/portal/branches/3.1.x/examples/extension/war/src/main/webapp/login/jsp/login.jsp 2010-11-16
10:27:49 UTC (rev 5103)
+++
exo/portal/branches/3.1.x/examples/extension/war/src/main/webapp/login/jsp/login.jsp 2010-11-16
11:29:42 UTC (rev 5104)
@@ -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:
exo/portal/branches/3.1.x/examples/extension/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl
===================================================================
---
exo/portal/branches/3.1.x/examples/extension/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl 2010-11-16
10:27:49 UTC (rev 5103)
+++
exo/portal/branches/3.1.x/examples/extension/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl 2010-11-16
11:29:42 UTC (rev 5104)
@@ -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&password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Administrator")%></a></div>
+ <div class="AccountTitle"><a
href="${_ctx.getPortalContextPath()}/login?username=root&password=gtn&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&password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Manager")%></a></div>
+ <div class="AccountTitle"><a
href="${_ctx.getPortalContextPath()}/login?username=john&password=gtn&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&password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.User")%></a></div>
+ <div class="AccountTitle"><a
href="${_ctx.getPortalContextPath()}/login?username=mary&password=gtn&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&password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Demo")%></a></div>
+ <div class="AccountTitle"><a
href="${_ctx.getPortalContextPath()}/login?username=demo&password=gtn&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:
exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/login/jsp/login.jsp
===================================================================
---
exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/login/jsp/login.jsp 2010-11-16
10:27:49 UTC (rev 5103)
+++
exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/login/jsp/login.jsp 2010-11-16
11:29:42 UTC (rev 5104)
@@ -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:
exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl
===================================================================
---
exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl 2010-11-16
10:27:49 UTC (rev 5103)
+++
exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/templates/groovy/webui/component/UIHomePagePortlet.gtmpl 2010-11-16
11:29:42 UTC (rev 5104)
@@ -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&password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Administrator")%></a></div>
+ <div class="AccountTitle"><a
href="${_ctx.getPortalContextPath()}/login?username=root&password=gtn&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&password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Manager")%></a></div>
+ <div class="AccountTitle"><a
href="${_ctx.getPortalContextPath()}/login?username=john&password=gtn&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&password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.User")%></a></div>
+ <div class="AccountTitle"><a
href="${_ctx.getPortalContextPath()}/login?username=mary&password=gtn&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&password=gtn"><%=_ctx.appRes("UIHomePagePortlet.Label.Demo")%></a></div>
+ <div class="AccountTitle"><a
href="${_ctx.getPortalContextPath()}/login?username=demo&password=gtn&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: exo/portal/branches/3.1.x/web/portal/src/main/webapp/login/jsp/login.jsp
===================================================================
--- exo/portal/branches/3.1.x/web/portal/src/main/webapp/login/jsp/login.jsp 2010-11-16
10:27:49 UTC (rev 5103)
+++ exo/portal/branches/3.1.x/web/portal/src/main/webapp/login/jsp/login.jsp 2010-11-16
11:29:42 UTC (rev 5104)
@@ -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,8 @@
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");
%>