From 0d623e4f3e42f3ee37f3fbe590a9fbd62bb47068 Mon Sep 17 00:00:00 2001 From: Boubaker Khanfir Date: Thu, 15 Mar 2018 11:20:31 +0100 Subject: [PATCH] PLF-7928 Cache stream owner attribute in request --- .../exoplatform/social/webui/URLUtils.java | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/component/webui/src/main/java/org/exoplatform/social/webui/URLUtils.java b/component/webui/src/main/java/org/exoplatform/social/webui/URLUtils.java index 5e4cff2e16..c16cc13144 100644 --- a/component/webui/src/main/java/org/exoplatform/social/webui/URLUtils.java +++ b/component/webui/src/main/java/org/exoplatform/social/webui/URLUtils.java @@ -16,6 +16,9 @@ */ package org.exoplatform.social.webui; +import org.apache.commons.lang.StringUtils; + +import org.exoplatform.commons.utils.CommonsUtils; import org.exoplatform.container.ExoContainer; import org.exoplatform.container.ExoContainerContext; import org.exoplatform.portal.application.PortalRequestContext; @@ -36,6 +39,7 @@ */ public class URLUtils { + private static final String STREAM_OWNER_ID = "streamOwnerId"; private static Log LOG = ExoLogger.getLogger(UISocialGroupSelector.class); private static String ROOT_NODE_NAME = "default"; @@ -46,20 +50,40 @@ public class URLUtils { */ public static String getCurrentUser() { PortalRequestContext pcontext = Util.getPortalRequestContext() ; + String currentUserName = (String) pcontext.getAttribute(STREAM_OWNER_ID); + if (currentUserName != null) { + if (StringUtils.EMPTY.equals(currentUserName)) { + return null; + } else { + return currentUserName; + } + } String requestPath = "/" + pcontext.getControllerContext().getParameter(RequestNavigationData.REQUEST_PATH); Route route = ExoRouter.route(requestPath); if (route == null) { return null; } - String currentUserName = route.localArgs.get("streamOwnerId"); - ExoContainer container = ExoContainerContext.getCurrentContainer(); - IdentityManager idm = (IdentityManager) container.getComponentInstanceOfType(IdentityManager.class); + currentUserName = route.localArgs.get(STREAM_OWNER_ID); try { if (currentUserName != null) { + IdentityManager idm = CommonsUtils.getService(IdentityManager.class); + // Workaround in case ;jsessionid is added to URL + if (currentUserName.contains(";")) { + currentUserName = currentUserName.split(";")[0]; + } Identity id = idm.getOrCreateIdentity(OrganizationIdentityProvider.NAME, currentUserName, false); - if (id != null) return currentUserName; + if (id != null) { + pcontext.setAttribute(STREAM_OWNER_ID, currentUserName); + return currentUserName; + } else { + pcontext.setAttribute(STREAM_OWNER_ID, StringUtils.EMPTY); + return null; + } + } else { + pcontext.setAttribute(STREAM_OWNER_ID, StringUtils.EMPTY); + return null; } } catch (Exception e) { if(LOG.isDebugEnabled()) { @@ -67,7 +91,6 @@ public static String getCurrentUser() { } return null; } - return null; } /**