Author: mputz
Date: 2013-01-02 09:31:40 -0500 (Wed, 02 Jan 2013)
New Revision: 9026
Modified:
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilterConfig.java
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java
Log:
Bug 861377 - Fix portlet access permissions, Performance improvements related to
PageTask.Load
Modified:
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java
===================================================================
---
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java 2012-12-25
06:56:24 UTC (rev 9025)
+++
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java 2013-01-02
14:31:40 UTC (rev 9026)
@@ -304,7 +304,7 @@
private void doFilter(int depth, NodeFilter filter)
{
- boolean accept = filter.accept(depth, getId(), name, getState());
+ boolean accept = filter.accept(depth, getId(), getName(), getState());
setHidden(!accept);
if (expanded)
{
Modified:
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java
===================================================================
---
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java 2012-12-25
06:56:24 UTC (rev 9025)
+++
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java 2013-01-02
14:31:40 UTC (rev 9026)
@@ -96,6 +96,10 @@
public boolean accept(int depth, String id, String name, NodeState state)
{
+ if (config.customFilter != null && !config.customFilter.accept(depth, id,
name, state))
+ {
+ return false;
+ }
Visibility visibility = state.getVisibility();
// Correct null -> displayed
Modified:
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilterConfig.java
===================================================================
---
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilterConfig.java 2012-12-25
06:56:24 UTC (rev 9025)
+++
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilterConfig.java 2013-01-02
14:31:40 UTC (rev 9026)
@@ -21,7 +21,7 @@
import org.exoplatform.commons.utils.Safe;
import org.exoplatform.portal.mop.Visibility;
-
+import org.exoplatform.portal.mop.navigation.NodeFilter;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
@@ -50,6 +50,9 @@
/** . */
final boolean temporalCheck;
+
+ /** . */
+ final NodeFilter customFilter;
public UserNodeFilterConfig(Builder builder)
{
@@ -62,6 +65,7 @@
this.visibility = Safe.unmodifiableSet(builder.withVisibility);
this.authorizationMode = builder.withAuthorizationMode;
this.temporalCheck = builder.withTemporalCheck;
+ this.customFilter = builder.withCustomFilter;
}
public Set<Visibility> getVisibility()
@@ -100,6 +104,9 @@
/** . */
private boolean withTemporalCheck;
+
+ /** . */
+ private NodeFilter withCustomFilter;
private Builder()
{
@@ -191,6 +198,12 @@
this.withAuthorizationMode = AUTH_NO_CHECK;
return this;
}
+
+ public Builder withCustomFilter(NodeFilter customFilter)
+ {
+ this.withCustomFilter = customFilter;
+ return this;
+ }
public UserNodeFilterConfig build()
{
Modified:
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java
===================================================================
---
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java 2012-12-25
06:56:24 UTC (rev 9025)
+++
epp/portal/branches/EPP_5_2_2_GA_BZ851985_BZ861377/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java 2013-01-02
14:31:40 UTC (rev 9026)
@@ -19,15 +19,19 @@
package org.exoplatform.portal.webui.page;
+import org.apache.commons.lang.StringUtils;
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.config.DataStorage;
import org.exoplatform.portal.config.UserPortalConfig;
+import org.exoplatform.portal.config.UserPortalConfigService;
import org.exoplatform.portal.config.model.Container;
import org.exoplatform.portal.config.model.ModelObject;
import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.SiteKey;
import org.exoplatform.portal.mop.SiteType;
+import org.exoplatform.portal.mop.navigation.NodeFilter;
+import org.exoplatform.portal.mop.navigation.NodeState;
import org.exoplatform.portal.mop.user.UserNavigation;
import org.exoplatform.portal.mop.user.UserNode;
import org.exoplatform.portal.mop.user.UserNodeFilterConfig;
@@ -36,6 +40,7 @@
import org.exoplatform.portal.webui.portal.PageNodeEvent;
import org.exoplatform.portal.webui.portal.UIPortal;
import org.exoplatform.portal.webui.util.PortalDataMapper;
+import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.portal.webui.workspace.UIPortalApplication;
import org.exoplatform.portal.webui.workspace.UIWorkingWorkspace;
import org.exoplatform.web.application.ApplicationMessage;
@@ -64,11 +69,17 @@
UIPortalApplication uiPortalApp = event.getSource();
UIPortal showedUIPortal = uiPortalApp.getCurrentSite();
- UserNodeFilterConfig.Builder builder = UserNodeFilterConfig.builder();
- builder.withReadCheck();
+
PageNodeEvent<UIPortalApplication> pageNodeEvent =
(PageNodeEvent<UIPortalApplication>)event;
String nodePath = pageNodeEvent.getTargetNodeUri();
+
+ UserNodeFilterConfig.Builder pathFilterBuild = UserNodeFilterConfig.builder();
+ pathFilterBuild.withReadCheck();
+ pathFilterBuild.withCustomFilter(new PathFilter(nodePath));
+
+ UserNodeFilterConfig.Builder defNodeBuild = UserNodeFilterConfig.builder();
+ defNodeBuild.withCustomFilter(new DefaultNodeFilter());
UserNode targetNode = null;
SiteKey siteKey = pageNodeEvent.getSiteKey();
@@ -77,13 +88,13 @@
UserNavigation navigation = userPortal.getNavigation(siteKey);
if (navigation != null)
{
- targetNode = userPortal.resolvePath(navigation, builder.build(),
nodePath);
+ targetNode = userPortal.resolvePath(navigation, pathFilterBuild.build(),
nodePath);
if (targetNode == null)
{
// If unauthenticated users have no permission on PORTAL node and URL
is valid, they will be required to login
if (pcontext.getRemoteUser() == null &&
siteKey.getType().equals(SiteType.PORTAL))
{
- targetNode = userPortal.resolvePath(navigation,
builder.withAuthMode(UserNodeFilterConfig.AUTH_NO_CHECK).build(), nodePath);
+ targetNode = userPortal.resolvePath(navigation, null, nodePath);
if (targetNode != null)
{
uiPortalApp.setLastRequestURI(null);
@@ -94,7 +105,7 @@
else
{
// If path to node is invalid, get the default node instead of.
- targetNode = userPortal.getDefaultPath(navigation,
builder.build());
+ targetNode = userPortal.getDefaultPath(navigation,
defNodeBuild.build());
}
}
}
@@ -102,7 +113,7 @@
if (targetNode == null)
{
- targetNode = userPortal.getDefaultPath(builder.build());
+ targetNode = userPortal.getDefaultPath(defNodeBuild.build());
if (targetNode == null)
{
if (showedUIPortal != null)
@@ -184,8 +195,84 @@
//Reset selected navigation on userPortalConfig
PortalDataMapper.toUIPortal(uiPortal, userPortalConfig.getPortalConfig());
return uiPortal;
+ }
+
+ private class PathFilter implements NodeFilter
+ {
+ private List<String> paths;
+
+ public PathFilter(String nodePath)
+ {
+ String[] tmp = StringUtils.split(nodePath, "/");
+
+ paths = new ArrayList<String>();
+ if (tmp != null)
+ {
+ for (String str : tmp)
+ {
+ if (str != null && !"".equals(str.trim()))
+ {
+ paths.add(str.trim());
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean accept(int depth, String id, String name, NodeState state)
+ {
+ return depth == 0 || (depth <= paths.size() && paths.get(depth
-1).equals(name));
+ }
}
- }
+
+ private class DefaultNodeFilter implements NodeFilter
+ {
+ private boolean found;
+
+ @Override
+ public boolean accept(int depth, String id, String name, NodeState state)
+ {
+ if (depth == 0)
+ {
+ return true;
+ }
+ else
+ {
+ if (found)
+ {
+ return false;
+ }
+ else
+ {
+ found = hasPermission(state.getPageRef());
+ return found;
+ }
+ }
+ }
+
+ private boolean hasPermission(String pageRef)
+ {
+ UIPortalApplication uiPortalApp = Util.getUIPortalApplication();
+ UserPortalConfigService service =
uiPortalApp.getApplicationComponent(UserPortalConfigService.class);
+ if (pageRef != null)
+ {
+ try
+ {
+ Page page = service.getPage(pageRef);
+ if (page != null)
+ {
+ return service.getUserACL().hasPermission(page);
+ }
+ }
+ catch (Exception e) {}
+ }
+ return false;
+ }
+ }
+ }
+
+
+
static public class DeleteGadgetActionListener extends EventListener<UIPage>
{