Files
alfresco-community-repo/source/java/org/alfresco/opencmis/CMISHttpServletRequest.java
Alan Davis cc1598b3d1 Merged 5.2.N (5.2.1) to HEAD (5.2)
132357 adavis: Merged 5.2.N-SERVLET-3.0 (5.2.1) to 5.2.N (5.2.1)
      131490: REPO-1238 / REPO-1413: Use data-model with the OpenCMIS upgrade.,
      131493: REPO-1238 / REPO-1413: OpenCMIS upgrade to 1.0.0.
          - Compilation errors fixed
          - Removed old JAX-WS listener from web.xml + sun-jaxws.xml - obsolete after the upgrade (OpenCMIS has replaced JAX-WS with Apache CXF)
          - Set chemistry-opencmis-test-browser version to 0.14.0, since it was removed in 1.0.0 (TODO: see if something from 1.0.0 can be used instead)
          - Changed dependency on XmlSchema 1.4.7 to xmlschema-core 2.2.1 (required by Apache CXF) - implications of this change still to be addressed.,
      131569: REPO-1238 / REPO-1413: OpenCMIS upgrade to 1.0.0.
          - Possible fix for the browser binding - since OpenCMIS 0.13.0, repository URLs always require a cmisselector parameter (see CMIS-893).,
      131671: REPO-843 Upgrade our Servlet API usage to 3.0.1 (from 2.4 / 2.5)
         - Modifications to weblogic-application.xml to allow Weblogic 12.2.1.1 to start with the changes
           made so far for the 1.0 Open CMIS upgrade (REPO-1238). This follows the Servlet 3.0 upgrade
           which resulted in WebLogic not starting. The Open CMIS upgrade has helped with fixing the WebLogic
           start up issue, however...
         - Some of the changes are TEMPORARY to pick up classes and resources from either the JRE or WebLogic
           rather than the alfresco.war. These should be coming from the alfresco.war, but we will still need to
           upgrade the jars that we package. See comments being added to REPO-1413 related to the CMIS upgrade.
         - It is likely that there are other entries in this file that are not needed.,
      131758: REPO-1238 / REPO-1413: OpenCMIS upgrade to 1.0.0 - Fix for CMISTCKVersioning tests.
          - The VersioningSmokeTest from the OpenCMIS TCK has been enhanced with the case of checking-in documents with new properties (not just new content). This touches the part of code in CMISConnector that parses the secondary types (aspects), removes the old ones and adds the new. The problem was that even the working copy aspect was removed for checked out documents. This is illegal and an error was thrown.
          - Applies to CMIS 1.1.,
      131815: REPO-1238 / REPO-1413: OpenCMIS upgrade to 1.0.0 - Fix for CMISTCKVersioning tests.
          - The VersioningSmokeTest from the OpenCMIS TCK has been enhanced with the case of checking-in documents with new properties (not just new content). So the tests check-in a document with the same name as the original name causing the rename of the working copy to fail. I added an extra check on the name format for working copies.
          - Applies to CMIS 1.0.,
      131843: REPO-1238 / REPO-1413: OpenCMIS upgrade to 1.0.0 - Fix for CMISTCKCRUD tests.
          - The SetAndDeleteContentTest from the OpenCMIS TCK has been enhanced with tests that append content. The case where the content was 0 bytes failed, because of an "unnecessary" (hopefully) check on the content data length.,
      131859: REPO-1413 : Upgrade to OpenCMIS 1.0 - update dependencies and fix compilation and/or build test failures
         - fixed failing testVersioningPropertiesHaveDefaultValue ,
      131868: REPO-1413 : Upgrade to OpenCMIS 1.0 - update dependencies and fix compilation and/or build test failures
         - fixed new failing tests,
      131876: REPO-1238 / REPO-1413: OpenCMIS upgrade to 1.0.0
          - Fix for versioning related tests.,
      131907: REPO-1238 / REPO-1413: OpenCMIS upgrade to 1.0.0
          - Removed unused dependency on chemistry-opencmis-test-browser,
      132064: REPO-1238 / REPO-1413: OpenCMIS upgrade to 1.0.0
          - Removed unnecessary excludes, updated data-model, added junit dependency for legacy-lucene which was relying on a now unused dependency to get the junit.,
      132069: REPO-1238 / REPO-1413: OpenCMIS upgrade to 1.0.0
          - Upgrade jaxb libraries to 2.2.11, alfresco-core to 6.7.,
      132110: REPO-843 Upgrade our Servlet API usage to 3.0.1 (from 2.4 / 2.5)
         - Further modifications to weblogic-application.xml
           - Checked file only contains references to files that we actually package in alfresco.war.
           - Add additional entries identified by WebLogic's CAT
             - Exclude myfaces-api-1.1.10.jar classes (used by the Explorer UI, removed in 5.0 but still used by Cloud).
             - Exclude classes that cause start up exception. We must use the RT or Weblogic versions.,
      132161: REPO-1238 / REPO-1413: OpenCMIS upgrade to 1.0.0
          - code review changes
      132356: Change to using data-model 6.6


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@132365 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2016-11-03 20:07:41 +00:00

