Merge remote-tracking branch 'origin/master' into feature/RM-6645_ArchiveAndRestoreActionsInexistentInRMSite

This commit is contained in:
ehardon
2020-04-14 17:49:16 +03:00
13 changed files with 746 additions and 35 deletions

View File

@@ -4,7 +4,7 @@
Please refer to our [How to contribute](/CONTRIBUTING.md) guide and our [Contributor Covenant Code of Conduct](/CODE_OF_CONDUCT.md).
## Configuring and starting Alfresco/Share
* Clone the project (e.g. `git clone git@gitlab.alfresco.com:records-management/records-management.git`)
* Clone the project (e.g. `git clone git@github.com:Alfresco/governance-services.git`)
* Import the project as a maven project
* Start the Alfresco/Share instances with the following commands:

View File

@@ -15,9 +15,9 @@
</organization>
<scm>
<connection>scm:git:https://git.alfresco.com/records-management/records-management.git</connection>
<developerConnection>scm:git:https://git.alfresco.com/records-management/records-management.git</developerConnection>
<url>https://git.alfresco.com/records-management/records-management</url>
<connection>scm:git:https://github.com/Alfresco/governance-services.git</connection>
<developerConnection>scm:git:https://github.com/Alfresco/governance-services.git</developerConnection>
<url>https://github.com/Alfresco/governance-services</url>
<tag>HEAD</tag>
</scm>

View File

