package org.alfresco.web.app.servlet; import java.io.IOException; import java.text.MessageFormat; import java.util.Stack; import java.util.StringTokenizer; import javax.faces.application.NavigationHandler; import javax.faces.context.FacesContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.alfresco.repo.webdav.WebDAVServlet; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.web.app.AlfrescoNavigationHandler; import org.alfresco.web.app.Application; import org.alfresco.web.bean.BrowseBean; import org.alfresco.web.bean.NavigationBean; import org.alfresco.web.bean.dashboard.DashboardManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.myfaces.shared_impl.renderkit.ViewSequenceUtils; /** * Servlet allowing external URL access to various global JSF views in the Web Client. *

* The servlet accepts a well formed URL that can easily be generated from a Content or Space NodeRef. * The URL also specifies the JSF "outcome" to be executed which provides the correct JSF View to be * displayed. The JSF "outcome" must equate to a global navigation rule or it will not be displayed. * Servlet URL is of the form: *

* http://<server>/alfresco/navigate/<outcome>[/<workspace>/<store>/<nodeId>] or
* http://<server>/alfresco/navigate/<outcome>[/webdav/<path/to/node>] *

* Like most Alfresco servlets, the URL may be followed by a valid 'ticket' argument for authentication: * ?ticket=1234567890 *

* And/or also followed by the "?guest=true" argument to force guest access login for the URL. * * @author Kevin Roast * @deprecated 5.0 not exposed in web-client web.xml */ public class ExternalAccessServlet extends BaseServlet { private static final long serialVersionUID = -4118907921337237802L; private static Log logger = LogFactory.getLog(ExternalAccessServlet.class); public final static String OUTCOME_DOCDETAILS = "showDocDetails"; public final static String OUTCOME_SPACEDETAILS = "showSpaceDetails"; public final static String OUTCOME_BROWSE = "browse"; public final static String OUTCOME_MYALFRESCO = "myalfresco"; public final static String OUTCOME_LOGOUT = "logout"; public final static String OUTCOME_DIALOG = "dialog"; public final static String OUTCOME_WIZARD = "wizard"; private static final String ARG_TEMPLATE = "template"; private static final String ARG_PAGE = "page"; /** * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String uri = req.getRequestURI(); if (logger.isDebugEnabled()) logger.debug("Processing URL: " + uri + (req.getQueryString() != null ? ("?" + req.getQueryString()) : "")); AuthenticationStatus status = servletAuthenticate(req, res); if (status == AuthenticationStatus.Failure) { return; } setNoCacheHeaders(res); uri = uri.substring(req.getContextPath().length()); StringTokenizer t = new StringTokenizer(uri, "/"); int tokenCount = t.countTokens(); if (tokenCount < 2) { throw new IllegalArgumentException("Externally addressable URL did not contain all required args: " + uri); } t.nextToken(); // skip servlet name String outcome = t.nextToken(); // get rest of the tokens arguments String[] args = new String[tokenCount - 2]; for (int i=0; i= 3) { int offset = 0; offset = args.length - 3; StoreRef storeRef = new StoreRef(args[0+offset], args[1+offset]); nodeRef = new NodeRef(storeRef, args[2+offset]); } if (nodeRef != null) { // check that the user has at least READ access - else redirect to an error or login page if (!checkAccess(req, res, nodeRef, PermissionService.READ_CONTENT, true)) { return; } // this call sets up the current node Id, and updates or initialises the // breadcrumb component with the selected node as appropriate. browseBean.updateUILocation(nodeRef); // force a "late" refresh of the BrowseBean to handle external servlet access URL browseBean.externalAccessRefresh(); // check for view mode first argument if (args[0].equals(ARG_TEMPLATE)) { browseBean.setDashboardView(true); } // the above calls into BrowseBean setup the NavigationHandler automatically } else { // perform the appropriate JSF navigation outcome NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler(); navigationHandler.handleNavigation(fc, null, outcome); } } else if (OUTCOME_MYALFRESCO.equals(outcome)) { // setup the Dashboard Manager ready for the page we want to display if (req.getParameter(ARG_PAGE) != null) { DashboardManager manager = (DashboardManager)FacesHelper.getManagedBean(fc, DashboardManager.BEAN_NAME); manager.getPageConfig().setCurrentPage(req.getParameter(ARG_PAGE)); } // perform the appropriate JSF navigation outcome NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler(); navigationHandler.handleNavigation(fc, null, outcome); } else if (OUTCOME_DIALOG.equals(outcome) || OUTCOME_WIZARD.equals(outcome)) { if (args.length != 0) { if (args.length > 1) { String currentNodeId = null; if (args[1].equals(WebDAVServlet.WEBDAV_PREFIX)) { // Drop the first argument String[] args2 = new String[ args.length -1 ]; for (int i=1; i/alfresco/navigate/[///] private static final String EXTERNAL_URL = "/n/{0}"; private static final String EXTERNAL_URL_ARGS = "/n/{0}/{1}"; }