Author: rwatler
Date: Mon Mar 8 03:57:37 2010
New Revision: 920192
URL: http://svn.apache.org/viewvc?rev=920192&view=rev
Log:
JS2-1117: integrate portal site with non-profiled physical site view into
PageValveImpl to supply standard menus, content mapping, and fallback rules
capabilities
Added:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/AbstractPageValveImpl.java
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/PageProfilerValve.java
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/PageValveImpl.java
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/profiler/impl/ProfilerValveImpl.java
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/PageProfilerValve.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/PageProfilerValve.java?rev=920192&r1=920191&r2=920192&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/PageProfilerValve.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/PageProfilerValve.java
Mon Mar 8 03:57:37 2010
@@ -30,7 +30,7 @@
* </ul>
*
* <br>
- * Note: The primary purpose of this interface is primary for documention.
+ * Note: The primary purpose of this interface is primary for documentation.
*
* @author <a href="mailto:[email protected]">Paul Spencer</a>
* @version $Id$
@@ -39,6 +39,28 @@
*/
public interface PageProfilerValve extends Valve
{
- String PROFILE_LOCATOR_REQUEST_ATTR_KEY =
"org.apache.jetspeed.profiler.ProfileLocator";
- String PROFILE_LOCATORS_PER_PRINCIPAL =
"org.apache.jetspeed.profiler.ProfileLocatorsPrincipal";
+ /**
+ * PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY - session portal site context
attribute key
+ */
+ static String PORTAL_SITE_SESSION_CONTEXT_ATTR_KEY =
"org.apache.jetspeed.portalsite.PortalSiteSessionContext";
+
+ /**
+ * PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY - request portal site context
attribute key
+ */
+ static String PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY =
"org.apache.jetspeed.portalsite.PortalSiteRequestContext";
+
+ /**
+ * PROFILED_PAGE_CONTEXT_ATTR_KEY - legacy request portal site context
attribute key
+ */
+ static String PROFILED_PAGE_CONTEXT_ATTR_KEY =
"org.apache.jetspeed.profiledPageContext";
+
+ /**
+ * PAGE_ACTION_ACCESS_MAP_SESSION_ATTR_KEY - PageActionAccess instances
map attribute key
+ */
+ static String PAGE_ACTION_ACCESS_MAP_SESSION_ATTR_KEY =
"org.apache.jetspeed.profiler.pageActionAccessMap";
+
+ /**
+ * PROFILE_LOCATOR_REQUEST_ATTR_KEY - request override for profile locator
attribute key
+ */
+ static String PROFILE_LOCATOR_REQUEST_ATTR_KEY =
"org.apache.jetspeed.profiler.ProfileLocator";
}
Added:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/AbstractPageValveImpl.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/AbstractPageValveImpl.java?rev=920192&view=auto
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/AbstractPageValveImpl.java
(added)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/AbstractPageValveImpl.java
Mon Mar 8 03:57:37 2010
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.pipeline.valve.impl;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.decoration.PageActionAccess;
+import org.apache.jetspeed.layout.PageLayoutComponent;
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.page.BaseConcretePageElement;
+import org.apache.jetspeed.om.page.ContentPage;
+import org.apache.jetspeed.om.page.PageTemplate;
+import org.apache.jetspeed.page.document.NodeNotFoundException;
+import org.apache.jetspeed.pipeline.PipelineException;
+import org.apache.jetspeed.pipeline.valve.AbstractValve;
+import org.apache.jetspeed.pipeline.valve.PageProfilerValve;
+import org.apache.jetspeed.pipeline.valve.ValveContext;
+import org.apache.jetspeed.portalsite.PortalSite;
+import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
+import org.apache.jetspeed.profiler.ProfilerException;
+import org.apache.jetspeed.request.RequestContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract page valve common implementation.
+ *
+ * @author <a href="mailto:[email protected]">Randy Watler</a>
+ * @version $Id$
+ */
+public abstract class AbstractPageValveImpl extends AbstractValve implements
PageProfilerValve
+{
+ protected Logger log =
LoggerFactory.getLogger(AbstractPageValveImpl.class);
+
+ /**
+ * portalSite - portal site component
+ */
+ protected PortalSite portalSite;
+
+ /**
+ * requestFallback - flag indicating whether request should fallback to
closest
+ * intermediate or root folder if locators do not select
a page
+ * or access is forbidden; if set, forbidden and not
found
+ * response status codes are avoided if at all possible:
do not
+ * set if 403s and 404s are expected to be returned by
the portal
+ */
+ protected boolean requestFallback;
+
+ /**
+ * useHistory - flag indicating whether to use visited page
+ * history to select default page per site folder
+ */
+ protected boolean useHistory;
+
+ /**
+ * pageLayoutComponent - component used to construct and maintain
ContentPage from
+ * profiled PSML Pages and Fragments.
+ */
+ protected PageLayoutComponent pageLayoutComponent;
+
+ /**
+ * AbstractPageValveImpl - constructor
+ *
+ * @param portalSite portal site component reference
+ * @param pageLayoutComponent page layout component reference
+ * @param requestFallback flag to enable root folder fallback
+ * @param useHistory flag to enable selection of last visited folder page
+ */
+ public AbstractPageValveImpl(PortalSite portalSite, PageLayoutComponent
pageLayoutComponent,
+ boolean requestFallback, boolean useHistory)
+ {
+ this.portalSite = portalSite;
+ this.pageLayoutComponent = pageLayoutComponent;
+ this.requestFallback = requestFallback;
+ this.useHistory = useHistory;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.jetspeed.pipeline.valve.AbstractValve#invoke(org.apache.jetspeed.request.RequestContext,
org.apache.jetspeed.pipeline.valve.ValveContext)
+ */
+ public void invoke(RequestContext request, ValveContext context) throws
PipelineException
+ {
+ try
+ {
+ // get request path
+ String requestPath = request.getPath();
+ if ((requestPath != null) && (requestPath.length() > 0))
+ {
+ if (!requestPath.startsWith(Folder.PATH_SEPARATOR))
+ {
+ requestPath = Folder.PATH_SEPARATOR+requestPath;
+ }
+ }
+ else
+ {
+ requestPath = Folder.PATH_SEPARATOR;
+ }
+ if (log.isDebugEnabled())
+ {
+ log.debug("Request path: "+requestPath);
+ }
+
+ // get request page and set page action access
+ setRequestPage(request, requestPath);
+ ContentPage requestPage = request.getPage();
+ if (requestPage != null)
+ {
+
request.setAttribute(PortalReservedParameters.PAGE_EDIT_ACCESS_ATTRIBUTE,
getPageActionAccess(request));
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("Page path: "+requestPage.getPath());
+ }
+ }
+ else
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("No page found for request path: "+requestPath);
+ }
+ }
+
+ // continue
+ if (context != null)
+ {
+ context.invokeNext(request);
+ }
+ }
+ catch (SecurityException se)
+ {
+ // fallback to root folder/default page
+ if (requestFallback)
+ {
+ // fallback to portal root folder/default page if
+ // no user is available and request path is not
+ // already attempting to access the root folder;
+ // this is rarely the case since the anonymous
+ // user is normally defined unless the default
+ // security system has been replaced/overridden
+ if ((request.getRequest().getUserPrincipal() == null) &&
(request.getPath() != null) && !request.getPath().equals("/"))
+ {
+ try
+ {
+
request.getResponse().sendRedirect(request.getRequest().getContextPath());
+ }
+ catch (IOException ioe)
+ {
+ }
+ return;
+ }
+ }
+
+ // return standard HTTP 403 - FORBIDDEN status
+ log.error(se.getMessage(), se);
+ try
+ {
+
request.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN,
se.getMessage());
+ }
+ catch (IOException ioe)
+ {
+ log.error("Failed to invoke HttpServletReponse.sendError: " +
ioe.getMessage(), ioe);
+ }
+ }
+ catch (NodeNotFoundException nnfe)
+ {
+ // return standard HTTP 404 - NOT FOUND status
+ log.error(nnfe.getMessage(), nnfe);
+ try
+ {
+
request.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND,
nnfe.getMessage());
+ }
+ catch (IOException ioe)
+ {
+ log.error("Failed to invoke HttpServletReponse.sendError: " +
ioe.getMessage(), ioe);
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("Exception in request pipeline: " + e.getMessage(), e);
+ throw new PipelineException(e.toString(), e);
+ }
+ }
+
+ /**
+ * Set request page and associated session and request attributes
+ * based on request and derived valve implementations.
+ *
+ * @param request invoked request
+ * @param requestPath invoked request path
+ */
+ protected abstract void setRequestPage(RequestContext request, String
requestPath) throws NodeNotFoundException, ProfilerException;
+
+ /**
+ * Set request page and associated session and request attributes
+ * based on portal site request context constructed by derived valve
+ * implementations.
+ *
+ * @param request invoked request
+ * @param requestPath invoked request path
+ * @param requestContext portal site request context
+ */
+ protected void setRequestPage(RequestContext request, String requestPath,
PortalSiteRequestContext requestContext) throws NodeNotFoundException
+ {
+ // save request context
+ request.setAttribute(PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY,
requestContext);
+
+ // additionally save request context under legacy key
+ // to support existing decorator access
+ request.setAttribute(PROFILED_PAGE_CONTEXT_ATTR_KEY, requestContext);
+
+ // get request page from portal site request context;
+ // accessing the request context here and in subsequent
+ // valves/decorators latently selects the page and builds
+ // menus from the user site view; the managed page accessed
+ // here is the raw selected page as returned by the
+ // page manager component; accessing the managed page here
+ // selects the current page for the request
+ BaseConcretePageElement managedPage = requestContext.getManagedPage();
+ PageTemplate managedPageTemplate =
requestContext.getManagedPageTemplate();
+ Map managedFragmentDefinitions =
requestContext.getManagedFragmentDefinitions();
+ ContentPage contentPage =
pageLayoutComponent.newContentPage(managedPage, managedPageTemplate,
managedFragmentDefinitions);
+ request.setPage(contentPage);
+ request.setProfileLocators(requestContext.getLocators());
+
+ // save original request for down stream content portlets
+ if (requestContext.isContentPage())
+ {
+ request.setAttribute(PortalReservedParameters.PATH_ATTRIBUTE,
requestPath);
+
request.setAttribute(PortalReservedParameters.CONTENT_PATH_ATTRIBUTE,
requestContext.getPageContentPath());
+ }
+ }
+
+ /**
+ * Returns the <code>PageActionAccess</code> for the current user request.
+ * @see PageActionAccess
+ * @param requestContext RequestContext of the current portal request.
+ * @return PageActionAccess for the current user request.
+ */
+ protected PageActionAccess getPageActionAccess(RequestContext
requestContext)
+ {
+ ContentPage page = requestContext.getPage();
+ String key = page.getId();
+ boolean loggedOn = requestContext.getRequest().getUserPrincipal() !=
null;
+ boolean anonymous = !loggedOn;
+ PageActionAccess pageActionAccess = null;
+
+ Map sessionActions = null;
+ synchronized (this)
+ {
+ sessionActions = (Map)
requestContext.getSessionAttribute(PAGE_ACTION_ACCESS_MAP_SESSION_ATTR_KEY);
+ if (sessionActions == null)
+ {
+ sessionActions = new HashMap();
+
requestContext.setSessionAttribute(PAGE_ACTION_ACCESS_MAP_SESSION_ATTR_KEY,
sessionActions);
+ }
+ else
+ {
+ pageActionAccess = (PageActionAccess) sessionActions.get(key);
+ }
+ }
+ synchronized (sessionActions)
+ {
+ if (pageActionAccess == null)
+ {
+ pageActionAccess = new PageActionAccess(anonymous, page);
+ sessionActions.put(key, pageActionAccess);
+ }
+ else
+ {
+ pageActionAccess.checkReset(anonymous, page);
+ }
+ }
+
+ return pageActionAccess;
+ }
+}
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/PageValveImpl.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/PageValveImpl.java?rev=920192&r1=920191&r2=920192&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/PageValveImpl.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/valve/impl/PageValveImpl.java
Mon Mar 8 03:57:37 2010
@@ -16,281 +16,105 @@
*/
package org.apache.jetspeed.pipeline.valve.impl;
-import java.io.IOException;
-import java.security.Principal;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.security.auth.Subject;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.jetspeed.PortalReservedParameters;
-import org.apache.jetspeed.administration.AdminUtil;
-import org.apache.jetspeed.decoration.PageActionAccess;
import org.apache.jetspeed.layout.PageLayoutComponent;
-import org.apache.jetspeed.om.folder.Folder;
-import org.apache.jetspeed.om.page.ContentPage;
-import org.apache.jetspeed.om.page.BaseConcretePageElement;
-import org.apache.jetspeed.om.page.Page;
-import org.apache.jetspeed.om.page.PageTemplate;
-import org.apache.jetspeed.page.PageManager;
-import org.apache.jetspeed.page.document.NodeException;
import org.apache.jetspeed.page.document.NodeNotFoundException;
-import org.apache.jetspeed.page.document.NodeSet;
-import org.apache.jetspeed.pipeline.PipelineException;
-import org.apache.jetspeed.pipeline.valve.AbstractValve;
import org.apache.jetspeed.pipeline.valve.PageProfilerValve;
-import org.apache.jetspeed.pipeline.valve.ValveContext;
import org.apache.jetspeed.portalsite.PortalSite;
import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
import org.apache.jetspeed.portalsite.PortalSiteSessionContext;
-import org.apache.jetspeed.profiler.ProfileLocator;
-import org.apache.jetspeed.profiler.Profiler;
import org.apache.jetspeed.profiler.ProfilerException;
import org.apache.jetspeed.request.RequestContext;
-import org.apache.jetspeed.security.SubjectHelper;
-import org.apache.jetspeed.security.User;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
- * Page Valve locates the page from the portal request without profiling
operations using a 1:1 URL:path location algorithm
+ * Page Valve locates the page from the portal request without profiling
+ * operations using a 1:1 URL:path location algorithm
*
* @author <a href="mailto:[email protected]">David Sean Taylor </a>
* @version $Id$
*/
-public class PageValveImpl extends AbstractValve implements PageProfilerValve
+public class PageValveImpl extends AbstractPageValveImpl implements
PageProfilerValve
{
- protected Logger log = LoggerFactory.getLogger(PageValveImpl.class);
-
-
/**
- * pageLayoutComponent - component used to construct and maintain
ContentPage from
- * profiled PSML Pages and Fragments.
+ * PageValveImpl - constructor
+ *
+ * @param portalSite portal site component reference
+ * @param pageLayoutComponent page layout component reference
+ * @param requestFallback flag to enable root folder fallback
+ * @param useHistory flag to enable selection of last visited folder page
*/
- private PageLayoutComponent pageLayoutComponent;
+ public PageValveImpl(PortalSite portalSite, PageLayoutComponent
pageLayoutComponent, boolean requestFallback, boolean useHistory)
+ {
+ super(portalSite, pageLayoutComponent, requestFallback, useHistory);
+ }
/**
- *
+ * PageValveImpl - constructor
+ *
+ * @param portalSite portal site component reference
+ * @param pageLayoutComponent page layout component reference
+ * @param requestFallback flag to enable root folder fallback
*/
- private PageManager pageManager;
-
- public PageValveImpl(PageManager pageManager, PageLayoutComponent
pageLayoutComponent)
+ public PageValveImpl(PortalSite portalSite, PageLayoutComponent
pageLayoutComponent, boolean requestFallback)
{
- this.pageManager = pageManager;
- this.pageLayoutComponent = pageLayoutComponent;
+ this(portalSite, pageLayoutComponent, requestFallback, true);
}
- public void invoke( RequestContext request, ValveContext context ) throws
PipelineException
+ /**
+ * PageValveImpl - constructor
+ *
+ * @param portalSite portal site component reference
+ * @param pageLayoutComponent page layout component reference
+ */
+ public PageValveImpl(PortalSite portalSite, PageLayoutComponent
pageLayoutComponent)
{
- try
- {
- String requestPath = request.getPath();
- if (log.isDebugEnabled())
- {
- log.debug("Request path: "+requestPath);
- }
- if (requestPath == null)
- {
- requestPath = Folder.PATH_SEPARATOR;
- }
- if (!requestPath.endsWith(Page.DOCUMENT_TYPE)) // FIXME: handle
dynamic pages, pages not ending with .psml
- {
- Folder folder = pageManager.getFolder(requestPath);
- String defaultPage = folder.getDefaultPage();
- if (defaultPage == null)
- {
- List<String> docs = folder.getDocumentOrder();
- if (docs != null || docs.size() > 0)
- {
- for (String doc: docs)
- {
- if
(doc.endsWith(Page.DOCUMENT_TYPE))
- {
- defaultPage = doc;
- break;
- }
- }
- }
- if (defaultPage == null)
- defaultPage =
Folder.FALLBACK_DEFAULT_PAGE;
- }
- requestPath = AdminUtil.concatenatePaths(requestPath,
defaultPage);
- }
- Page page = pageManager.getPage(requestPath);
-
- // get profiler locators for request subject/principal using the
profiler
- Subject subject = request.getSubject();
- if (subject == null)
- {
- throw new ProfilerException("Missing subject for request: " +
requestPath);
- }
- Principal principal = SubjectHelper.getBestPrincipal(subject,
User.class);
- if (principal == null)
- {
- throw new ProfilerException("Missing principal for request: "
+ requestPath);
- }
-
- BaseConcretePageElement managedPage = page;
//requestContext.getManagedPage();
- PageTemplate managedPageTemplate = this.getPageTemplate(page);
//requestContext.getManagedPageTemplate();
- Map managedFragmentDefinitions = null;
//requestContext.getManagedFragmentDefinitions();
- ContentPage contentPage =
pageLayoutComponent.newContentPage(managedPage, managedPageTemplate,
managedFragmentDefinitions);
- request.setPage(contentPage);
-
- request.setAttribute(PortalReservedParameters.PATH_ATTRIBUTE,
requestPath);
-
request.setAttribute(PortalReservedParameters.CONTENT_PATH_ATTRIBUTE,
requestPath); //requestContext.getPageContentPath());
-//
request.setAttribute(PortalReservedParameters.PAGE_EDIT_ACCESS_ATTRIBUTE,getPageActionAccess(request));
-
- if (log.isDebugEnabled())
- {
- log.debug("Page path: "+contentPage.getPath());
- }
-
-
- // continue
- if (context != null)
- {
- context.invokeNext(request);
- }
- }
- catch (SecurityException se)
- {
- // fallback to root folder/default page
- if (true) //requestFallback)
- {
- // fallback to portal root folder/default page if
- // no user is available and request path is not
- // already attempting to access the root folder;
- // this is rarely the case since the anonymous
- // user is normally defined unless the default
- // security system has been replaced/overridden
- if (request.getRequest().getUserPrincipal() == null &&
- request.getPath() != null &&
- !request.getPath().equals("/"))
- {
- try
- {
-
request.getResponse().sendRedirect(request.getRequest().getContextPath());
- }
- catch (IOException ioe){}
- return;
- }
- }
+ this(portalSite, pageLayoutComponent, true, true);
+ }
- // return standard HTTP 403 - FORBIDDEN status
- log.error(se.getMessage(), se);
- try
- {
-
request.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN,
se.getMessage());
- }
- catch (IOException ioe)
- {
- log.error("Failed to invoke HttpServletReponse.sendError: " +
ioe.getMessage(), ioe);
- }
- }
- catch (NodeNotFoundException nnfe)
- {
- // return standard HTTP 404 - NOT FOUND status
- log.error(nnfe.getMessage(), nnfe);
- try
- {
-
request.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND,
nnfe.getMessage());
- }
- catch (IOException ioe)
- {
- log.error("Failed to invoke HttpServletReponse.sendError: " +
ioe.getMessage(), ioe);
- }
- }
- catch (Exception e)
+ /**
+ * Set request page and associated session and request attributes
+ * based on request and derived valve implementations.
+ *
+ * @param request invoked request
+ * @param requestPath invoked request path
+ */
+ protected void setRequestPage(RequestContext request, String requestPath)
throws NodeNotFoundException, ProfilerException
+ {
+ // get or create portal site session context; the session
+ // context maintains the user view of the site and is
+ // searched against to locate the requested page and
+ // used to build site menus from its extent; this is
+ // cached in the session because the session view does
+ // not frequently change; if the context is invalid,
+ // (perhaps because the session was persisted and is
+ // now being reloaded in a new server), it must be
+ // replaced with a newly created session context
+ PortalSiteSessionContext sessionContext =
(PortalSiteSessionContext)request.getSessionAttribute(PORTAL_SITE_SESSION_CONTEXT_ATTR_KEY);
+ if ((sessionContext == null) || !sessionContext.isValid())
{
- log.error("Exception in request pipeline: " + e.getMessage(), e);
- throw new PipelineException(e.toString(), e);
+ sessionContext = portalSite.newSessionContext();
+ request.setSessionAttribute(PORTAL_SITE_SESSION_CONTEXT_ATTR_KEY,
sessionContext);
}
+
+ // construct and save a new portal site request context
+ // using session context, fallback, and folder page
+ // histories; the request context acts as a short term
+ // request cache for the selected page and built menus;
+ // however, creating the request context here does not
+ // select the page or build menus: that is done when the
+ // request context is accessed subsequently
+ String requestServerName = ((request.getRequest() != null) ?
request.getRequest().getServerName() : null);
+ PortalSiteRequestContext requestContext =
sessionContext.newRequestContext(requestPath, requestServerName,
requestFallback, useHistory);
+
+ // save request context and set request page from portal
+ // site request context
+ setRequestPage(request, requestPath, requestContext);
}
- /**
- * Returns the <code>PageActionAccess</code> for the current user request.
- * @see PageActionAccess
- * @param requestContext RequestContext of the current portal request.
- * @return PageActionAccess for the current user request.
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
*/
-// protected PageActionAccess getPageActionAccess(RequestContext
requestContext)
-// {
-// ContentPage page = requestContext.getPage();
-// String key = page.getId();
-// boolean loggedOn = requestContext.getRequest().getUserPrincipal() !=
null;
-// boolean anonymous = !loggedOn;
-// PageActionAccess pageActionAccess = null;
-//
-// Map sessionActions = null;
-// synchronized (this)
-// {
-// sessionActions = (Map)
requestContext.getSessionAttribute(PAGE_ACTION_ACCESS_MAP_SESSION_ATTR_KEY);
-// if (sessionActions == null)
-// {
-// sessionActions = new HashMap();
-//
requestContext.setSessionAttribute(PAGE_ACTION_ACCESS_MAP_SESSION_ATTR_KEY,
sessionActions);
-// }
-// else
-// {
-// pageActionAccess = (PageActionAccess)
sessionActions.get(key);
-// }
-// }
-// synchronized (sessionActions)
-// {
-// if (pageActionAccess == null)
-// {
-// pageActionAccess = new PageActionAccess(anonymous, page);
-// sessionActions.put(key, pageActionAccess);
-// }
-// else
-// {
-// pageActionAccess.checkReset(anonymous, page);
-// }
-// }
-//
-// return pageActionAccess;
-// }
-
public String toString()
{
return "PageValve";
}
-
- public PageTemplate getPageTemplate(Page page2) throws
NodeNotFoundException
- {
- PageTemplate requestPageTemplate = null;
- BaseConcretePageElement page = page2;
- if (page != null)
- {
- // scan through site looking for first page template
- // up the folder hierarchy from the requested page
- try
- {
- Folder folder = (Folder)page.getParent();
- while ((folder != null) && (requestPageTemplate == null))
- {
- NodeSet pageTemplates = folder.getPageTemplates();
- if ((pageTemplates != null) && !pageTemplates.isEmpty())
- {
- // return first page template found
- requestPageTemplate =
(PageTemplate)pageTemplates.iterator().next();
- }
- else
- {
- // continue scan
- folder = (Folder)folder.getParent();
- }
- }
- }
- catch (NodeException ne)
- {
- }
- }
- return requestPageTemplate;
- }
-
-
}
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/profiler/impl/ProfilerValveImpl.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/profiler/impl/ProfilerValveImpl.java?rev=920192&r1=920191&r2=920192&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/profiler/impl/ProfilerValveImpl.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/profiler/impl/ProfilerValveImpl.java
Mon Mar 8 03:57:37 2010
@@ -16,25 +16,16 @@
*/
package org.apache.jetspeed.profiler.impl;
-import java.io.IOException;
import java.security.Principal;
import java.util.HashMap;
import java.util.Map;
import javax.security.auth.Subject;
-import javax.servlet.http.HttpServletResponse;
import org.apache.jetspeed.PortalReservedParameters;
-import org.apache.jetspeed.decoration.PageActionAccess;
import org.apache.jetspeed.layout.PageLayoutComponent;
-import org.apache.jetspeed.om.page.ContentPage;
-import org.apache.jetspeed.om.page.BaseConcretePageElement;
-import org.apache.jetspeed.om.page.PageTemplate;
import org.apache.jetspeed.page.document.NodeNotFoundException;
-import org.apache.jetspeed.pipeline.PipelineException;
-import org.apache.jetspeed.pipeline.valve.AbstractValve;
-import org.apache.jetspeed.pipeline.valve.PageProfilerValve;
-import org.apache.jetspeed.pipeline.valve.ValveContext;
+import org.apache.jetspeed.pipeline.valve.impl.AbstractPageValveImpl;
import org.apache.jetspeed.portalsite.PortalSite;
import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
import org.apache.jetspeed.portalsite.PortalSiteSessionContext;
@@ -45,71 +36,20 @@
import org.apache.jetspeed.security.SubjectHelper;
import org.apache.jetspeed.security.User;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* ProfilerValveImpl
*
* @author <a href="mailto:[email protected]">David Sean Taylor </a>
* @version $Id$
*/
-public class ProfilerValveImpl extends AbstractValve implements
PageProfilerValve
+public class ProfilerValveImpl extends AbstractPageValveImpl
{
- protected Logger log = LoggerFactory.getLogger(ProfilerValveImpl.class);
-
- /**
- * PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY - session portal site context
attribute key
- */
- public static final String PORTAL_SITE_SESSION_CONTEXT_ATTR_KEY =
"org.apache.jetspeed.portalsite.PortalSiteSessionContext";
-
- /**
- * PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY - request portal site context
attribute key
- */
- public static final String PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY =
"org.apache.jetspeed.portalsite.PortalSiteRequestContext";
-
- /**
- * PROFILED_PAGE_CONTEXT_ATTR_KEY - legacy request portal site context
attribute key
- */
- public static final String PROFILED_PAGE_CONTEXT_ATTR_KEY =
"org.apache.jetspeed.profiledPageContext";
-
- /**
- * session key for storing map of PageActionAccess instances
- */
- private static final String PAGE_ACTION_ACCESS_MAP_SESSION_ATTR_KEY =
"org.apache.jetspeed.profiler.pageActionAccessMap";
-
/**
* profiler - profiler component
*/
private Profiler profiler;
/**
- * portalSite - portal site component
- */
- private PortalSite portalSite;
-
- /**
- * requestFallback - flag indicating whether request should fallback to
closest
- * intermediate or root folder if locators do not select
a page
- * or access is forbidden; if set, forbidden and not
found
- * response status codes are avoided if at all possible:
do not
- * set if 403s and 404s are expected to be returned by
the portal
- */
- private boolean requestFallback;
-
- /**
- * useHistory - flag indicating whether to use visited page
- * history to select default page per site folder
- */
- private boolean useHistory;
-
- /**
- * pageLayoutComponent - component used to construct and maintain
ContentPage from
- * profiled PSML Pages and Fragments.
- */
- private PageLayoutComponent pageLayoutComponent;
-
- /**
* ProfilerValveImpl - constructor
*
* @param profiler profiler component reference
@@ -118,14 +58,10 @@
* @param requestFallback flag to enable root folder fallback
* @param useHistory flag to enable selection of last visited folder page
*/
- public ProfilerValveImpl( Profiler profiler, PortalSite portalSite,
PageLayoutComponent pageLayoutComponent,
- boolean requestFallback, boolean useHistory)
+ public ProfilerValveImpl(Profiler profiler, PortalSite portalSite,
PageLayoutComponent pageLayoutComponent, boolean requestFallback, boolean
useHistory)
{
+ super(portalSite, pageLayoutComponent, requestFallback, useHistory);
this.profiler = profiler;
- this.portalSite = portalSite;
- this.pageLayoutComponent = pageLayoutComponent;
- this.requestFallback = requestFallback;
- this.useHistory = useHistory;
}
/**
@@ -136,8 +72,7 @@
* @param pageLayoutComponent page layout component reference
* @param requestFallback flag to enable root folder fallback
*/
- public ProfilerValveImpl(Profiler profiler, PortalSite portalSite,
PageLayoutComponent pageLayoutComponent,
- boolean requestFallback)
+ public ProfilerValveImpl(Profiler profiler, PortalSite portalSite,
PageLayoutComponent pageLayoutComponent, boolean requestFallback)
{
this(profiler, portalSite, pageLayoutComponent, requestFallback, true);
}
@@ -153,244 +88,104 @@
{
this(profiler, portalSite, pageLayoutComponent, true, true);
}
-
- /*
- * (non-Javadoc)
+
+ /**
+ * Set request page and associated session and request attributes
+ * based on request and derived valve implementations.
*
- * @see
org.apache.jetspeed.pipeline.valve.Valve#invoke(org.apache.jetspeed.request.RequestContext,
- * org.apache.jetspeed.pipeline.valve.ValveContext)
+ * @param request invoked request
+ * @param requestPath invoked request path
*/
- public void invoke( RequestContext request, ValveContext context ) throws
PipelineException
+ protected void setRequestPage(RequestContext request, String requestPath)
throws NodeNotFoundException, ProfilerException
{
- try
+ // get profiler locators for request subject/principal using the
profiler
+ Subject subject = request.getSubject();
+ if (subject == null)
+ {
+ throw new ProfilerException("Missing subject for request: " +
requestPath);
+ }
+ Principal principal = SubjectHelper.getBestPrincipal(subject,
User.class);
+ if (principal == null)
{
- String requestPath = request.getPath();
- if (log.isDebugEnabled())
- {
- log.debug("Request path: "+requestPath);
- }
-
- // get profiler locators for request subject/principal using the
profiler
- Subject subject = request.getSubject();
- if (subject == null)
- {
- throw new ProfilerException("Missing subject for request: " +
requestPath);
- }
- Principal principal = SubjectHelper.getBestPrincipal(subject,
User.class);
- if (principal == null)
- {
- throw new ProfilerException("Missing principal for request: "
+ requestPath);
- }
-
- // get request specific profile locators if required
- Map locators = null;
- String locatorName =
(String)request.getAttribute(PROFILE_LOCATOR_REQUEST_ATTR_KEY);
- if ( locatorName != null )
- {
- ProfileLocator locator =
profiler.getProfile(request,locatorName);
- if ( locator != null )
- {
- locators = new HashMap();
- locators.put(ProfileLocator.PAGE_LOCATOR, locator);
- }
- }
-
- // get specified or default locators for the current user,
- // falling back to global defaults and, if necessary, explicitly
- // fallback to 'page' profile locators
- if ( locators == null )
- {
- locators = profiler.getProfileLocators(request, principal);
- }
- if (locators.size() == 0)
- {
- locators = profiler.getDefaultProfileLocators(request);
- }
- if (locators.size() == 0)
- {
- locators.put(ProfileLocator.PAGE_LOCATOR,
profiler.getProfile(request, ProfileLocator.PAGE_LOCATOR));
- }
-
- // get profiled page using the profiler, page manager,
- // and portal site components
- if (locators != null)
- {
- // get or create portalsite session context; the session
- // context maintains the user view of the site and is
- // searched against to locate the requested page and
- // used to build site menus from its extent; this is
- // cached in the session because locators seldom change
- // during the session so the session view of the site can
- // be cached unless locators do change; if the context
- // is invalid, (perhaps because the session was persisted
- // and is now being reloaded in a new server), it must be
- // replaced with a newly created session context
- PortalSiteSessionContext sessionContext =
(PortalSiteSessionContext)request.getSessionAttribute(PORTAL_SITE_SESSION_CONTEXT_ATTR_KEY);
- if ((sessionContext == null) || !sessionContext.isValid())
- {
- sessionContext = portalSite.newSessionContext();
-
request.setSessionAttribute(PORTAL_SITE_SESSION_CONTEXT_ATTR_KEY,
sessionContext);
- }
-
- // construct and save a new portalsite request context
- // using session context, locators map, fallback, and
- // folder page histories; the request context uses the
- // locators to initialize or resets the session context if
- // locators have changed for this request; the request
- // context also acts as a short term request cache for the
- // selected page and built menus; however, creating the
- // request context here does not select the page or build
- // menus: that is done when the request context is
- // accessed subsequently
- String pipeline = request.getPipeline().getName();
- boolean forceReservedFoldersVisibleInView =
(pipeline.equals(PortalReservedParameters.CONFIG_PIPELINE_NAME) ||
-
pipeline.equals(PortalReservedParameters.DESKTOP_CONFIG_PIPELINE_NAME));
- PortalSiteRequestContext requestContext =
sessionContext.newRequestContext(locators, requestFallback, useHistory,
forceReservedFoldersVisibleInView);
- request.setAttribute(PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY,
requestContext);
-
- // additionally save request context under legacy key
- // to support existing decorator access
- request.setAttribute(PROFILED_PAGE_CONTEXT_ATTR_KEY,
requestContext);
-
- // get profiled page from portalsite request context
- // and save profile locators map; accessing the request
- // context here and in subsequent valves/decorators
- // latently selects the page and builds menus from the
- // user site view using the request context locators;
- // the managed page accessed here is the raw selected page
- // as returned by the PageManager component; accessing
- // the managed page here selects the current page for the
- // request
- BaseConcretePageElement managedPage =
requestContext.getManagedPage();
- PageTemplate managedPageTemplate =
requestContext.getManagedPageTemplate();
- Map managedFragmentDefinitions =
requestContext.getManagedFragmentDefinitions();
- ContentPage contentPage =
pageLayoutComponent.newContentPage(managedPage, managedPageTemplate,
managedFragmentDefinitions);
- request.setPage(contentPage);
- request.setProfileLocators(requestContext.getLocators());
-
- // save original request for down stream content portlets
- if (requestContext.isContentPage())
- {
-
request.setAttribute(PortalReservedParameters.PATH_ATTRIBUTE, requestPath);
-
request.setAttribute(PortalReservedParameters.CONTENT_PATH_ATTRIBUTE,
requestContext.getPageContentPath());
- }
-
-
request.setAttribute(PortalReservedParameters.PAGE_EDIT_ACCESS_ATTRIBUTE,getPageActionAccess(request));
-
- if (log.isDebugEnabled())
- {
- log.debug("Page path: "+contentPage.getPath());
- }
- }
-
- // continue
- if (context != null)
- {
- context.invokeNext(request);
- }
+ throw new ProfilerException("Missing principal for request: " +
requestPath);
}
- catch (SecurityException se)
- {
- // fallback to root folder/default page
- if (requestFallback)
- {
- // fallback to portal root folder/default page if
- // no user is available and request path is not
- // already attempting to access the root folder;
- // this is rarely the case since the anonymous
- // user is normally defined unless the default
- // security system has been replaced/overridden
- if (request.getRequest().getUserPrincipal() == null &&
- request.getPath() != null &&
- !request.getPath().equals("/"))
- {
- try
- {
-
request.getResponse().sendRedirect(request.getRequest().getContextPath());
- }
- catch (IOException ioe){}
- return;
- }
- }
-
- // return standard HTTP 403 - FORBIDDEN status
- log.error(se.getMessage(), se);
- try
- {
-
request.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN,
se.getMessage());
- }
- catch (IOException ioe)
- {
- log.error("Failed to invoke HttpServletReponse.sendError: " +
ioe.getMessage(), ioe);
- }
- }
- catch (NodeNotFoundException nnfe)
+
+ // get request specific profile locators if required
+ Map locators = null;
+ String locatorName =
(String)request.getAttribute(PROFILE_LOCATOR_REQUEST_ATTR_KEY);
+ if ( locatorName != null )
{
- // return standard HTTP 404 - NOT FOUND status
- log.error(nnfe.getMessage(), nnfe);
- try
- {
-
request.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND,
nnfe.getMessage());
- }
- catch (IOException ioe)
+ ProfileLocator locator = profiler.getProfile(request,locatorName);
+ if ( locator != null )
{
- log.error("Failed to invoke HttpServletReponse.sendError: " +
ioe.getMessage(), ioe);
+ locators = new HashMap();
+ locators.put(ProfileLocator.PAGE_LOCATOR, locator);
}
}
- catch (Exception e)
+
+ // get specified or default locators for the current user,
+ // falling back to global defaults and, if necessary, explicitly
+ // fallback to 'page' profile locators
+ if ( locators == null )
{
- log.error("Exception in request pipeline: " + e.getMessage(), e);
- throw new PipelineException(e.toString(), e);
+ locators = profiler.getProfileLocators(request, principal);
}
- }
-
- /**
- * Returns the <code>PageActionAccess</code> for the current user request.
- * @see PageActionAccess
- * @param requestContext RequestContext of the current portal request.
- * @return PageActionAccess for the current user request.
- */
- protected PageActionAccess getPageActionAccess(RequestContext
requestContext)
- {
- ContentPage page = requestContext.getPage();
- String key = page.getId();
- boolean loggedOn = requestContext.getRequest().getUserPrincipal() !=
null;
- boolean anonymous = !loggedOn;
- PageActionAccess pageActionAccess = null;
-
- Map sessionActions = null;
- synchronized (this)
+ if (locators.size() == 0)
{
- sessionActions = (Map)
requestContext.getSessionAttribute(PAGE_ACTION_ACCESS_MAP_SESSION_ATTR_KEY);
- if (sessionActions == null)
- {
- sessionActions = new HashMap();
-
requestContext.setSessionAttribute(PAGE_ACTION_ACCESS_MAP_SESSION_ATTR_KEY,
sessionActions);
- }
- else
- {
- pageActionAccess = (PageActionAccess) sessionActions.get(key);
- }
+ locators = profiler.getDefaultProfileLocators(request);
}
- synchronized (sessionActions)
+ if (locators.size() == 0)
{
- if (pageActionAccess == null)
- {
- pageActionAccess = new PageActionAccess(anonymous, page);
- sessionActions.put(key, pageActionAccess);
- }
- else
- {
- pageActionAccess.checkReset(anonymous, page);
- }
+ locators.put(ProfileLocator.PAGE_LOCATOR,
profiler.getProfile(request, ProfileLocator.PAGE_LOCATOR));
}
- return pageActionAccess;
+ // get profiled page using the profiler, page manager,
+ // and portal site components
+ if (locators != null)
+ {
+ // get or create portal site session context; the session
+ // context maintains the user view of the site and is
+ // searched against to locate the requested page and
+ // used to build site menus from its extent; this is
+ // cached in the session because locators seldom change
+ // during the session so the session view of the site can
+ // be cached unless locators do change; if the context
+ // is invalid, (perhaps because the session was persisted
+ // and is now being reloaded in a new server), it must be
+ // replaced with a newly created session context
+ PortalSiteSessionContext sessionContext =
(PortalSiteSessionContext)request.getSessionAttribute(PORTAL_SITE_SESSION_CONTEXT_ATTR_KEY);
+ if ((sessionContext == null) || !sessionContext.isValid())
+ {
+ sessionContext = portalSite.newSessionContext();
+
request.setSessionAttribute(PORTAL_SITE_SESSION_CONTEXT_ATTR_KEY,
sessionContext);
+ }
+
+ // construct and save a new portal site request context
+ // using session context, locators map, fallback, and
+ // folder page histories; the request context uses the
+ // locators to initialize or resets the session context if
+ // locators have changed for this request; the request
+ // context also acts as a short term request cache for the
+ // selected page and built menus; however, creating the
+ // request context here does not select the page or build
+ // menus: that is done when the request context is
+ // accessed subsequently
+ String pipeline = request.getPipeline().getName();
+ boolean forceReservedFoldersVisibleInView =
(pipeline.equals(PortalReservedParameters.CONFIG_PIPELINE_NAME) ||
+
pipeline.equals(PortalReservedParameters.DESKTOP_CONFIG_PIPELINE_NAME));
+ PortalSiteRequestContext requestContext =
sessionContext.newRequestContext(locators, requestFallback, useHistory,
forceReservedFoldersVisibleInView);
+
+ // save request context and set request page from portal
+ // site request context
+ setRequestPage(request, requestPath, requestContext);
+ }
}
-
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
public String toString()
{
return "ProfilerValve";
}
-
}
Modified:
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml?rev=920192&r1=920191&r2=920192&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
(original)
+++
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
Mon Mar 8 03:57:37 2010
@@ -141,12 +141,29 @@
<bean id="pageValve"
class="org.apache.jetspeed.pipeline.valve.impl.PageValveImpl"
init-method="initialize">
<meta key="j2:cat" value="default" />
<constructor-arg index="0">
- <ref bean="org.apache.jetspeed.page.PageManager" />
+ <ref bean="org.apache.jetspeed.portalsite.PortalSite" />
</constructor-arg>
<constructor-arg index="1">
<ref bean="org.apache.jetspeed.layout.PageLayoutComponent" />
</constructor-arg>
- </bean>
+ <!--
+ request fallback to root folder/page enabled by default;
+ if set to false, requests generate HTTP 403/404 errors
+ for access errors or missing pages
+ -->
+ <constructor-arg index="2">
+ <value>true</value>
+ </constructor-arg>
+ <!--
+ use last visited page histories to select default page
+ for folder navigational urls; if set to false, the
+ default page specified in PSML, (or the first page in
+ the folder), is always selected
+ -->
+ <constructor-arg index="3">
+ <value>true</value>
+ </constructor-arg>
+ </bean>
<!--
To create a new page when a user first logs in from their roles,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]