mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Fix authentication, upload and download to handle generic JSR-168 portals - means we can run against Liferay and other portals besides JBoss
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3188 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -62,7 +62,7 @@ public class Application
|
||||
|
||||
public static final String MESSAGE_BUNDLE = "alfresco.messages.webclient";
|
||||
|
||||
private static ThreadLocal<Boolean> inPortalServer = new ThreadLocal<Boolean>();
|
||||
private static boolean inPortalServer = false;
|
||||
private static StoreRef repoStoreRef;
|
||||
private static String rootPath;
|
||||
private static String companyRootId;
|
||||
@@ -88,7 +88,7 @@ public class Application
|
||||
*/
|
||||
public static void setInPortalServer(boolean inPortal)
|
||||
{
|
||||
inPortalServer.set(inPortal);
|
||||
inPortalServer = inPortal;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +98,7 @@ public class Application
|
||||
*/
|
||||
public static boolean inPortalServer()
|
||||
{
|
||||
return (inPortalServer.get() != null ? inPortalServer.get() : false);
|
||||
return inPortalServer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package org.alfresco.web.app;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -35,7 +36,6 @@ import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.web.app.portlet.AlfrescoFacesPortlet;
|
||||
import org.alfresco.web.app.servlet.AuthenticationHelper;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.bean.repository.User;
|
||||
@@ -164,7 +164,8 @@ public class ContextListener implements ServletContextListener, HttpSessionListe
|
||||
*/
|
||||
public void sessionCreated(HttpSessionEvent event)
|
||||
{
|
||||
if (logger.isDebugEnabled()) logger.debug("HTTP session created: " + event.getSession().getId());
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("HTTP session created: " + event.getSession().getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,27 +173,42 @@ public class ContextListener implements ServletContextListener, HttpSessionListe
|
||||
*/
|
||||
public void sessionDestroyed(HttpSessionEvent event)
|
||||
{
|
||||
if (logger.isDebugEnabled()) logger.debug("HTTP session destroyed: " + event.getSession().getId());
|
||||
|
||||
String userKey;
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("HTTP session destroyed: " + event.getSession().getId());
|
||||
|
||||
String userKey = null;
|
||||
if (Application.inPortalServer() == false)
|
||||
{
|
||||
userKey = AuthenticationHelper.AUTHENTICATION_USER;
|
||||
}
|
||||
else
|
||||
{
|
||||
userKey = AlfrescoFacesPortlet.MANAGED_BEAN_PREFIX + AuthenticationHelper.AUTHENTICATION_USER;
|
||||
// search for the user object in the portlet wrapped session keys
|
||||
// each vendor uses a different naming scheme so we search by hand
|
||||
String userKeyPostfix = "?" + AuthenticationHelper.AUTHENTICATION_USER;
|
||||
Enumeration enumNames = event.getSession().getAttributeNames();
|
||||
while (enumNames.hasMoreElements())
|
||||
{
|
||||
String name = (String)enumNames.nextElement();
|
||||
if (name.endsWith(userKeyPostfix))
|
||||
{
|
||||
userKey = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
User user = (User)event.getSession().getAttribute(userKey);
|
||||
if (user != null)
|
||||
if (userKey != null)
|
||||
{
|
||||
// invalidate ticket and clear the Security context for this thread
|
||||
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
|
||||
AuthenticationService authService = (AuthenticationService)ctx.getBean("authenticationService");
|
||||
authService.invalidateTicket(user.getTicket());
|
||||
authService.clearCurrentSecurityContext();
|
||||
event.getSession().removeAttribute(userKey);
|
||||
User user = (User)event.getSession().getAttribute(userKey);
|
||||
if (user != null)
|
||||
{
|
||||
// invalidate ticket and clear the Security context for this thread
|
||||
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
|
||||
AuthenticationService authService = (AuthenticationService)ctx.getBean("authenticationService");
|
||||
authService.invalidateTicket(user.getTicket());
|
||||
authService.clearCurrentSecurityContext();
|
||||
event.getSession().removeAttribute(userKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -63,8 +63,6 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
public class AlfrescoFacesPortlet extends MyFacesGenericPortlet
|
||||
{
|
||||
private static final String PREF_ALF_USERNAME = "_alfUserName";
|
||||
public static final String INSTANCE_NAME = "AlfrescoClientInstance";
|
||||
public static final String MANAGED_BEAN_PREFIX = "javax.portlet.p." + INSTANCE_NAME + "?";
|
||||
|
||||
private static final String ERROR_PAGE_PARAM = "error-page";
|
||||
private static final String ERROR_OCCURRED = "error-occurred";
|
||||
@@ -165,11 +163,9 @@ public class AlfrescoFacesPortlet extends MyFacesGenericPortlet
|
||||
LoginBean loginBean = (LoginBean)request.getPortletSession().getAttribute(AuthenticationHelper.LOGIN_BEAN);
|
||||
if (loginBean != null)
|
||||
{
|
||||
//
|
||||
// TODO: Need to login to JBoss Portal to get a user here to store prefs against
|
||||
// TODO: Need to login to the Portal to get a user here to store prefs against
|
||||
// so not really a suitable solution as they get thrown away at present!
|
||||
// Also would need to store prefs PER user - so auto login for each...?
|
||||
//
|
||||
String oldValue = request.getPreferences().getValue(PREF_ALF_USERNAME, null);
|
||||
if (oldValue == null || oldValue.equals(loginBean.getUsernameInternal()) == false)
|
||||
{
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package org.alfresco.web.app.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.portlet.PortletSession;
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -39,7 +40,6 @@ import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.app.portlet.AlfrescoFacesPortlet;
|
||||
import org.alfresco.web.bean.LoginBean;
|
||||
import org.alfresco.web.bean.repository.User;
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -78,6 +78,9 @@ public final class AuthenticationHelper
|
||||
/** cookie names */
|
||||
private static final String COOKIE_ALFUSER = "alfUser";
|
||||
|
||||
/** portal mode key name */
|
||||
private static ThreadLocal<String> portalUserKeyName = new ThreadLocal<String>();
|
||||
|
||||
private static Log logger = LogFactory.getLog(AuthenticationHelper.class);
|
||||
|
||||
|
||||
@@ -98,7 +101,7 @@ public final class AuthenticationHelper
|
||||
HttpSession session = httpRequest.getSession();
|
||||
|
||||
// examine the appropriate session for our User object
|
||||
User user;
|
||||
User user = null;
|
||||
LoginBean loginBean = null;
|
||||
if (Application.inPortalServer() == false)
|
||||
{
|
||||
@@ -107,9 +110,28 @@ public final class AuthenticationHelper
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: this prefix is not consistent between JSR-168 vendors!
|
||||
// we need a solution for each vendor?
|
||||
user = (User)session.getAttribute(AlfrescoFacesPortlet.MANAGED_BEAN_PREFIX + AUTHENTICATION_USER);
|
||||
// naff solution as we need to enumerate all session keys until we find the one that
|
||||
// should match our User objects - this is weak but we don't know how the underlying
|
||||
// Portal vendor has decided to encode the objects in the session
|
||||
if (portalUserKeyName.get() == null)
|
||||
{
|
||||
String userKeyPostfix = "?" + AUTHENTICATION_USER;
|
||||
Enumeration enumNames = session.getAttributeNames();
|
||||
while (enumNames.hasMoreElements())
|
||||
{
|
||||
String name = (String)enumNames.nextElement();
|
||||
if (name.endsWith(userKeyPostfix))
|
||||
{
|
||||
// cache the key value once found!
|
||||
portalUserKeyName.set(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (portalUserKeyName.get() != null)
|
||||
{
|
||||
user = (User)session.getAttribute(portalUserKeyName.get());
|
||||
}
|
||||
}
|
||||
|
||||
// setup the authentication context
|
||||
|
@@ -23,19 +23,14 @@
|
||||
<%@ page isELIgnored="false" %>
|
||||
<%@ page import="javax.faces.context.FacesContext" %>
|
||||
<%@ page import="org.alfresco.web.app.Application" %>
|
||||
<%@ page import="org.alfresco.web.app.portlet.AlfrescoFacesPortlet" %>
|
||||
<%@ page import="org.alfresco.web.bean.content.AddContentDialog" %>
|
||||
<%@ page import="org.alfresco.web.app.servlet.FacesHelper" %>
|
||||
<%@ page import="org.alfresco.web.ui.common.PanelGenerator" %>
|
||||
|
||||
<%
|
||||
boolean fileUploaded = false;
|
||||
|
||||
AddContentDialog dialog = (AddContentDialog)session.getAttribute(AlfrescoFacesPortlet.MANAGED_BEAN_PREFIX + "AddContentDialog");
|
||||
if (dialog == null)
|
||||
{
|
||||
dialog = (AddContentDialog)session.getAttribute("AddContentDialog");
|
||||
}
|
||||
|
||||
AddContentDialog dialog = (AddContentDialog)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "AddContentDialog");
|
||||
if (dialog != null && dialog.getFileName() != null)
|
||||
{
|
||||
fileUploaded = true;
|
||||
|
@@ -23,7 +23,7 @@
|
||||
<%@ page buffer="32kb" contentType="text/html;charset=UTF-8" %>
|
||||
<%@ page isELIgnored="false" %>
|
||||
<%@ page import="org.alfresco.web.ui.common.PanelGenerator" %>
|
||||
<%@ page import="org.alfresco.web.app.portlet.AlfrescoFacesPortlet" %>
|
||||
<%@ page import="org.alfresco.web.app.servlet.FacesHelper" %>
|
||||
<%@ page import="org.alfresco.web.bean.CheckinCheckoutBean" %>
|
||||
<%@ page import="org.alfresco.web.app.Application" %>
|
||||
<%@ page import="javax.faces.context.FacesContext" %>
|
||||
@@ -192,11 +192,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
<%
|
||||
CheckinCheckoutBean bean = (CheckinCheckoutBean)session.getAttribute(AlfrescoFacesPortlet.MANAGED_BEAN_PREFIX + "CheckinCheckoutBean");
|
||||
if (bean == null)
|
||||
{
|
||||
bean = (CheckinCheckoutBean)session.getAttribute("CheckinCheckoutBean");
|
||||
}
|
||||
CheckinCheckoutBean bean = (CheckinCheckoutBean)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "CheckinCheckoutBean");
|
||||
if (bean != null && bean.getFileName() != null) {
|
||||
%>
|
||||
<tr><td class="paddingRow"></td></tr>
|
||||
|
@@ -24,7 +24,7 @@
|
||||
<%@ page isELIgnored="false" %>
|
||||
<%@ page import="org.alfresco.web.ui.common.PanelGenerator" %>
|
||||
<%@ page import="org.alfresco.web.bean.ImportBean" %>
|
||||
<%@ page import="org.alfresco.web.app.portlet.AlfrescoFacesPortlet" %>
|
||||
<%@ page import="org.alfresco.web.app.servlet.FacesHelper" %>
|
||||
<%@ page import="org.alfresco.web.app.Application" %>
|
||||
<%@ page import="javax.faces.context.FacesContext" %>
|
||||
|
||||
@@ -129,11 +129,7 @@
|
||||
<h:form acceptCharset="UTF-8" id="import-upload-end">
|
||||
<tr><td class="paddingRow"></td></tr>
|
||||
<%
|
||||
ImportBean bean = (ImportBean)session.getAttribute(AlfrescoFacesPortlet.MANAGED_BEAN_PREFIX + "ImportDialog");
|
||||
if (bean == null)
|
||||
{
|
||||
bean = (ImportBean)session.getAttribute("ImportDialog");
|
||||
}
|
||||
ImportBean bean = (ImportBean)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "ImportDialog");
|
||||
if (bean != null && bean.getFileName() != null) {
|
||||
%>
|
||||
<tr>
|
||||
|
@@ -23,7 +23,7 @@
|
||||
<%@ page buffer="32kb" contentType="text/html;charset=UTF-8" %>
|
||||
<%@ page isELIgnored="false" %>
|
||||
<%@ page import="org.alfresco.web.ui.common.PanelGenerator" %>
|
||||
<%@ page import="org.alfresco.web.app.portlet.AlfrescoFacesPortlet" %>
|
||||
<%@ page import="org.alfresco.web.app.servlet.FacesHelper" %>
|
||||
<%@ page import="org.alfresco.web.bean.CheckinCheckoutBean" %>
|
||||
<%@ page import="org.alfresco.web.app.Application" %>
|
||||
<%@ page import="javax.faces.context.FacesContext" %>
|
||||
@@ -127,11 +127,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
<%
|
||||
CheckinCheckoutBean bean = (CheckinCheckoutBean)session.getAttribute(AlfrescoFacesPortlet.MANAGED_BEAN_PREFIX + "CheckinCheckoutBean");
|
||||
if (bean == null)
|
||||
{
|
||||
bean = (CheckinCheckoutBean)session.getAttribute("CheckinCheckoutBean");
|
||||
}
|
||||
CheckinCheckoutBean bean = (CheckinCheckoutBean)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "CheckinCheckoutBean");
|
||||
if (bean != null && bean.getFileName() != null) {
|
||||
%>
|
||||
<tr>
|
||||
|
@@ -24,8 +24,8 @@
|
||||
<%@ page isELIgnored="false" %>
|
||||
<%@ page import="org.alfresco.web.ui.common.PanelGenerator" %>
|
||||
<%@ page import="org.alfresco.web.bean.wizard.AddContentWizard" %>
|
||||
<%@ page import="org.alfresco.web.app.portlet.AlfrescoFacesPortlet" %>
|
||||
<%@ page import="org.alfresco.web.app.Application" %>
|
||||
<%@ page import="org.alfresco.web.app.servlet.FacesHelper" %>
|
||||
<%@ page import="javax.faces.context.FacesContext" %>
|
||||
|
||||
<r:page titleId="title_add_content_upload">
|
||||
@@ -146,13 +146,9 @@
|
||||
</r:uploadForm>
|
||||
|
||||
<h:form acceptCharset="UTF-8" id="add-content-upload-end">
|
||||
<tr><td class="paddingRow"></td></tr>
|
||||
<tr><td class="paddingRow">===TEST JSP===</td></tr>
|
||||
<%
|
||||
AddContentWizard wiz = (AddContentWizard)session.getAttribute(AlfrescoFacesPortlet.MANAGED_BEAN_PREFIX + "AddContentWizard");
|
||||
if (wiz == null)
|
||||
{
|
||||
wiz = (AddContentWizard)session.getAttribute("AddContentWizard");
|
||||
}
|
||||
AddContentWizard wiz = (AddContentWizard)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "AddContentWizard");
|
||||
if (wiz != null && wiz.getFileName() != null) {
|
||||
%>
|
||||
<tr>
|
||||
|
Reference in New Issue
Block a user