@@ -87,12 +87,20 @@ public class RestAPIFactory
return getRmRestWrapper().withCoreAPI();
}
private SearchAPI getSearchAPI(UserModel userModel)
public SearchAPI getSearchAPI(UserModel userModel)
{
getRmRestWrapper().authenticateUser(userModel != null ? userModel : getDataUser().getAdminUser());
return getRmRestWrapper().withSearchAPI();
}
/**
* When no user is given the default is set to admin
*/
public SearchAPI getSearchAPI()
{
return getSearchAPI(null);
}
public Node getNodeAPI(RepoTestModel model) throws RuntimeException
{
try

View File

@@ -0,0 +1,94 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2020 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.rest.core.search;
import java.util.List;
import org.alfresco.rest.search.Pagination;
import org.alfresco.rest.search.RestRequestQueryModel;
import org.alfresco.rest.search.SearchRequest;
/**
* Builder class for creating a search api request
*/
public class SearchRequestBuilder extends SearchRequest
{
/**
* Constructor for Search API Request
*/
public SearchRequestBuilder()
{
new SearchRequest();
}
/**
* Set the sql statement for the SearchRequest
*
* @param query sql statement
* @return search request
*/
public SearchRequestBuilder setQueryBuilder(RestRequestQueryModel query)
{
super.setQuery(query);
return this;
}
/**
* Set the paging statement for the SearchRequest
*
* @param paging pagination requested
* @return search request
*/
public SearchRequestBuilder setPagingBuilder(Pagination paging)
{
super.setPaging(paging);
return this;
}
/**
* Set the pagination properties
*/
public Pagination setPagination(Integer maxItems, Integer skipCount)
{
Pagination pagination = new Pagination();
pagination.setMaxItems(maxItems);
pagination.setSkipCount(skipCount);
return pagination;
}
/**
* Set the requested fields for the SearchRequest
*
* @param fields requested fields
* @return search request
*/
public SearchRequestBuilder setFieldsBuilder(List<String> fields)
{
super.setFields(fields);
return this;
}
}

View File

@@ -0,0 +1,191 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2020 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.rest.rm.community.search;
import static java.util.Arrays.asList;
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
import static org.alfresco.utility.report.log.Step.STEP;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.alfresco.rest.core.search.SearchRequestBuilder;
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.search.RestRequestQueryModel;
import org.alfresco.rest.search.SearchResponse;
import org.alfresco.rest.v0.UserTrashcanAPI;
import org.alfresco.utility.Utility;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType;
import org.alfresco.utility.model.SiteModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
* This class contains the tests for v1 Search API with documents with CMIS and AFTS queries
*/
public class SearchDocumentsV1Test extends BaseRMRestTest
{
private static final String SEARCH_TERM = generateTestPrefix(SearchDocumentsV1Test.class);
private SiteModel collaborationSite;
private FileModel fileModel;
@Autowired
private UserTrashcanAPI userTrashcanAPI;
/**
* Data Provider with: queries using CMIS and AFTS languages
*/
@DataProvider
public static Object[][] queryTypes()
{
RestRequestQueryModel cmisQueryModel = new RestRequestQueryModel();
cmisQueryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE '%" + SEARCH_TERM + ".txt'");
cmisQueryModel.setLanguage("cmis");
RestRequestQueryModel aftsQueryModel = new RestRequestQueryModel();
aftsQueryModel.setQuery("cm:name:*" + SEARCH_TERM);
aftsQueryModel.setLanguage("afts");
return new RestRequestQueryModel[][] {
{ cmisQueryModel },
{ aftsQueryModel }
};
}
/**
* Create a collaboration site and some documents.
*/
@BeforeClass (alwaysRun = true)
public void setupSearchDocumentsV1Test() throws Exception
{
STEP("Create a collaboration site");
collaborationSite = dataSite.usingAdmin().createPrivateRandomSite();
STEP("Create 10 documents ending with SEARCH_TERM");
for (int i = 0; ++i <= 10; )
{
fileModel = new FileModel(String.format("%s.%s", "Doc" + i + SEARCH_TERM, FileType.TEXT_PLAIN.extension));
dataContent.usingAdmin().usingSite(collaborationSite).createContent(fileModel);
}
waitIndexing();
}
/**
* Do the query to wait for solr indexing
*
* @throws Exception when maximum retry period is reached
*/
private void waitIndexing() throws Exception
{
RestRequestQueryModel queryType = new RestRequestQueryModel();
queryType.setQuery("cm:name:*" + SEARCH_TERM);
queryType.setLanguage("afts");
Utility.sleep(1000, 80000, () ->
{
SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
.setPagingBuilder(new SearchRequestBuilder().setPagination(100, 0))
.setFieldsBuilder(asList("id", "name"));
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest);
assertEquals(searchResponse.getPagination().getTotalItems().intValue(), 10,
"Total number of items is not retrieved yet");
});
}
/**
* Given some documents ending with a particular text
* When executing the search query with paging
* And setting the skipCount and maxItems to reach the number of total items
* Then hasMoreItems will be set to false
*/
@Test(dataProvider = "queryTypes")
public void searchWhenMaxItemsReach(RestRequestQueryModel queryType)
{
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5))
.setFieldsBuilder(asList("id", "name"));
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI().search(sqlRequest);
assertEquals(searchResponse.getPagination().getCount(), 5, "Expected maxItems to be five");
assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five");
assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
assertEquals(searchResponse.getEntries().size(), 5, "Expected total entries to be five");
}
/**
* Given some documents ending with a particular text
* When executing the search query with paging
* And setting skipCount and maxItems to exceed the number of total items
* Then hasMoreItems will be set to false
*/
@Test(dataProvider = "queryTypes")
public void searchWhenTotalItemsExceed(RestRequestQueryModel queryType)
{
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6))
.setFieldsBuilder(asList("id", "name"));
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI().search(sqlRequest);
assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
assertEquals(searchResponse.getPagination().getSkipCount(), 6, "Expected skip count to be six");
assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
}
/**
* Given some documents ending with a particular text
* When executing the search query with paging
* And setting skipCount and maxItems under the number of total items
* Then hasMoreItems will be set to true
*/
@Test(dataProvider = "queryTypes")
public void searchResultsUnderTotalItems(RestRequestQueryModel queryType)
{
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
.setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5))
.setFieldsBuilder(asList("id", "name"));
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI().search(sqlRequest);
assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five");
assertTrue(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be true");
assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
}
@AfterClass (alwaysRun = true)
public void tearDown()
{
dataSite.usingAdmin().deleteSite(collaborationSite);
userTrashcanAPI.emptyTrashcan(getAdminUser().getUsername(), getAdminUser().getPassword());
}
}

View File

