diff --git a/remote-api/src/main/java/org/alfresco/rest/api/discovery/DiscoveryApiWebscript.java b/remote-api/src/main/java/org/alfresco/rest/api/discovery/DiscoveryApiWebscript.java index c163447fd0..b4ee326711 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/discovery/DiscoveryApiWebscript.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/discovery/DiscoveryApiWebscript.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -25,6 +25,7 @@ */ package org.alfresco.rest.api.discovery; +import org.alfresco.rest.api.impl.directurl.RestApiDirectUrlConfig; import org.alfresco.rest.api.model.DiscoveryDetails; import org.alfresco.rest.api.model.ModulePackage; import org.alfresco.rest.api.model.RepositoryInfo; @@ -41,6 +42,7 @@ import org.alfresco.service.cmr.audit.AuditService; import org.alfresco.service.cmr.module.ModuleDetails; import org.alfresco.service.cmr.module.ModuleService; import org.alfresco.service.cmr.quickshare.QuickShareService; +import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.thumbnail.ThumbnailService; import org.alfresco.service.descriptor.Descriptor; import org.alfresco.service.descriptor.DescriptorService; @@ -67,6 +69,8 @@ public class DiscoveryApiWebscript extends AbstractWebScript implements Recogniz private ModuleService moduleService; private ApiAssistant assistant; private ThumbnailService thumbnailService; + private RestApiDirectUrlConfig restApiDirectUrlConfig; + private ContentService contentService; private boolean enabled = true; private final static String DISABLED = "Not Implemented"; @@ -106,6 +110,16 @@ public class DiscoveryApiWebscript extends AbstractWebScript implements Recogniz this.thumbnailService = thumbnailService; } + public void setRestApiDirectUrlConfig(RestApiDirectUrlConfig restApiDirectUrlConfig) + { + this.restApiDirectUrlConfig = restApiDirectUrlConfig; + } + + public void setContentService(ContentService contentService) + { + this.contentService = contentService; + } + @Override public void afterPropertiesSet() throws Exception { @@ -116,6 +130,8 @@ public class DiscoveryApiWebscript extends AbstractWebScript implements Recogniz PropertyCheck.mandatory(this, "moduleService", moduleService); PropertyCheck.mandatory(this, "assistant", assistant); PropertyCheck.mandatory(this, "thumbnailService", thumbnailService); + PropertyCheck.mandatory(this, "restApiDirectUrlConfig", restApiDirectUrlConfig); + PropertyCheck.mandatory(this, "contentService", contentService); } @Override @@ -154,7 +170,8 @@ public class DiscoveryApiWebscript extends AbstractWebScript implements Recogniz .setReadOnly(repoAdminService.getUsage().isReadOnly()) .setAuditEnabled(auditService.isAuditEnabled()) .setQuickShareEnabled(quickShareService.isQuickShareEnabled()) - .setThumbnailGenerationEnabled(thumbnailService.getThumbnailsEnabled())); + .setThumbnailGenerationEnabled(thumbnailService.getThumbnailsEnabled()) + .setDirectAccessUrlEnabled(isContentDirectUrlEnabled())); } private List getModules() @@ -194,4 +211,10 @@ public class DiscoveryApiWebscript extends AbstractWebScript implements Recogniz throw new DisabledServiceException(DISABLED); } } + + protected boolean isContentDirectUrlEnabled() + { + return (restApiDirectUrlConfig.isEnabled() && contentService.isContentDirectUrlEnabled()); + } + } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/RepositoryInfo.java b/remote-api/src/main/java/org/alfresco/rest/api/model/RepositoryInfo.java index f65aa8c5c7..60bbadd32a 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/RepositoryInfo.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/RepositoryInfo.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -416,6 +416,7 @@ public class RepositoryInfo private boolean isAuditEnabled; private boolean isQuickShareEnabled; private boolean isThumbnailGenerationEnabled; + private boolean isDirectAccessUrlEnabled; public StatusInfo() { @@ -465,6 +466,17 @@ public class RepositoryInfo return this; } + public boolean getIsDirectAccessUrlEnabled() + { + return isDirectAccessUrlEnabled; + } + + public StatusInfo setDirectAccessUrlEnabled(boolean isDirectAccessUrlEnabled) + { + this.isDirectAccessUrlEnabled = isDirectAccessUrlEnabled; + return this; + } + @Override public String toString() { @@ -473,6 +485,7 @@ public class RepositoryInfo .append(", isAuditEnabled=").append(isAuditEnabled) .append(", isQuickShareEnabled=").append(isQuickShareEnabled) .append(", isThumbnailGenerationEnabled=").append(isThumbnailGenerationEnabled) + .append(", isDirectAccessUrlEnabled=").append(isDirectAccessUrlEnabled) .append(']'); return sb.toString(); } diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index 8c965e2a36..9f659bc8b2 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1063,12 +1063,21 @@ + + + + + + + + + diff --git a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java index 9d18221209..b22987a9f2 100644 --- a/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java +++ b/remote-api/src/test/java/org/alfresco/AppContext02TestSuite.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2017 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -47,6 +47,7 @@ import org.junit.runners.Suite; org.alfresco.rest.api.tests.ActivitiesPostingTest.class, org.alfresco.rest.api.tests.AuthenticationsTest.class, org.alfresco.rest.api.tests.DiscoveryApiTest.class, + org.alfresco.rest.api.discovery.DiscoveryApiWebscriptUnitTest.class, org.alfresco.rest.api.tests.GroupsTest.class, org.alfresco.rest.api.tests.ModulePackagesApiTest.class, org.alfresco.rest.api.tests.NodeApiTest.class, diff --git a/remote-api/src/test/java/org/alfresco/rest/api/discovery/DiscoveryApiWebscriptUnitTest.java b/remote-api/src/test/java/org/alfresco/rest/api/discovery/DiscoveryApiWebscriptUnitTest.java new file mode 100644 index 0000000000..394c13a8f1 --- /dev/null +++ b/remote-api/src/test/java/org/alfresco/rest/api/discovery/DiscoveryApiWebscriptUnitTest.java @@ -0,0 +1,87 @@ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2021 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 . + * #L% + */ +package org.alfresco.rest.api.discovery; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +import org.alfresco.rest.api.impl.directurl.RestApiDirectUrlConfig; +import org.alfresco.service.cmr.repository.ContentService; +import org.junit.Test; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +/** + * @author Mikołaj Brzeziński + */ +public class DiscoveryApiWebscriptUnitTest +{ + private static final Boolean ENABLED = Boolean.TRUE; + private static final Boolean DISABLED = Boolean.FALSE; + + private DiscoveryApiWebscript discoveryApiWebscript = mock(DiscoveryApiWebscript.class); + private RestApiDirectUrlConfig restApiDirectUrlConfig = mock(RestApiDirectUrlConfig.class); + private ContentService contentService = mock(ContentService.class); + + public void mockedAsserts(boolean restEnabled, boolean systemwideEnabled) + { + when(contentService.isContentDirectUrlEnabled()).thenReturn(systemwideEnabled); + when(restApiDirectUrlConfig.isEnabled()).thenReturn(restEnabled); + assertEquals(systemwideEnabled, contentService.isContentDirectUrlEnabled()); + assertEquals(restEnabled, restApiDirectUrlConfig.isEnabled()); + when(discoveryApiWebscript.isContentDirectUrlEnabled()).thenReturn(restEnabled && systemwideEnabled); + } + + @Test + public void testEnabledConfig_RestEnabledAndSystemwideEnabled() + { + mockedAsserts(ENABLED,ENABLED); + assertTrue("Direct Acess URLs are enabled",discoveryApiWebscript.isContentDirectUrlEnabled()); + } + + @Test + public void testDisabledConfig_RestEnabledAndSystemwideDisabled() + { + mockedAsserts(ENABLED,DISABLED); + assertFalse("Direct Access URLs are disabled system-wide",discoveryApiWebscript.isContentDirectUrlEnabled()); + } + + @Test + public void testDisabledConfig_RestDisabledAndSystemwideDisabled() + { + mockedAsserts(DISABLED,DISABLED); + assertFalse("REST API Direct Access URLs are disabled and Direct Access URLs are disabled system-wide ",discoveryApiWebscript.isContentDirectUrlEnabled()); + } + + @Test + public void testDisabledConfig_RestDisabledAndSystemwideEnabled() + { + mockedAsserts(DISABLED,ENABLED); + assertFalse("REST API direct access URLs are disabled",discoveryApiWebscript.isContentDirectUrlEnabled()); + } + +} diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/DiscoveryApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/DiscoveryApiTest.java index 6cfbdb9885..f244401350 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/DiscoveryApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/DiscoveryApiTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -185,6 +185,7 @@ public class DiscoveryApiTest extends AbstractSingleNetworkSiteTest assertTrue(statusInfo.getIsAuditEnabled()); assertTrue(statusInfo.getIsQuickShareEnabled()); assertTrue(statusInfo.getIsThumbnailGenerationEnabled()); + assertFalse(statusInfo.getIsDirectAccessUrlEnabled()); // Check modules List modulePackageList = repositoryInfo.getModules(); diff --git a/repository/src/main/resources/alfresco/public-services-security-context.xml b/repository/src/main/resources/alfresco/public-services-security-context.xml index 0129319643..d0506a5e62 100644 --- a/repository/src/main/resources/alfresco/public-services-security-context.xml +++ b/repository/src/main/resources/alfresco/public-services-security-context.xml @@ -496,6 +496,7 @@ org.alfresco.service.cmr.repository.ContentService.getWriter=ACL_NODE.0.sys:base.WriteContent org.alfresco.service.cmr.repository.ContentService.getDirectAccessUrl=ACL_NODE.0.sys:base.ReadContent org.alfresco.service.cmr.repository.ContentService.getTempWriter=ACL_ALLOW + org.alfresco.service.cmr.repository.ContentService.isContentDirectUrlEnabled=ACL_ALLOW org.alfresco.service.cmr.repository.ContentService.*=ACL_DENY