diff --git a/source/java/org/alfresco/rest/api/PublicApiTenantWebScriptServletRuntime.java b/source/java/org/alfresco/rest/api/PublicApiTenantWebScriptServletRuntime.java index 53b2353e73..b1a3acc50d 100644 --- a/source/java/org/alfresco/rest/api/PublicApiTenantWebScriptServletRuntime.java +++ b/source/java/org/alfresco/rest/api/PublicApiTenantWebScriptServletRuntime.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2012 Alfresco Software Limited. + * Copyright (C) 2005-2015 Alfresco Software Limited. * * This file is part of Alfresco * @@ -18,6 +18,8 @@ */ package org.alfresco.rest.api; +import java.util.regex.Pattern; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -31,6 +33,8 @@ import org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFac public class PublicApiTenantWebScriptServletRuntime extends TenantWebScriptServletRuntime { + private static final Pattern CMIS_URI_PATTERN = Pattern.compile(".*/cmis/versions/[0-9]+\\.[0-9]+/.*"); + public PublicApiTenantWebScriptServletRuntime(RuntimeContainer container, ServletAuthenticatorFactory authFactory, HttpServletRequest req, HttpServletResponse res, ServerProperties serverProperties) { @@ -54,6 +58,11 @@ public class PublicApiTenantWebScriptServletRuntime extends TenantWebScriptServl // NOTE: this is unlikely, and we'll take the hit if the path contains a semi-colon pathInfo = req.getPathInfo(); } + // MNT-13057 fix, do not decode CMIS uris. + else if (CMIS_URI_PATTERN.matcher(requestURI).matches()) + { + pathInfo = requestURI.substring(serviceContextPath.length()); + } else { pathInfo = URLDecoder.decode(requestURI.substring(serviceContextPath.length())); diff --git a/source/test-java/org/alfresco/rest/api/tests/TestCMIS.java b/source/test-java/org/alfresco/rest/api/tests/TestCMIS.java index 65858abd46..cf5709f92a 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestCMIS.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestCMIS.java @@ -127,7 +127,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springframework.context.ApplicationContext; -import org.springframework.test.AssertThrows; +import org.springframework.extensions.surf.util.URLEncoder; public class TestCMIS extends EnterpriseTestApi { @@ -2081,6 +2081,70 @@ public class TestCMIS extends EnterpriseTestApi assertEquals("Ipsum and so on", content); } + @Test + public void testMNT_13057() throws Exception + { + final TestNetwork network1 = getTestFixture().getRandomNetwork(); + + String username = "user" + System.currentTimeMillis(); + PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null); + TestPerson person1 = network1.createUser(personInfo); + String person1Id = person1.getId(); + + String guid = GUID.generate(); + String name = guid + "_KRUIS_LOGO_100%_PMS.txt"; + String urlFileName = guid + "_KRUIS_LOGO_100%25_PMS.txt"; + + final String siteName = "site" + System.currentTimeMillis(); + + TenantUtil.runAsUserTenant(new TenantRunAsWork() + { + @Override + public NodeRef doWork() throws Exception + { + SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE); + TestSite site = repoService.createSite(null, siteInfo); + + String name = GUID.generate(); + NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name); + return folderNodeRef; + } + }, person1Id, network1.getId()); + + // Create a document... + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id)); + CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11); + Folder docLibrary = (Folder)cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary"); + + Map properties = new HashMap(); + { + properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT); + properties.put(PropertyIds.NAME, name); + } + + ContentStreamImpl fileContent = new ContentStreamImpl(); + { + ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt")); + writer.putContent("Ipsum"); + ContentReader reader = writer.getReader(); + fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN); + fileContent.setStream(reader.getContentInputStream()); + } + + /* Create document */ + Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR); + + String id = doc.getId(); + assertNotNull(id); + Map params = new HashMap(); + params.put("id", URLEncoder.encode(id)); + + urlFileName += "?id=" + URLEncoder.encode(id); + + HttpResponse response = publicApiClient.get("/" + network1.getId() + "/public/cmis/versions/1.1/atom/content/" + urlFileName, null); + assertEquals(200, response.getStatusCode()); + } + @Test public void testMNT10430() throws Exception {