@@ -0,0 +1,230 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2020 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.rest.rm.community.search;
import static java.util.Arrays.asList;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_MANAGER;
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
import static org.alfresco.utility.report.log.Step.STEP;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.alfresco.rest.core.search.SearchRequestBuilder;
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
import org.alfresco.rest.rm.community.model.user.UserPermissions;
import org.alfresco.rest.search.RestRequestQueryModel;
import org.alfresco.rest.search.SearchResponse;
import org.alfresco.rest.v0.UserTrashcanAPI;
import org.alfresco.rest.v0.service.RoleService;
import org.alfresco.utility.Utility;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* This class contains the tests for v1 Search API with records with CMIS query
*/
public class SearchRecordsV1CmisTests extends BaseRMRestTest
{
private static final String SEARCH_TERM = generateTestPrefix(SearchRecordsV1CmisTests.class);
private SiteModel collaborationSite;
private UserModel nonRMUser, rmUser;
private FileModel fileModel;
private RestRequestQueryModel queryModel;
@Autowired
private UserTrashcanAPI userTrashcanAPI;
@Autowired
private RoleService roleService;
/**
* Create a collaboration site and some in place records.
*/
@BeforeClass (alwaysRun = true)
public void setupSearchRecordsV1Cmis() throws Exception
{
STEP("Create a collaboration site");
collaborationSite = dataSite.usingAdmin().createPrivateRandomSite();
STEP("Create a site manager user for the collaboration site");
nonRMUser = getDataUser().createRandomTestUser();
getDataUser().addUserToSite(nonRMUser, collaborationSite, UserRole.SiteManager);
STEP("Create an rm user");
rmUser = getDataUser().createRandomTestUser();
STEP("Create 10 documents and declare as records");
for (int i = 0; ++i <= 10; )
{
fileModel = new FileModel(String.format("%s.%s", "Record" + SEARCH_TERM + i, FileType.TEXT_PLAIN.extension));
fileModel = dataContent.usingUser(nonRMUser).usingSite(collaborationSite).createContent(fileModel);
getRestAPIFactory().getFilesAPI(nonRMUser).declareAsRecord(fileModel.getNodeRefWithoutVersion());
}
STEP("Create record folder and some records ");
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
roleService.assignUserPermissionsOnCategoryAndRMRole(rmUser, recordFolder.getId(),
UserPermissions.PERMISSION_READ_RECORDS, ROLE_RM_MANAGER.roleId);
for (int i = 0; ++i <= 10; )
{
createElectronicRecord(recordFolder.getId(), "Record" + SEARCH_TERM + i);
}
queryModel = new RestRequestQueryModel();
queryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE 'Record" + SEARCH_TERM + "%'");
queryModel.setLanguage("cmis");
//wait for solr indexing
Utility.sleep(1000, 80000, () ->
{
SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
.setPagingBuilder(new SearchRequestBuilder().setPagination(100, 0))
.setFieldsBuilder(asList("id", "name"));
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest);
assertEquals(searchResponse.getPagination().getTotalItems().intValue(), 20,
"Total number of items is not retrieved yet");
});
}
/**
* Given some documents with names starting with a particular test
* When executing the search query with paging
* And setting the skipCount and maxItems to reach the number of total items
* Then hasMoreItems will be set to false
*/
@Test
public void searchWhenTotalItemsReach()
{
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 15))
.setFieldsBuilder(asList("id", "name"));
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest);
assertEquals(searchResponse.getPagination().getCount(), 5, "Expected maxItems to be five");
assertEquals(searchResponse.getPagination().getSkipCount(), 15, "Expected skip count to be fifteen");
assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
assertEquals(searchResponse.getEntries().size(), 5, "Expected total entries to be five");
}
@Test
public void searchWhenTotalItemsReachWithNonRM()
{
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 0))
.setFieldsBuilder(asList("id", "name"));
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest);
assertEquals(searchResponse.getPagination().getCount(), 5, "Expected maxItems to be five");
assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five");
assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
assertEquals(searchResponse.getEntries().size(), 5, "Expected total entries to be five");
}
/**
* Given some documents with names starting with a particular text
* When executing the search query with paging
* And setting skipCount and maxItems to exceed the number of total items
* Then hasMoreItems will be set to false
*/
@Test
public void searchWhenTotalItemsExceedRMUser()
{
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 16))
.setFieldsBuilder(asList("id", "name"));
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest);
assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
assertEquals(searchResponse.getPagination().getSkipCount(), 16, "Expected skip count to be sixteen");
assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
}
@Test
public void searchWhenTotalItemsExceedNonRMUser()
{
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6))
.setFieldsBuilder(asList("id", "name"));
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest);
assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
assertEquals(searchResponse.getPagination().getSkipCount(), 6, "Expected skip count to be six");
assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
}
/**
* Given some documents ending with a particular text
* When executing the search query with paging
* And setting skipCount and maxItems under the number of total items
* Then hasMoreItems will be set to true
*/
@Test
public void searchResultsUnderTotalItemsRMUser()
{
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
.setPagingBuilder(new SearchRequestBuilder().setPagination(4, 15))
.setFieldsBuilder(asList("id", "name"));
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest);
assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
assertEquals(searchResponse.getPagination().getSkipCount(), 15, "Expected skip count to be fifteen");
assertTrue(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be true");
assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
}
@Test
public void searchResultsUnderTotalItemsNonRMUser()
{
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
.setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5))
.setFieldsBuilder(asList("id", "name"));
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest);
assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five");
assertTrue(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be true");
assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
}
@AfterClass (alwaysRun = true)
public void tearDown()
{
dataSite.usingAdmin().deleteSite(collaborationSite);
userTrashcanAPI.emptyTrashcan(getAdminUser().getUsername(), getAdminUser().getPassword());
}
}