647 lines
14 KiB
Java

/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.opencmis;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.AsyncContext;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.Part;
import org.alfresco.opencmis.CMISDispatcherRegistry.Binding;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantAdminService;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.web.scripts.TenantWebScriptServletRequest;
import org.alfresco.service.descriptor.Descriptor;
import org.apache.chemistry.opencmis.commons.impl.Constants;
import org.apache.chemistry.opencmis.server.shared.Dispatcher;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.extensions.webscripts.Match;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WrappingWebScriptRequest;
import org.springframework.extensions.webscripts.servlet.WebScriptServletRuntime;
/**
* Wraps an OpenCMIS HttpServletRequest, mapping urls and adding servlet attributes specific to the Alfresco implementation of OpenCMIS.
*/
@SuppressWarnings("rawtypes")
public class CMISHttpServletRequest implements HttpServletRequest
{
protected WebScriptRequest req;
protected HttpServletRequest httpReq;
protected String networkId;
protected String operation;
protected String id; // object id (or path for browser binding)
protected String serviceName;
protected BaseUrlGenerator baseUrlGenerator;
protected Binding binding;
protected Descriptor currentDescriptor;
public CMISHttpServletRequest(WebScriptRequest req, String serviceName, BaseUrlGenerator baseUrlGenerator, Binding binding, Descriptor currentDescriptor,
TenantAdminService tenantAdminService)
{
this.req = req;
this.serviceName = serviceName;
this.baseUrlGenerator = baseUrlGenerator;
this.binding = binding;
String pathInfo = req.getPathInfo();
WebScriptRequest baseReq = getBaseRequest(req);
if(!pathInfo.startsWith("/cmis") && (baseReq instanceof TenantWebScriptServletRequest))
{
TenantWebScriptServletRequest servletReq = (TenantWebScriptServletRequest)baseReq;
String tenant = servletReq.getTenant();
if(tenant.equalsIgnoreCase(TenantUtil.DEFAULT_TENANT))
{
String user = AuthenticationUtil.getFullyAuthenticatedUser();
String domain = tenantAdminService.getUserDomain(user);
if(domain == null || domain.equals(TenantService.DEFAULT_DOMAIN))
{
this.networkId = tenant;
}
else
{
this.networkId = domain;
}
}
else
{
this.networkId = tenant;
}
}
Match match = req.getServiceMatch();
Map<String, String> templateVars = match.getTemplateVars();
HttpServletRequest httpReq = WebScriptServletRuntime.getHttpServletRequest(req);
this.httpReq = httpReq;
this.operation = templateVars.get("operation");
this.id = templateVars.get("id");
addAttributes();
}
/*
* Recursively unwrap req if it is a WrappingWebScriptRequest
*/
private WebScriptRequest getBaseRequest(WebScriptRequest req)
{
WebScriptRequest ret = req;
while(ret instanceof WrappingWebScriptRequest)
{
WrappingWebScriptRequest wrapping = (WrappingWebScriptRequest)req;
ret = wrapping.getNext();
}
return ret;
}
protected void addAttributes()
{
if(networkId != null)
{
httpReq.setAttribute(Constants.PARAM_REPOSITORY_ID, networkId);
}
httpReq.setAttribute("serviceName", serviceName);
}
@Override
public Object getAttribute(String arg0)
{
if(arg0.equals(Dispatcher.BASE_URL_ATTRIBUTE))
{
return baseUrlGenerator.getBaseUrl(this, networkId, binding);
}
else
{
return httpReq.getAttribute(arg0);
}
}
@SuppressWarnings("unchecked")
@Override
public Enumeration getAttributeNames()
{
Enumeration e = httpReq.getAttributeNames();
List attrNames = new ArrayList();
while(e.hasMoreElements())
{
attrNames.add(e.nextElement());
}
attrNames.add(Dispatcher.BASE_URL_ATTRIBUTE);
final Iterator it = attrNames.iterator();
return new Enumeration()
{
public boolean hasMoreElements()
{
return it.hasNext();
}
public Object nextElement()
{
return it.next();
}
};
}
@Override
public String getCharacterEncoding()
{
return httpReq.getCharacterEncoding();
}
@Override
public int getContentLength()
{
return httpReq.getContentLength();
}
@Override
public String getContentType()
{
return httpReq.getContentType();
}
@Override
public ServletInputStream getInputStream() throws IOException
{
return httpReq.getInputStream();
}
@Override
public String getLocalAddr()
{
return httpReq.getLocalAddr();
}
@Override
public String getLocalName()
{
return httpReq.getLocalName();
}
@Override
public int getLocalPort()
{
return httpReq.getLocalPort();
}
@Override
public Locale getLocale()
{
return httpReq.getLocale();
}
@Override
public Enumeration getLocales()
{
return httpReq.getLocales();
}
@Override
public String getParameter(String arg0)
{
if(arg0.equals(Constants.PARAM_REPOSITORY_ID))
{
return networkId;
}
return httpReq.getParameter(arg0);
}
@SuppressWarnings("unchecked")
@Override
public Map getParameterMap()
{
Map map = httpReq.getParameterMap();
Map ret = new HashedMap(map);
if(networkId != null)
{
ret.put(Constants.PARAM_REPOSITORY_ID, new String[] { networkId });
}
return ret;
}
@SuppressWarnings("unchecked")
@Override
public Enumeration getParameterNames()
{
final Enumeration e = httpReq.getParameterNames();
List l = new ArrayList();
while(e.hasMoreElements())
{
l.add(e.nextElement());
}
if(networkId != null)
{
l.add(Constants.PARAM_REPOSITORY_ID);
}
final Iterator it = l.iterator();
Enumeration ret = new Enumeration()
{
@Override
public boolean hasMoreElements()
{
return it.hasNext();
}
@Override
public Object nextElement()
{
return it.next();
}
};
return ret;
}
@Override
public String[] getParameterValues(String arg0)
{
return httpReq.getParameterValues(arg0);
}
@Override
public String getProtocol()
{
return httpReq.getProtocol();
}
@Override
public BufferedReader getReader() throws IOException
{
return httpReq.getReader();
}
@SuppressWarnings("deprecation")
@Override
public String getRealPath(String arg0)
{
return httpReq.getRealPath(arg0);
}
@Override
public String getRemoteAddr()
{
return httpReq.getRemoteAddr();
}
@Override
public String getRemoteHost()
{
return httpReq.getRemoteHost();
}
@Override
public int getRemotePort()
{
return httpReq.getRemotePort();
}
@Override
public RequestDispatcher getRequestDispatcher(String arg0)
{
return httpReq.getRequestDispatcher(arg0);
}
@Override
public String getScheme()
{
return httpReq.getScheme();
}
@Override
public String getServerName()
{
return httpReq.getServerName();
}
@Override
public int getServerPort()
{
return httpReq.getServerPort();
}
@Override
public boolean isSecure()
{
return httpReq.isSecure();
}
@Override
public void removeAttribute(String arg0)
{
httpReq.removeAttribute(arg0);
}
@Override
public void setAttribute(String arg0, Object arg1)
{
httpReq.setAttribute(arg0, arg1);
}
@Override
public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException
{
httpReq.setCharacterEncoding(arg0);
}
@Override
public String getAuthType()
{
return httpReq.getAuthType();
}
@Override
public String getContextPath()
{
String contextPath = baseUrlGenerator.getContextPath(httpReq);
return contextPath;
}
@Override
public Cookie[] getCookies()
{
return httpReq.getCookies();
}
@Override
public long getDateHeader(String arg0)
{
return httpReq.getDateHeader(arg0);
}
@Override
public String getHeader(String arg0)
{
return httpReq.getHeader(arg0);
}
@Override
public Enumeration getHeaderNames()
{
return httpReq.getHeaderNames();
}
@Override
public Enumeration getHeaders(String arg0)
{
return httpReq.getHeaders(arg0);
}
@Override
public int getIntHeader(String arg0)
{
return httpReq.getIntHeader(arg0);
}
@Override
public String getMethod()
{
return httpReq.getMethod();
}
@Override
public String getPathInfo()
{
StringBuilder sb = new StringBuilder("/");
sb.append(networkId == null ? TenantUtil.DEFAULT_TENANT : networkId);
if(operation != null)
{
sb.append("/");
sb.append(operation);
}
return sb.toString();
}
@Override
public String getPathTranslated()
{
return httpReq.getPathTranslated();
}
@Override
public String getQueryString()
{
StringBuilder queryString = new StringBuilder();
String reqQueryString = httpReq.getQueryString();
if(networkId != null && networkId.length() > 0)
{
if (reqQueryString == null)
{
queryString.append("repositoryId=");
queryString.append(networkId);
}
else
{
queryString.append(reqQueryString);
queryString.append("&repositoryId=");
queryString.append(networkId);
}
queryString.append("&cmisselector=");
queryString.append(Constants.SELECTOR_REPOSITORY_INFO);
return queryString.toString();
}
return reqQueryString;
}
@Override
public String getRemoteUser()
{
return httpReq.getRemoteUser();
}
@Override
public String getRequestURI()
{
String requestURI = baseUrlGenerator.getRequestURI(httpReq, networkId, operation, id);
return requestURI;
}
@Override
public StringBuffer getRequestURL()
{
return httpReq.getRequestURL();
}
@Override
public String getRequestedSessionId()
{
return httpReq.getRequestedSessionId();
}
@Override
public String getServletPath()
{
String servletPath = baseUrlGenerator.getServletPath(httpReq);
return servletPath;
}
@Override
public HttpSession getSession()
{
return httpReq.getSession();
}
@Override
public HttpSession getSession(boolean arg0)
{
return httpReq.getSession(arg0);
}
@Override
public Principal getUserPrincipal()
{
return httpReq.getUserPrincipal();
}
@Override
public boolean isRequestedSessionIdFromCookie()
{
return httpReq.isRequestedSessionIdFromCookie();
}
@Override
public boolean isRequestedSessionIdFromURL()
{
return httpReq.isRequestedSessionIdFromURL();
}
@Override
public boolean isRequestedSessionIdFromUrl()
{
return httpReq.isRequestedSessionIdFromURL();
}
@Override
public boolean isRequestedSessionIdValid()
{
return httpReq.isRequestedSessionIdValid();
}
@Override
public boolean isUserInRole(String arg0)
{
return httpReq.isUserInRole(arg0);
}
@Override
public boolean authenticate(HttpServletResponse response) throws IOException, ServletException
{
return httpReq.authenticate(response);
}
@Override
public void login(String username, String password) throws ServletException
{
httpReq.login(username, password);
}
@Override
public void logout() throws ServletException
{
httpReq.logout();
}
@Override
public Collection<Part> getParts() throws IOException, ServletException
{
return httpReq.getParts();
}
@Override
public Part getPart(String name) throws IOException, ServletException
{
return httpReq.getPart(name);
}
@Override
public ServletContext getServletContext()
{
return httpReq.getServletContext();
}
@Override
public AsyncContext startAsync() throws IllegalStateException
{
return httpReq.startAsync();
}
@Override
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException
{
return httpReq.startAsync(servletRequest, servletResponse);
}
@Override
public boolean isAsyncStarted()
{
return httpReq.isAsyncStarted();
}
@Override
public boolean isAsyncSupported()
{
return httpReq.isAsyncSupported();
}
@Override
public AsyncContext getAsyncContext()
{
return httpReq.getAsyncContext();
}
@Override
public DispatcherType getDispatcherType()
{
return httpReq.getDispatcherType();
}
}