View File

@@ -19,7 +19,7 @@ Recorded content can be explicitly destroyed whilst maintaining the original nod
### Artifacts and Guidance
* Source Code Link: [GitLab](https://gitlab.alfresco.com/records-management/records-management/tree/master)
* Source Code Link: [GitHub](https://github.com/Alfresco/records-management)
* License: Alfresco Community
* Issue Tracker Link: [JIRA RM](https://issues.alfresco.com/jira/projects/RM/summary)
* Contribution Model: Alfresco Closed Source

View File

@@ -17,7 +17,7 @@ RM is split into two main parts - a repository integration and a Share integrati
### Artifacts and Guidance
* [Community Source Code](https://github.com/Alfresco/records-management)
* [Enterprise Source Code](https://gitlab.alfresco.com/records-management/records-management) (for partners and customers)
* [Enterprise Source Code](https://github.com/Alfresco/governance-services) (for partners and customers)
* [Community License](../LICENSE.txt)
* [Enterprise License](../../rm-enterprise/LICENSE.txt) (this file will only be present in clones of the Enterprise repository)
* [Issue Tracker Link](https://issues.alfresco.com/jira/projects/RM)

View File

@@ -159,6 +159,7 @@
<property name="maxPermissionChecks">
<value>${system.acl.maxPermissionChecks}</value>
</property>
<property name="authenticationUtil" ref="rm.authenticationUtil" />
</bean>
<!-- Link up after method call security -->

View File

@@ -46,10 +46,10 @@ import net.sf.acegisecurity.vote.AccessDecisionVoter;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.repo.search.SimpleResultSetMetaData;
import org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet;
import org.alfresco.repo.search.impl.querymodel.QueryEngineResults;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.permissions.PermissionCheckCollection;
import org.alfresco.repo.security.permissions.PermissionCheckValue;
import org.alfresco.repo.security.permissions.PermissionCheckedCollection.PermissionCheckedCollectionMixin;
@@ -80,8 +80,8 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
private static final String AFTER_RM = "AFTER_RM";
private AuthenticationUtil authenticationUtil;
private int maxPermissionChecks;
private long maxPermissionCheckTimeMillis;
public boolean supports(ConfigAttribute configAttribute)
@@ -131,6 +131,16 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
this.maxPermissionCheckTimeMillis = maxPermissionCheckTimeMillis;
}
/**
* Sets the authentication util
*
* @param authenticationUtil The authentication util to set
*/
public void setAuthenticationUtil(AuthenticationUtil authenticationUtil)
{
this.authenticationUtil = authenticationUtil;
}
@SuppressWarnings("rawtypes")
public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config, Object returnedObject)
{
@@ -148,7 +158,7 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
}
try
{
if (AuthenticationUtil.isRunAsUserTheSystemUser())
if (authenticationUtil.isRunAsUserTheSystemUser())
{
if (logger.isDebugEnabled())
{
@@ -564,6 +574,13 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
}
}
if (maxSize != null)
{
LimitBy limitBy = returnedObject.length() > maxSize ? LimitBy.FINAL_SIZE : LimitBy.UNLIMITED;
filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(limitBy,
PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
}
filteringResultSet.setNumberFound(returnedObject.getNumberFound());
return filteringResultSet;

View File

@@ -26,8 +26,7 @@
*/
package org.alfresco.module.org_alfresco_module_rm.util;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.QName;
@@ -41,11 +40,12 @@ import org.alfresco.util.ParameterCheck;
*/
public class NodeTypeUtility
{
/** Static cache for results of types that are instances of other Alfresco types. */
private static ConcurrentHashMap<String, Boolean> instanceOfCache = new ConcurrentHashMap<>();
/** Dictionary service */
private DictionaryService dictionaryService;
private static Map<String, Boolean> instanceOfCache = new WeakHashMap<>();
/**
* @param dictionaryService dictionary service
*/
@@ -66,24 +66,8 @@ public class NodeTypeUtility
ParameterCheck.mandatory("className", className);
ParameterCheck.mandatory("ofClassName", ofClassName);
boolean result = false;
String key = className.toString() + "|" + ofClassName.toString();
if (instanceOfCache.containsKey(key))
{
result = instanceOfCache.get(key);
}
else
{
if (ofClassName.equals(className) ||
dictionaryService.isSubClass(className, ofClassName))
{
result = true;
}
instanceOfCache.put(key, result);
}
return result;
return instanceOfCache.computeIfAbsent(key, k ->
(ofClassName.equals(className) || dictionaryService.isSubClass(className, ofClassName)));
}
}

View File

@@ -0,0 +1,181 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2020 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.module.org_alfresco_module_rm.capability;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import java.util.List;
import net.sf.acegisecurity.Authentication;
import net.sf.acegisecurity.ConfigAttribute;
import net.sf.acegisecurity.ConfigAttributeDefinition;
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.LimitBy;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetMetaData;
import org.alfresco.service.cmr.search.SearchParameters;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
/** Unit tests for {@link RMAfterInvocationProvider}. */
public class RMAfterInvocationProviderUnitTest
{
private static final NodeRef NODE_A = new NodeRef("test://node/a");
/** The class under test. */
@InjectMocks
private RMAfterInvocationProvider rmAfterInvocationProvider;
@Mock
private Authentication authentication;
@Mock
Object object;
@Mock
ConfigAttributeDefinition config;
@Mock
AuthenticationUtil authenticationUtil;
@Mock
NodeService nodeService;
@Mock
ChildAssociationRef childAssocRefA;
/** Set up the mocks and common test data. */
@Before
public void setUp()
{
initMocks(this);
// Set up the nodes and associations.
when(nodeService.exists(NODE_A)).thenReturn(true);
when(childAssocRefA.getParentRef()).thenReturn(NODE_A);
// Create the config object for use by the tests.
ConfigAttribute configAttribute = mock(ConfigAttribute.class);
when(configAttribute.getAttribute()).thenReturn("AFTER_RM.test");
List<ConfigAttribute> configAttributes = asList(configAttribute);
when(config.getConfigAttributes()).thenReturn(configAttributes.iterator());
}
/** Check that when all the results fit into a page then we get a response of "UNLIMITED". */
@Test
public void testDecide_resultSet_unlimited()
{
// The returned object is a search result set.
ResultSet returnedObject = mock(ResultSet.class);
ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
when(returnedObject.getResultSetMetaData()).thenReturn(resultSetMetaData);
// Simulate a single result, and the user has access to it.
when(returnedObject.length()).thenReturn(1);
when(returnedObject.getNumberFound()).thenReturn(1L);
when(returnedObject.getNodeRef(0)).thenReturn(NODE_A);
when(returnedObject.getChildAssocRef(0)).thenReturn(childAssocRefA);
// Set the page size to 1 and skip count to 0.
SearchParameters searchParameters = mock(SearchParameters.class);
when(searchParameters.getMaxItems()).thenReturn(1);
when(searchParameters.getSkipCount()).thenReturn(0);
when(searchParameters.getLanguage()).thenReturn("afts");
when(resultSetMetaData.getSearchParameters()).thenReturn(searchParameters);
// Call the method under test.
FilteringResultSet filteringResultSet = (FilteringResultSet) rmAfterInvocationProvider.decide(authentication, object, config, returnedObject);
assertEquals("Expected total of one result.", 1, filteringResultSet.getNumberFound());
assertEquals("Expected one result returned.", 1, filteringResultSet.length());
assertEquals("Expected that results were not limited by the page size.", LimitBy.UNLIMITED, filteringResultSet.getResultSetMetaData().getLimitedBy());
}
/** Check that results can skipped due to the skip count. */
@Test
public void testDecide_resultSet_skipped()
{
// The returned object is a search result set.
ResultSet returnedObject = mock(ResultSet.class);
ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
when(returnedObject.getResultSetMetaData()).thenReturn(resultSetMetaData);
// Simulate a single result that was skipped due to the skip count.
when(returnedObject.length()).thenReturn(0);
when(returnedObject.getNumberFound()).thenReturn(1L);
// Set the page size to 1 and skip count to 1 (so the result is skipped).
SearchParameters searchParameters = mock(SearchParameters.class);
when(searchParameters.getMaxItems()).thenReturn(1);
when(searchParameters.getSkipCount()).thenReturn(1);
when(searchParameters.getLanguage()).thenReturn("afts");
when(resultSetMetaData.getSearchParameters()).thenReturn(searchParameters);
// Call the method under test.
FilteringResultSet filteringResultSet = (FilteringResultSet) rmAfterInvocationProvider.decide(authentication, object, config, returnedObject);
assertEquals("Expected total of one result.", 1, filteringResultSet.getNumberFound());
assertEquals("Expected no results returned.", 0, filteringResultSet.length());
assertEquals("Expected that results were not limited by the page size.", LimitBy.UNLIMITED, filteringResultSet.getResultSetMetaData().getLimitedBy());
}
/** Check that results can be limited by the page size. */
@Test
public void testDecide_resultSet_pageSize()
{
// The returned object is a search result set.
ResultSet returnedObject = mock(ResultSet.class);
ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
when(returnedObject.getResultSetMetaData()).thenReturn(resultSetMetaData);
// Simulate a single result, and the user has access to it.
when(returnedObject.length()).thenReturn(1);
when(returnedObject.getNumberFound()).thenReturn(1L);
when(returnedObject.getNodeRef(0)).thenReturn(NODE_A);
when(returnedObject.getChildAssocRef(0)).thenReturn(childAssocRefA);
// Set the page size to 0 and skip count to 0 (so the result is not in page).
SearchParameters searchParameters = mock(SearchParameters.class);
when(searchParameters.getMaxItems()).thenReturn(0);
when(searchParameters.getSkipCount()).thenReturn(0);
when(searchParameters.getLanguage()).thenReturn("afts");
when(resultSetMetaData.getSearchParameters()).thenReturn(searchParameters);
// Call the method under test.
FilteringResultSet filteringResultSet = (FilteringResultSet) rmAfterInvocationProvider.decide(authentication, object, config, returnedObject);
assertEquals("Expected total of one result.", 1, filteringResultSet.getNumberFound());
assertEquals("Expected no results returned.", 0, filteringResultSet.length());
assertEquals("Expected that results were limited by page size.", LimitBy.FINAL_SIZE, filteringResultSet.getResultSetMetaData().getLimitedBy());
}
}

View File

@@ -10,5 +10,10 @@ if [ "$docker_images_list" == "" ]; then
echo "No docker images on the agent"
else
echo "Clearing images: $docker_images_list"
docker rmi -f $docker_images_list
if docker rmi -f $docker_images_list ; then
echo "Deleting images was successful."
else
echo "Deleting specified images failed, so falling back to delete ALL images on system."
docker rmi -f $(docker images -aq)
fi
fi