mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-09-10 14:11:58 +00:00
Compare commits
66 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
088d8f9448 | ||
|
0d43100018 | ||
|
93800b6906 | ||
|
82f8b938a6 | ||
|
8727ee18e8 | ||
|
a688d475dc | ||
|
83b1c323de | ||
|
e063e1d816 | ||
|
65c62c7d03 | ||
|
7a6949a059 | ||
|
1a0e45b6c8 | ||
|
1d1dead902 | ||
|
6a69b3fd86 | ||
|
f391cfa38c | ||
|
fbef1156a8 | ||
|
5d93c2efd4 | ||
|
c94807cd8c | ||
|
ff979314ae | ||
|
7f6bd86b0c | ||
|
fd2f793722 | ||
|
489b0058fe | ||
|
14572d328f | ||
|
759927c37b | ||
|
42ef2160ef | ||
|
4f561166b7 | ||
|
295a8f7ba2 | ||
|
fd73ebe45a | ||
|
3bbaabd755 | ||
|
ed50b9bb9b | ||
|
361a674a19 | ||
|
9f839b5372 | ||
|
c76d3b99c4 | ||
|
4998f19da9 | ||
|
b1340d12ef | ||
|
2b79a4489d | ||
|
e41fc6af02 | ||
|
162264a8d7 | ||
|
a5977fedb2 | ||
|
024e4e072b | ||
|
5c33911e5f | ||
|
2a6eb91ebd | ||
|
c588b915d5 | ||
|
4e2384fd9a | ||
|
6071188405 | ||
|
4c2d9ef64d | ||
|
f71f243b9b | ||
|
3f10227c0f | ||
|
a361596512 | ||
|
4ad2bda8b9 | ||
|
1339dd59a9 | ||
|
9dad28ee4d | ||
|
308dd9825a | ||
|
609aa750d6 | ||
|
def0201274 | ||
|
a7d885c630 | ||
|
3fcbb076a2 | ||
|
9ab4d29ff6 | ||
|
1388a76dc7 | ||
|
1944186ef8 | ||
|
66ea8c0534 | ||
|
571f4b121d | ||
|
2f2e7ade80 | ||
|
2d69d44049 | ||
|
6ad58b137e | ||
|
4c086751e6 | ||
|
7cb98f2d5d |
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-amps</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-parent</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-automation-community-repo</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
|
@@ -26,6 +26,7 @@
|
||||
*/
|
||||
package org.alfresco.rest.v0;
|
||||
|
||||
import static org.apache.http.HttpStatus.SC_OK;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -36,6 +37,7 @@ import java.util.List;
|
||||
import org.alfresco.rest.core.v0.BaseAPI;
|
||||
import org.alfresco.rest.rm.community.model.audit.AuditEntry;
|
||||
import org.alfresco.rest.rm.community.util.PojoUtility;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
@@ -58,6 +60,8 @@ public class RMAuditAPI extends BaseAPI
|
||||
private static final String RM_AUDIT_API = "{0}rma/admin/rmauditlog";
|
||||
private static final String RM_AUDIT_LOG_API = RM_AUDIT_API + "?{1}";
|
||||
|
||||
private static final String RM_AUDIT_LOG_AS_RECORD = "{0}node/{1}/rmauditlog";
|
||||
|
||||
/**
|
||||
* Returns a list of rm audit entries .
|
||||
*
|
||||
@@ -84,6 +88,21 @@ public class RMAuditAPI extends BaseAPI
|
||||
return PojoUtility.jsonToObject(auditEntries, AuditEntry.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of rm audit entries .
|
||||
*
|
||||
* @param user The username of the user to use.
|
||||
* @param password The password of the user.
|
||||
* @param size Maximum number of log entries to return
|
||||
* @return return All return log entries
|
||||
*/
|
||||
public List<AuditEntry> getRMAuditLogAll(String user, String password, final int size) {
|
||||
String parameters = "size=" + size;
|
||||
JSONArray auditEntries = doGetRequest(user, password,
|
||||
MessageFormat.format(RM_AUDIT_LOG_API,"{0}", parameters)).getJSONObject("data").getJSONArray("entries");
|
||||
return PojoUtility.jsonToObject(auditEntries, AuditEntry.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the list of audit entries.
|
||||
*
|
||||
@@ -100,5 +119,19 @@ public class RMAuditAPI extends BaseAPI
|
||||
&& getRMAuditLog(username, password, 100, null).size() == 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the Audit Log as Record.
|
||||
*
|
||||
* @param username The username of the user to use.
|
||||
* @param password The password of the user.
|
||||
* @param recNodeRef The Record Node reference for which Audit log should be created as record
|
||||
* @param destinationNodeRef The Folder id Node reference where the html file should be placed
|
||||
* @throws AssertionError If the API call didn't create the Audit Log as Record.
|
||||
*/
|
||||
public HttpResponse logsAuditLogAsRecord(String username, String password, String recNodeRef, String destinationNodeRef) {
|
||||
JSONObject requestParams = new JSONObject();
|
||||
requestParams.put("destination", destinationNodeRef);
|
||||
return doPostJsonRequest(username, password, SC_OK, requestParams, RM_AUDIT_LOG_AS_RECORD,recNodeRef);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -97,4 +97,16 @@ public class RecordFoldersAPI extends BaseAPI
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public HttpResponse reOpenRecordFolder(String user, String password, String recordFolder)
|
||||
{
|
||||
String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordFolder);
|
||||
|
||||
JSONObject requestParams = new JSONObject();
|
||||
requestParams.put("name", "openRecordFolder");
|
||||
requestParams.put("nodeRef", recNodeRef);
|
||||
|
||||
return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -360,4 +360,25 @@ public class RecordsAPI extends BaseAPI
|
||||
{
|
||||
return getNodeRefSpacesStore() + getItemNodeRef(username, password, recordPath + "/" + recordName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reopens the record given as parameter
|
||||
*
|
||||
* @param user the user declaring the document as record
|
||||
* @param password the user's password
|
||||
* @param recordName the record name
|
||||
* @return The HTTP Response.
|
||||
*/
|
||||
|
||||
public HttpResponse reOpenRecord(String user, String password, String recordName)
|
||||
{
|
||||
String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordName);
|
||||
|
||||
JSONObject requestParams = new JSONObject();
|
||||
requestParams.put("name", "undeclareRecord");
|
||||
requestParams.put("nodeRef", recNodeRef);
|
||||
|
||||
return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.audit;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.*;
|
||||
import static org.alfresco.rest.rm.community.model.audit.AuditEvents.ADD_TO_HOLD;
|
||||
import static org.alfresco.rest.rm.community.model.audit.AuditEvents.REMOVE_FROM_HOLD;
|
||||
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomName;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.testng.AssertJUnit.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.alfresco.dataprep.CMISUtil;
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.audit.AuditEntry;
|
||||
import org.alfresco.rest.rm.community.model.audit.AuditEvents;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolder;
|
||||
import org.alfresco.rest.rm.community.model.user.UserRoles;
|
||||
import org.alfresco.rest.v0.HoldsAPI;
|
||||
import org.alfresco.rest.v0.service.RMAuditService;
|
||||
import org.alfresco.rest.v0.service.RoleService;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
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.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
public class AuditHoldsTest extends BaseRMRestTest {
|
||||
private final String PREFIX = generateTestPrefix(AuditAddToHoldTests.class);
|
||||
private final String HOLD1 = PREFIX + "hold1";
|
||||
private SiteModel publicSite;
|
||||
private FileModel testFile;
|
||||
@Autowired
|
||||
private RMAuditService rmAuditService;
|
||||
@Autowired
|
||||
private HoldsAPI holdsAPI;
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
private UserModel rmAdmin;
|
||||
private RecordCategory recordCategory;
|
||||
private RecordCategoryChild recordFolder1,recordFolder2;
|
||||
private List<AuditEntry> auditEntries;
|
||||
private String hold1NodeRef;
|
||||
public static final String RECORD_FOLDER_THREE = "record-folder-three";
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void preconditionForAuditAddToHoldTests()
|
||||
{
|
||||
createRMSiteIfNotExists();
|
||||
rmAdmin = roleService.createUserWithRMRole(UserRoles.ROLE_RM_ADMIN.roleId);
|
||||
|
||||
STEP("Create a hold");
|
||||
hold1NodeRef = holdsAPI.createHoldAndGetNodeRef(rmAdmin.getUsername(), rmAdmin.getPassword(), HOLD1, HOLD_REASON,
|
||||
HOLD_DESCRIPTION);
|
||||
|
||||
STEP("Create a collaboration site with a test file.");
|
||||
publicSite = dataSite.usingAdmin().createPublicRandomSite();
|
||||
testFile = dataContent.usingAdmin().usingSite(publicSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
|
||||
|
||||
STEP("Create a record category with 2 folders and 1 record");
|
||||
recordCategory = createRootCategory(getRandomName("recordCategory"));
|
||||
recordFolder1 = createRecordFolder(recordCategory.getId(), PREFIX + "recFolder1");
|
||||
recordFolder2 = createRecordFolder(recordCategory.getId(), PREFIX + "recFolder2");
|
||||
Record recordToBeAdded = createElectronicRecord(recordFolder1.getId(), PREFIX + "record");
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
STEP("Add some items to the hold, then remove them from the hold");
|
||||
final List<String> itemsList = asList(testFile.getNodeRefWithoutVersion(), recordToBeAdded.getId(), recordFolder2.getId());
|
||||
final List<String> holdsList = Collections.singletonList(HOLD1);
|
||||
holdsAPI.addItemToHold(rmAdmin.getUsername(), rmAdmin.getPassword(), recordToBeAdded.getId(), HOLD1);
|
||||
holdsAPI.removeItemsFromHolds(rmAdmin.getUsername(), rmAdmin.getPassword(), itemsList, holdsList);
|
||||
|
||||
STEP("Delete the record folder that was held");
|
||||
getRestAPIFactory().getRecordFolderAPI().deleteRecordFolder(recordFolder2.getId());
|
||||
|
||||
STEP("Rename the parent of the record that was held");
|
||||
RecordFolder recordFolder = RecordFolder.builder().name(RECORD_FOLDER_THREE).build();
|
||||
getRestAPIFactory().getRecordFolderAPI().updateRecordFolder(recordFolder, recordFolder1.getId());
|
||||
}
|
||||
/**
|
||||
* Data provider with hold events that have links to held items
|
||||
*
|
||||
* @return the hold events
|
||||
*/
|
||||
@DataProvider (name = "holdsEvents")
|
||||
public Object[][] getHoldEvents()
|
||||
{
|
||||
return new AuditEvents[][]
|
||||
{
|
||||
{ ADD_TO_HOLD },
|
||||
{ REMOVE_FROM_HOLD }
|
||||
};
|
||||
}
|
||||
@Test (dataProvider = "holdsEvents")
|
||||
public void checkItemPathLink(AuditEvents event) {
|
||||
auditEntries = rmAuditService.getAuditEntriesFilteredByEvent(getAdminUser(), event);
|
||||
assertFalse("Audit results should not be empty",auditEntries.size()==0);
|
||||
final String auditedEvent = event + " - " + testFile.getName();
|
||||
assertTrue("Audit results should contain one " + auditedEvent + " event",auditEntries.stream().anyMatch(e -> e.getEvent().startsWith(event.eventDisplayName)));
|
||||
STEP("Check the audit log contains only an entry for add to hold.");
|
||||
assertThat(auditEntries, is(not(empty())));
|
||||
}
|
||||
@AfterClass(alwaysRun = true)
|
||||
private void cleanup() {
|
||||
dataSite.usingAdmin().deleteSite(publicSite);
|
||||
deleteRecordFolder(recordFolder1.getId());
|
||||
deleteRecordFolder(recordFolder2.getId());
|
||||
deleteRecordCategory(recordCategory.getId());
|
||||
rmAuditService.clearAuditLog();
|
||||
}
|
||||
}
|
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.audit;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.audit.AuditEntry;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.v0.RMAuditAPI;
|
||||
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
|
||||
import org.alfresco.rest.v0.RecordsAPI;
|
||||
import org.alfresco.test.AlfrescoTest;
|
||||
import org.alfresco.utility.Utility;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.testng.AssertJUnit;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAspects.ASPECTS_COMPLETED_RECORD;
|
||||
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordModel;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.test.util.AssertionErrors.assertTrue;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
public class ElectronicRecordAuditLogTest extends BaseRMRestTest {
|
||||
|
||||
private Optional<UserModel> rmAdmin;
|
||||
@Autowired
|
||||
private RMRolesAndActionsAPI rmRolesAndActionsAPI;
|
||||
@Autowired
|
||||
private RMAuditAPI auditLog;
|
||||
@Autowired
|
||||
private RecordsAPI recordApi;
|
||||
/* electronic record details */
|
||||
private static final String AUDIT_ELECTRONIC_RECORD = generateTestPrefix(ElectronicRecordAuditLogTest.class) + "electronic record";
|
||||
private static final String AUDIT_COMPLETE_REOPEN_ELECTRONIC_RECORD = "Complete Reopen Electronic Record";
|
||||
public static final String TITLE = "Title";
|
||||
public static final String DESCRIPTION = "Description";
|
||||
private RecordCategory category1;
|
||||
private RecordCategoryChild recordFolder1;
|
||||
private Record electronicRecord, electronicRecord2;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void electronicRecordsAuditLogSetup()
|
||||
{
|
||||
createRMSiteIfNotExists();
|
||||
rmAdmin = Optional.ofNullable(getDataUser().createRandomTestUser());
|
||||
rmRolesAndActionsAPI.assignRoleToUser(
|
||||
getDataUser().usingAdmin().getAdminUser().getUsername(),
|
||||
getDataUser().usingAdmin().getAdminUser().getPassword(),
|
||||
rmAdmin.get().getUsername(),
|
||||
"Administrator");
|
||||
auditLog.clearAuditLog(rmAdmin.get().getUsername(),rmAdmin.get().getPassword());
|
||||
category1 = createRootCategory(TITLE, DESCRIPTION);
|
||||
recordFolder1 = createFolder(category1.getId(),TITLE);
|
||||
|
||||
electronicRecord = createElectronicRecord(recordFolder1.getId(),AUDIT_ELECTRONIC_RECORD,rmAdmin.get());
|
||||
}
|
||||
|
||||
@Test(description = "Audit log for newly filed electronic record")
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void newElectronicRecordAudit() {
|
||||
List<AuditEntry> auditEntries= auditLog.getRMAuditLogAll(getAdminUser().getUsername(),getAdminUser().getPassword(),100);
|
||||
|
||||
// newly created record contains 2 events: "file to" and metadata update
|
||||
// the order in which object creation and metadata update are listed isn't always identical due to
|
||||
// both happening in the same transaction
|
||||
assertTrue("File To Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("File to")));
|
||||
assertTrue("Updated metadata Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Updated Metadata")));
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
dependsOnMethods = "newElectronicRecordAudit",
|
||||
description = "Viewing electronic record audit log is itself an auditable event"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void electronicRecordAuditIsEvent()
|
||||
{
|
||||
List<AuditEntry> auditEntries= auditLog.getRMAuditLogAll(getAdminUser().getUsername(),getAdminUser().getPassword(),100);
|
||||
assertTrue("Audit View Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Audit View")));
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
dependsOnMethods = "electronicRecordAuditIsEvent",
|
||||
description = "Rename electronic record is an edit metadata event"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void renameElectronicRecord() {
|
||||
auditLog.clearAuditLog(rmAdmin.get().getUsername(),rmAdmin.get().getPassword());
|
||||
Record renameElectronicRecord = createRecordModel("edited " + electronicRecord.getName(), "", "");
|
||||
|
||||
// rename record
|
||||
getRestAPIFactory().getRecordsAPI().updateRecord(renameElectronicRecord, electronicRecord.getId());
|
||||
assertStatusCode(OK);
|
||||
|
||||
// we expect 1 new event: "metadata update"
|
||||
List<AuditEntry> auditEntries= auditLog.getRMAuditLogAll(getAdminUser().getUsername(),getAdminUser().getPassword(),100);
|
||||
assertTrue("Updated metadata Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Updated Metadata")));
|
||||
}
|
||||
|
||||
@Test (
|
||||
dependsOnMethods = "newElectronicRecordAudit",
|
||||
description = "Complete and reopen electronic record")
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void completeAndReopenElectronicRecord() {
|
||||
electronicRecord2 = createElectronicRecord(recordFolder1.getId(),AUDIT_COMPLETE_REOPEN_ELECTRONIC_RECORD);
|
||||
|
||||
// complete record
|
||||
recordApi.completeRecord(rmAdmin.get().getUsername(),rmAdmin.get().getPassword(),
|
||||
electronicRecord2.getName());
|
||||
|
||||
try
|
||||
{
|
||||
Utility.sleep(1000, 30000, () ->
|
||||
{
|
||||
org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
List<String> aspects = recordsAPI.getRecord(electronicRecord2.getId()).getAspectNames();
|
||||
// a record must be completed
|
||||
assertTrue("Record is not completed.",aspects.contains(ASPECTS_COMPLETED_RECORD));
|
||||
});
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
fail("InterruptedException received while waiting for results.");
|
||||
}
|
||||
|
||||
List<AuditEntry> auditEntries= auditLog.getRMAuditLogAll(getAdminUser().getUsername(),getAdminUser().getPassword(),100);
|
||||
assertTrue("Complete Record Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Complete Record")));
|
||||
|
||||
// Reopen record
|
||||
recordApi.reOpenRecord(rmAdmin.get().getUsername(),rmAdmin.get().getPassword(),
|
||||
electronicRecord2.getName());
|
||||
|
||||
try
|
||||
{
|
||||
Utility.sleep(1000, 30000, () ->
|
||||
{
|
||||
org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
List<String> aspects = recordsAPI.getRecord(electronicRecord2.getId()).getAspectNames();
|
||||
// a record mustn't be completed
|
||||
assertFalse(aspects.contains(ASPECTS_COMPLETED_RECORD));
|
||||
});
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
fail("InterruptedException received while waiting for results.");
|
||||
}
|
||||
|
||||
auditEntries= auditLog.getRMAuditLogAll(getAdminUser().getUsername(),getAdminUser().getPassword(),100);
|
||||
assertTrue("Reopen Record Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Reopen Record")));
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
dependsOnMethods = "completeAndReopenElectronicRecord",
|
||||
description = "File electronic record's audit log as record"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void fileElectronicRecordAuditLogAsRecord()
|
||||
{
|
||||
// audit log is stored in the same folder, refresh it so that it appears in the list
|
||||
HttpResponse auditRecordHttpResponse = auditLog.logsAuditLogAsRecord(rmAdmin.get().getUsername(),rmAdmin.get().getPassword(),
|
||||
getRecordNodeRef(electronicRecord2.getId()),getFolderNodeRef(recordFolder1.getId()));
|
||||
JSONObject auditRecordProperties = getAuditPropertyValues(auditRecordHttpResponse);
|
||||
Record auditRecord = getRestAPIFactory().getRecordsAPI().getRecord(auditRecordProperties.get("record").toString()
|
||||
.replace("workspace://SpacesStore/",""));
|
||||
// check audit log
|
||||
AssertJUnit.assertTrue(auditRecordProperties.get("recordName").toString().endsWith(".html"));
|
||||
AssertJUnit.assertTrue(auditRecord.getAspectNames().stream().noneMatch(x -> x.startsWith(ASPECTS_COMPLETED_RECORD)));
|
||||
}
|
||||
|
||||
private String getFolderNodeRef(String folderId) {
|
||||
return "workspace://SpacesStore/" + folderId;
|
||||
}
|
||||
|
||||
private String getRecordNodeRef(String recordId) {
|
||||
return "workspace/SpacesStore/" + recordId;
|
||||
}
|
||||
|
||||
private JSONObject getAuditPropertyValues(HttpResponse httpResponse) {
|
||||
HttpEntity entity = httpResponse.getEntity();
|
||||
String responseString = null;
|
||||
try {
|
||||
responseString = EntityUtils.toString(entity, "UTF-8");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
JSONObject result = new JSONObject(responseString);
|
||||
return result;
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
private void closeAuditLog() {
|
||||
auditLog.clearAuditLog(rmAdmin.get().getUsername(),rmAdmin.get().getPassword());
|
||||
}
|
||||
|
||||
@AfterClass(alwaysRun = true)
|
||||
private void electronicRecordAuditLogCleanup() {
|
||||
deleteRecord(electronicRecord.getId());
|
||||
deleteRecordFolder(recordFolder1.getId());
|
||||
deleteRecordCategory(category1.getId());
|
||||
dataUser.usingAdmin().deleteUser(new UserModel(rmAdmin.get().getUsername(), rmAdmin.get().getPassword()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.audit;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.audit.AuditEntry;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.v0.RMAuditAPI;
|
||||
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
|
||||
import org.alfresco.rest.v0.RecordsAPI;
|
||||
import org.alfresco.test.AlfrescoTest;
|
||||
import org.alfresco.utility.Utility;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.testng.AssertJUnit;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAspects.ASPECTS_COMPLETED_RECORD;
|
||||
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordModel;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.test.util.AssertionErrors.assertTrue;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
|
||||
public class NonElectronicRecordAuditLogTest extends BaseRMRestTest {
|
||||
private Optional<UserModel> rmAdmin;
|
||||
@Autowired
|
||||
private RMRolesAndActionsAPI rmRolesAndActionsAPI;
|
||||
@Autowired
|
||||
private RMAuditAPI auditLog;
|
||||
@Autowired
|
||||
private RecordsAPI recordApi;
|
||||
private RecordCategory category1;
|
||||
private RecordCategoryChild recordFolder1;
|
||||
private Record nonElectronicRecord , nonElectronicRecord2;
|
||||
private static final String AUDIT_NON_ELECTRONIC_RECORD = generateTestPrefix(NonElectronicRecordAuditLogTest.class) + "non electronic record";
|
||||
private static final String AUDIT_COMPLETE_REOPEN_NON_ELECTRONIC_RECORD = "Complete Reopen Non-Electronic Record";
|
||||
public static final String TITLE = "Title";
|
||||
public static final String DESCRIPTION = "Description";
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void nonElectronicRecordAuditLogSetup()
|
||||
{
|
||||
createRMSiteIfNotExists();
|
||||
rmAdmin = Optional.ofNullable(getDataUser().createRandomTestUser());
|
||||
rmRolesAndActionsAPI.assignRoleToUser(
|
||||
getDataUser().usingAdmin().getAdminUser().getUsername(),
|
||||
getDataUser().usingAdmin().getAdminUser().getPassword(),
|
||||
rmAdmin.get().getUsername(),
|
||||
"Administrator");
|
||||
|
||||
auditLog.clearAuditLog(rmAdmin.get().getUsername(),rmAdmin.get().getPassword());
|
||||
category1 = createRootCategory(TITLE, DESCRIPTION);
|
||||
recordFolder1 = createFolder(category1.getId(),TITLE);
|
||||
nonElectronicRecord = createNonElectronicRecord(recordFolder1.getId(),AUDIT_NON_ELECTRONIC_RECORD,rmAdmin.get());
|
||||
|
||||
}
|
||||
|
||||
@Test(description = "Audit log for newly filed non-electronic record")
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void newNonElectronicRecordAudit()
|
||||
{
|
||||
|
||||
List<AuditEntry> auditEntries= auditLog.getRMAuditLogAll(getAdminUser().getUsername(),getAdminUser().getPassword(),100);
|
||||
|
||||
// newly created record contains 3 events: "created object", "file to" and metadata update
|
||||
assertTrue("File To Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("File to")));
|
||||
assertTrue("Updated metadata Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Updated Metadata")));
|
||||
assertTrue("Created Object Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Created Object")));
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
dependsOnMethods = "newNonElectronicRecordAudit",
|
||||
description = "Viewing Non electronic record audit log is itself an auditable event"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void nonElectronicRecordAuditIsEvent()
|
||||
{
|
||||
List<AuditEntry> auditEntries= auditLog.getRMAuditLogAll(getAdminUser().getUsername(),getAdminUser().getPassword(),100);
|
||||
assertTrue("Audit View Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Audit View")));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
dependsOnMethods = "nonElectronicRecordAuditIsEvent",
|
||||
description = "Rename electronic record is an edit metadata event"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void renameNonElectronicRecord()
|
||||
{
|
||||
auditLog.clearAuditLog(rmAdmin.get().getUsername(),rmAdmin.get().getPassword());
|
||||
Record renameNonElectronicRecord = createRecordModel("edited " + nonElectronicRecord.getName(), "", "");
|
||||
|
||||
// rename record
|
||||
getRestAPIFactory().getRecordsAPI().updateRecord(renameNonElectronicRecord, nonElectronicRecord.getId());
|
||||
assertStatusCode(OK);
|
||||
|
||||
// we expect 1 new event: "metadata update"
|
||||
List<AuditEntry> auditEntries= auditLog.getRMAuditLogAll(getAdminUser().getUsername(),getAdminUser().getPassword(),100);
|
||||
assertTrue("Updated metadata Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Updated Metadata")));
|
||||
|
||||
}
|
||||
|
||||
@Test (dependsOnMethods = "newNonElectronicRecordAudit",description = "Complete and reopen electronic record")
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void completeAndReopenNonElectronicRecord()
|
||||
{
|
||||
nonElectronicRecord2 = createNonElectronicRecord(recordFolder1.getId(),AUDIT_COMPLETE_REOPEN_NON_ELECTRONIC_RECORD);
|
||||
|
||||
// complete record
|
||||
recordApi.completeRecord(rmAdmin.get().getUsername(),rmAdmin.get().getPassword(),
|
||||
nonElectronicRecord2.getName());
|
||||
|
||||
try
|
||||
{
|
||||
Utility.sleep(1000, 30000, () ->
|
||||
{
|
||||
org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
List<String> aspects = recordsAPI.getRecord(nonElectronicRecord2.getId()).getAspectNames();
|
||||
// a record must be completed
|
||||
assertTrue("Record is not completed.",aspects.contains(ASPECTS_COMPLETED_RECORD));
|
||||
});
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
fail("InterruptedException received while waiting for results.");
|
||||
}
|
||||
|
||||
List<AuditEntry> auditEntries= auditLog.getRMAuditLogAll(getAdminUser().getUsername(),getAdminUser().getPassword(),100);
|
||||
assertTrue("Complete Record Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Complete Record")));
|
||||
|
||||
// Reopen record
|
||||
recordApi.reOpenRecord(rmAdmin.get().getUsername(),rmAdmin.get().getPassword(),
|
||||
nonElectronicRecord2.getName());
|
||||
|
||||
try
|
||||
{
|
||||
Utility.sleep(1000, 30000, () ->
|
||||
{
|
||||
org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
List<String> aspects = recordsAPI.getRecord(nonElectronicRecord2.getId()).getAspectNames();
|
||||
// a record mustn't be completed
|
||||
assertFalse(aspects.contains(ASPECTS_COMPLETED_RECORD));
|
||||
});
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
fail("InterruptedException received while waiting for results.");
|
||||
}
|
||||
|
||||
auditEntries= auditLog.getRMAuditLogAll(getAdminUser().getUsername(),getAdminUser().getPassword(),100);
|
||||
assertTrue("Reopen Record Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Reopen Record")));
|
||||
|
||||
}
|
||||
@Test
|
||||
(
|
||||
dependsOnMethods = "completeAndReopenNonElectronicRecord",
|
||||
description = "File electronic record's audit log as record"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void fileNonElectronicRecordAuditLogAsRecord()
|
||||
{
|
||||
// audit log is stored in the same folder, refresh it so that it appears in the list
|
||||
HttpResponse auditRecordHttpResponse = auditLog.logsAuditLogAsRecord(rmAdmin.get().getUsername(),rmAdmin.get().getPassword(),
|
||||
getRecordNodeRef(nonElectronicRecord2.getId()),getFolderNodeRef(recordFolder1.getId()));
|
||||
JSONObject auditRecordProperties = getAuditPropertyValues(auditRecordHttpResponse);
|
||||
Record auditRecord = getRestAPIFactory().getRecordsAPI().getRecord(auditRecordProperties.get("record").toString()
|
||||
.replace("workspace://SpacesStore/",""));
|
||||
// check audit log
|
||||
AssertJUnit.assertTrue(auditRecordProperties.get("recordName").toString().endsWith(".html"));
|
||||
AssertJUnit.assertTrue(auditRecord.getAspectNames().stream().noneMatch(x -> x.startsWith(ASPECTS_COMPLETED_RECORD)));
|
||||
|
||||
}
|
||||
|
||||
private String getFolderNodeRef(String folderId) {
|
||||
return "workspace://SpacesStore/" + folderId;
|
||||
}
|
||||
|
||||
private String getRecordNodeRef(String recordId) {
|
||||
return "workspace/SpacesStore/" + recordId;
|
||||
}
|
||||
|
||||
private JSONObject getAuditPropertyValues(HttpResponse httpResponse) {
|
||||
HttpEntity entity = httpResponse.getEntity();
|
||||
String responseString = null;
|
||||
try {
|
||||
responseString = EntityUtils.toString(entity, "UTF-8");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
JSONObject result = new JSONObject(responseString);
|
||||
return result;
|
||||
}
|
||||
@AfterMethod
|
||||
private void closeAuditLog() {
|
||||
auditLog.clearAuditLog(rmAdmin.get().getUsername(),rmAdmin.get().getPassword());
|
||||
}
|
||||
|
||||
@AfterClass(alwaysRun = true)
|
||||
private void nonElectronicRecordAuditLogCleanup() {
|
||||
deleteRecord(nonElectronicRecord.getId());
|
||||
deleteRecord(nonElectronicRecord2.getId());
|
||||
deleteRecordFolder(recordFolder1.getId());
|
||||
deleteRecordCategory(category1.getId());
|
||||
dataUser.usingAdmin().deleteUser(new UserModel(rmAdmin.get().getUsername(), rmAdmin.get().getPassword()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.audit;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.audit.AuditEntry;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.v0.RMAuditAPI;
|
||||
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
|
||||
import org.alfresco.test.AlfrescoTest;
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.test.util.AssertionErrors.assertTrue;
|
||||
|
||||
public class RecordCategoryAuditLogTest extends BaseRMRestTest {
|
||||
@Autowired
|
||||
private RMRolesAndActionsAPI rmRolesAndActionsAPI;
|
||||
@Autowired
|
||||
private RMAuditAPI auditLog;
|
||||
|
||||
private final String TEST_PREFIX = generateTestPrefix(RecordCategoryAuditLogTest.class);
|
||||
private final String RM_ADMIN = TEST_PREFIX + "rm_admin";
|
||||
private static final String AUDIT_CATEGORY = generateTestPrefix(RecordCategoryAuditLogTest.class) + "category";
|
||||
private RecordCategory recordCategoryAudit;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void recordCategoryAuditLogSetup() {
|
||||
STEP("Create RM Site");
|
||||
createRMSiteIfNotExists();
|
||||
|
||||
STEP("Create RM Admin user");
|
||||
rmRolesAndActionsAPI.createUserAndAssignToRole(getAdminUser().getUsername(), getAdminUser().getPassword(), RM_ADMIN,
|
||||
getAdminUser().getPassword(),
|
||||
"Administrator");
|
||||
}
|
||||
|
||||
@Test
|
||||
@AlfrescoTest(jira = "RM-2768")
|
||||
public void recordCategoryAudit() throws Exception {
|
||||
STEP("Create root level category");
|
||||
recordCategoryAudit = createRootCategory(AUDIT_CATEGORY);
|
||||
List<AuditEntry> auditEntries = auditLog.getRMAuditLogAll(getAdminUser().getUsername(), getAdminUser().getPassword(), 100);
|
||||
// newly created record category contains 3 events: object creation, inherited permissions set to false and metadata update
|
||||
// the order in which object creation and metadata update are listed isn't always identical due to
|
||||
// both happening in the same transaction
|
||||
assertTrue("Created Object Event is not present.", auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Created Object")));
|
||||
assertTrue("Updated metadata Event is not present.", auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Updated Metadata")));
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
dependsOnMethods = "recordCategoryAudit",
|
||||
description = "Viewing audit log is itself an auditable event"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void recordCategoryAuditIsEvent() {
|
||||
List<AuditEntry> auditEntries = auditLog.getRMAuditLogAll(getAdminUser().getUsername(), getAdminUser().getPassword(), 100);
|
||||
assertTrue("Audit View Event is not present.", auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Audit View")));
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
dependsOnMethods = "recordCategoryAuditIsEvent",
|
||||
description = "Record category rename is an edit metadata event"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4303")
|
||||
public void renameRecordCategory() {
|
||||
String categoryName = "Category name " + getRandomAlphanumeric();
|
||||
RecordCategory rootRecordCategory = createRootCategory(categoryName);
|
||||
String newCategoryName = "Rename " + categoryName;
|
||||
RecordCategory recordCategoryUpdated = RecordCategory.builder().name(newCategoryName).build();
|
||||
RecordCategory renamedRecordCategory = getRestAPIFactory().getRecordCategoryAPI().updateRecordCategory(recordCategoryUpdated, rootRecordCategory.getId());
|
||||
|
||||
assertStatusCode(OK);
|
||||
// we expect 1 new event: "metadata update"
|
||||
List<AuditEntry> auditEntries = auditLog.getRMAuditLogAll(getAdminUser().getUsername(), getAdminUser().getPassword(), 100);
|
||||
assertTrue("Updated metadata Event is not present.", auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Updated Metadata")));
|
||||
}
|
||||
@AfterClass(alwaysRun = true)
|
||||
private void electronicRecordAuditLogCleanup() {
|
||||
deleteRecordCategory(recordCategoryAudit.getId());
|
||||
dataUser.deleteUser(new UserModel(RM_ADMIN,
|
||||
getAdminUser().getPassword()));
|
||||
auditLog.clearAuditLog(getAdminUser().getUsername(), getAdminUser().getPassword());
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.audit;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.audit.AuditEntry;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolder;
|
||||
import org.alfresco.rest.v0.RMAuditAPI;
|
||||
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
|
||||
import org.alfresco.rest.v0.RecordFoldersAPI;
|
||||
import org.alfresco.test.AlfrescoTest;
|
||||
import org.alfresco.utility.Utility;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAspects.ASPECTS_COMPLETED_RECORD;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordFolderModel;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.test.util.AssertionErrors.assertTrue;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
public class RecordFolderAuditLogTest extends BaseRMRestTest {
|
||||
|
||||
private Optional<UserModel> rmAdmin;
|
||||
@Autowired
|
||||
private RMRolesAndActionsAPI rmRolesAndActionsAPI;
|
||||
@Autowired
|
||||
private RMAuditAPI auditLog;
|
||||
|
||||
@Autowired
|
||||
private RecordFoldersAPI recordFoldersAPI;
|
||||
private RecordCategory category1;
|
||||
private RecordCategoryChild recordFolder1;
|
||||
public static final String TITLE = "Title";
|
||||
public static final String DESCRIPTION = "Description";
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void recordFolderAuditLogSetup() {
|
||||
createRMSiteIfNotExists();
|
||||
rmAdmin = Optional.ofNullable(getDataUser().createRandomTestUser());
|
||||
rmRolesAndActionsAPI.assignRoleToUser(
|
||||
getDataUser().usingAdmin().getAdminUser().getUsername(),
|
||||
getDataUser().usingAdmin().getAdminUser().getPassword(),
|
||||
rmAdmin.get().getUsername(),
|
||||
"Administrator");
|
||||
}
|
||||
|
||||
@Test(description = "Audit log for empty record folder")
|
||||
@AlfrescoTest(jira = "RM-4303")
|
||||
public void recordFolderAudit() {
|
||||
category1 = createRootCategory(TITLE, DESCRIPTION);
|
||||
recordFolder1 = createFolder(category1.getId(), TITLE);
|
||||
List<AuditEntry> auditEntries = auditLog.getRMAuditLogAll(getAdminUser().getUsername(), getAdminUser().getPassword(), 100);
|
||||
assertTrue("Created Object Event is not present.", auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Created Object")));
|
||||
assertTrue("Updated metadata Event is not present.", auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Updated Metadata")));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
dependsOnMethods = "recordFolderAudit",
|
||||
description = "Viewing record folder audit log is itself an auditable event"
|
||||
)
|
||||
@AlfrescoTest(jira = "RM-4303")
|
||||
public void recordFolderAuditIsEvent() {
|
||||
List<AuditEntry> auditEntries = auditLog.getRMAuditLogAll(getAdminUser().getUsername(), getAdminUser().getPassword(), 100);
|
||||
assertTrue("Audit View Event is not present.", auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Audit View")));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
dependsOnMethods = "recordFolderAuditIsEvent",
|
||||
description = "Record folder rename is an edit metadata event"
|
||||
)
|
||||
@AlfrescoTest(jira = "RM-4303")
|
||||
public void renameRecordFolder() {
|
||||
auditLog.clearAuditLog(rmAdmin.get().getUsername(), rmAdmin.get().getPassword());
|
||||
RecordFolder renameRecordFolder = createRecordFolderModel(category1.getId(), "edited");
|
||||
getRestAPIFactory().getRecordFolderAPI().updateRecordFolder(renameRecordFolder, recordFolder1.getId());
|
||||
assertStatusCode(OK);
|
||||
// we expect 1 new event: "metadata update"
|
||||
List<AuditEntry> auditEntries = auditLog.getRMAuditLogAll(getAdminUser().getUsername(), getAdminUser().getPassword(), 100);
|
||||
// assertTrue("Move To Event is not present.",auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Move to")));
|
||||
assertTrue("Updated metadata Event is not present.", auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Updated Metadata")));
|
||||
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "recordFolderAudit",
|
||||
description = "Close and reopen folder")
|
||||
@AlfrescoTest(jira = "RM-4303")
|
||||
public void closeReopenFolder() {
|
||||
//close folder
|
||||
recordFoldersAPI.closeRecordFolder(rmAdmin.get().getUsername(), rmAdmin.get().getPassword(),
|
||||
recordFolder1.getName());
|
||||
try
|
||||
{
|
||||
Utility.sleep(1000, 30000, () ->
|
||||
{
|
||||
List<AuditEntry> auditEntries = auditLog.getRMAuditLogAll(getAdminUser().getUsername(), getAdminUser().getPassword(), 100);
|
||||
assertTrue("Folder Close Record Event is not present.", auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Close Record Folder")));
|
||||
|
||||
});
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
fail("InterruptedException received while waiting for results.");
|
||||
}
|
||||
|
||||
//reopen folder
|
||||
recordFoldersAPI.reOpenRecordFolder(rmAdmin.get().getUsername(), rmAdmin.get().getPassword(),
|
||||
recordFolder1.getName());
|
||||
try
|
||||
{
|
||||
Utility.sleep(1000, 30000, () ->
|
||||
{
|
||||
|
||||
List<AuditEntry> auditEntries = auditLog.getRMAuditLogAll(getAdminUser().getUsername(), getAdminUser().getPassword(), 100);
|
||||
assertTrue("Reopen Record Event is not present.", auditEntries.stream().anyMatch(x -> x.getEvent().startsWith("Open Record Folder")));
|
||||
|
||||
});
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
fail("InterruptedException received while waiting for results.");
|
||||
}
|
||||
}
|
||||
@AfterMethod
|
||||
private void closeAuditLog()
|
||||
{
|
||||
auditLog.clearAuditLog(rmAdmin.get().getUsername(),rmAdmin.get().getPassword());
|
||||
}
|
||||
|
||||
@AfterClass (alwaysRun = true)
|
||||
public void recordFolderAuditLogCleanup()
|
||||
{
|
||||
deleteRecordFolder(recordFolder1.getId());
|
||||
deleteRecordCategory(category1.getId());
|
||||
dataUser.usingAdmin().deleteUser(new UserModel(rmAdmin.get().getUsername(), rmAdmin.get().getPassword()));
|
||||
}
|
||||
|
||||
}
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-parent</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
@@ -30,8 +30,10 @@ package org.alfresco.module.org_alfresco_module_rm.job;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.action.RMDispositionActionExecuterAbstractBase.PARAM_NO_ERROR_CHECK;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -47,7 +49,6 @@ import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
|
||||
/**
|
||||
@@ -64,7 +65,6 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
|
||||
/** batching properties */
|
||||
private int batchSize;
|
||||
public static final int DEFAULT_BATCH_SIZE = 500;
|
||||
private static final String MSG_NODE_FROZEN = "rm.action.node.frozen.error-message";
|
||||
|
||||
/** list of disposition actions to automatically execute */
|
||||
private List<String> dispositionActions;
|
||||
@@ -194,6 +194,7 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
|
||||
|
||||
boolean hasMore = true;
|
||||
int skipCount = 0;
|
||||
List<NodeRef> resultNodes = new ArrayList<>();
|
||||
|
||||
if (batchSize < 1)
|
||||
{
|
||||
@@ -214,7 +215,14 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
|
||||
|
||||
// execute search
|
||||
ResultSet results = searchService.query(params);
|
||||
List<NodeRef> resultNodes = results.getNodeRefs();
|
||||
if(results != null)
|
||||
{
|
||||
// filtering out the hold/freezed cases from the result set
|
||||
resultNodes =
|
||||
results.getNodeRefs().stream().filter(node -> nodeService.getPrimaryParent(node) == null ?
|
||||
!freezeService.isFrozenOrHasFrozenChildren(node) :
|
||||
!freezeService.isFrozenOrHasFrozenChildren(nodeService.getPrimaryParent(node).getParentRef())).collect(Collectors.toList());
|
||||
}
|
||||
hasMore = results.hasMore();
|
||||
skipCount += resultNodes.size(); // increase by page size
|
||||
results.close();
|
||||
@@ -265,12 +273,6 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
|
||||
}
|
||||
Map<String, Serializable> props = Map.of(PARAM_NO_ERROR_CHECK, false);
|
||||
|
||||
if (freezeService.isFrozenOrHasFrozenChildren(parent.getParentRef()))
|
||||
{
|
||||
log.debug(I18NUtil.getMessage(MSG_NODE_FROZEN, dispAction));
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// execute disposition action
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
# Version label
|
||||
version.major=7
|
||||
version.minor=3
|
||||
version.minor=4
|
||||
version.revision=0
|
||||
version.label=
|
||||
|
||||
|
@@ -170,7 +170,7 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
|
||||
executer.executeImpl();
|
||||
|
||||
// then
|
||||
|
||||
verify(mockedNodeService, times(2)).getPrimaryParent(any(NodeRef.class));
|
||||
// ensure the query is executed and closed
|
||||
verifyQueryTimes(2);
|
||||
|
||||
@@ -206,7 +206,7 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
|
||||
executer.executeImpl();
|
||||
|
||||
// then
|
||||
|
||||
verify(mockedNodeService, times(1)).getPrimaryParent(any(NodeRef.class));
|
||||
// ensure the query is executed and closed
|
||||
verifyQueryTimes(1);
|
||||
|
||||
@@ -262,11 +262,11 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
|
||||
// ensure each node is process correctly
|
||||
// node1
|
||||
verify(mockedNodeService, times(1)).getProperty(node1, RecordsManagementModel.PROP_DISPOSITION_ACTION);
|
||||
verify(mockedNodeService, times(1)).getPrimaryParent(node1);
|
||||
verify(mockedNodeService, times(3)).getPrimaryParent(node1);
|
||||
verify(mockedRecordsManagementActionService, times(1)).executeRecordsManagementAction(eq(parent), eq(CUTOFF), anyMap());
|
||||
// node2
|
||||
verify(mockedNodeService, times(1)).getProperty(node2, RecordsManagementModel.PROP_DISPOSITION_ACTION);
|
||||
verify(mockedNodeService, times(1)).getPrimaryParent(node2);
|
||||
verify(mockedNodeService, times(3)).getPrimaryParent(node2);
|
||||
verify(mockedRecordsManagementActionService, times(1)).executeRecordsManagementAction(eq(parent), eq(RETAIN), anyMap());
|
||||
|
||||
// ensure no more interactions
|
||||
@@ -329,7 +329,7 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
|
||||
// call the service
|
||||
executer.executeImpl();
|
||||
|
||||
// check the loop iterated trough all the elements
|
||||
// check the loop iterated through all the elements
|
||||
verify(mockedNodeService).exists(node1);
|
||||
verify(mockedNodeService).exists(node2);
|
||||
verify(mockedNodeService).exists(node3);
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-amps</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
@@ -134,7 +134,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.woodstox</groupId>
|
||||
<artifactId>woodstox-core</artifactId>
|
||||
<version>6.3.1</version>
|
||||
<version>6.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- the cxf libs were updated, see dependencyManagement section -->
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@@ -9,6 +9,6 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
</project>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -1,9 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
set -x
|
||||
|
||||
export DOCKER_COMPOSE_PATH=$1
|
||||
export CLEAN_UP="$2"
|
||||
export DOCKER_COMPOSES=""
|
||||
export CLEAN_UP=""
|
||||
|
||||
if [ -z "$DOCKER_COMPOSE_PATH" ]
|
||||
for var in "$@"
|
||||
do
|
||||
if [ "$var" == "no-clean-up" ]
|
||||
then
|
||||
export CLEAN_UP="$var"
|
||||
else
|
||||
export DOCKER_COMPOSES+="--file $var "
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$DOCKER_COMPOSES" ]
|
||||
then
|
||||
echo "Please provide path to docker-compose.yml: \"${0##*/} /path/to/docker-compose.yml\""
|
||||
exit 1
|
||||
@@ -15,8 +27,8 @@ fi
|
||||
# The second parameter can be used to avoid doing a clean up if we are doing a restart test.
|
||||
if [ "$CLEAN_UP" != "no-clean-up" ]
|
||||
then
|
||||
docker-compose --file "${DOCKER_COMPOSE_PATH}" kill
|
||||
docker-compose --file "${DOCKER_COMPOSE_PATH}" rm -f
|
||||
docker-compose ${DOCKER_COMPOSES} --project-directory $(dirname "${DOCKER_COMPOSE_PATH}") kill
|
||||
docker-compose ${DOCKER_COMPOSES} --project-directory $(dirname "${DOCKER_COMPOSE_PATH}") rm -f
|
||||
|
||||
export GENERATED_IMAGES=$(docker images | grep '^environment_' | awk '{ print $3 }')
|
||||
if [ -n "$GENERATED_IMAGES" ]
|
||||
@@ -31,7 +43,7 @@ export TRANSFORMERS_TAG=$(mvn help:evaluate -Dexpression=dependency.alfresco-tra
|
||||
export TRANSFORM_ROUTER_TAG=$(mvn help:evaluate -Dexpression=dependency.alfresco-transform-service.version -q -DforceStdout)
|
||||
|
||||
# .env files are picked up from project directory correctly on docker-compose 1.23.0+
|
||||
docker-compose --file "${DOCKER_COMPOSE_PATH}" --project-directory $(dirname "${DOCKER_COMPOSE_PATH}") up -d
|
||||
docker-compose ${DOCKER_COMPOSES} --project-directory $(dirname "${DOCKER_COMPOSE_PATH}") up -d
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<organization>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
@@ -14,6 +14,7 @@ import org.alfresco.utility.testrail.annotation.TestRail;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Ignore;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class AddFavoritesTests extends RestTest
|
||||
@@ -354,6 +355,7 @@ public class AddFavoritesTests extends RestTest
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
|
||||
description = "Verify add file favorite with tag id returns status code 404")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION })
|
||||
@Ignore
|
||||
public void addFileFavoriteUsingTagId() throws Exception
|
||||
{
|
||||
FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
|
||||
|
@@ -951,6 +951,28 @@ public class CreateRulesTests extends RestTest
|
||||
restClient.assertLastError().containsSummary("Category in condition is invalid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check we get 400 error when condition comparator is invalid
|
||||
*/
|
||||
@Test(groups = {TestGroup.REST_API, TestGroup.RULES})
|
||||
public void createRuleWithConditions_invalidComparator()
|
||||
{
|
||||
STEP("Try to create a rule with invalid comparator in conditions.");
|
||||
final String comparator = "greaterthan";
|
||||
RestCompositeConditionDefinitionModel conditions = rulesUtils.createCompositeCondition(List.of(
|
||||
rulesUtils.createCompositeCondition(!INVERTED, List.of(
|
||||
rulesUtils.createSimpleCondition("size", comparator, "500")
|
||||
))
|
||||
));
|
||||
RestRuleModel ruleModel = rulesUtils.createRuleModelWithDefaultValues();
|
||||
ruleModel.setConditions(conditions);
|
||||
|
||||
restClient.authenticateUser(user).withPrivateAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
|
||||
restClient.assertStatusCodeIs(BAD_REQUEST);
|
||||
restClient.assertLastError().containsSummary("Comparator value for condition is invalid: " + comparator);
|
||||
}
|
||||
|
||||
private String getAddPermissionsBody(String username, String role)
|
||||
{
|
||||
JsonObject userPermission = Json.createObjectBuilder().add("permissions",
|
||||
|
@@ -30,7 +30,10 @@ import static org.alfresco.rest.rules.RulesTestsUtils.LOCKABLE_ASPECT;
|
||||
import static org.alfresco.rest.rules.RulesTestsUtils.RULE_NAME_DEFAULT;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.dataprep.CMISUtil;
|
||||
import org.alfresco.rest.RestTest;
|
||||
@@ -294,5 +297,28 @@ public class ExecuteRulesTests extends RestTest
|
||||
rulesUtils.assertThat(fileNode).containsAspects(AUDIO_ASPECT);
|
||||
}
|
||||
|
||||
//TODO: add test(s) that would cover handling executing broken rule and/or broken rule execution (ACS-3699)
|
||||
/**
|
||||
* Try to execute rule with broken action and receive 404 error.
|
||||
*/
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.ACTIONS })
|
||||
public void executeRules_copyActionWithDeletedDestinationFolder()
|
||||
{
|
||||
FolderModel owningFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
FileModel owningFolderFile = dataContent.usingUser(user).usingResource(owningFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
|
||||
FolderModel destinationFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
|
||||
STEP("Create copy action and rule");
|
||||
final Map<String, Serializable> copyParams =
|
||||
Map.of("destination-folder", destinationFolder.getNodeRef(), "deep-copy", true);
|
||||
final RestActionBodyExecTemplateModel copyAction = rulesUtils.createCustomActionModel("copy", copyParams);
|
||||
final RestRuleModel ruleModel = rulesUtils.createRuleModelWithDefaultValues();
|
||||
ruleModel.setActions(Arrays.asList(copyAction));
|
||||
|
||||
restClient.authenticateUser(user).withPrivateAPI().usingNode(owningFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
|
||||
STEP("Delete destination folder and execute rule");
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(destinationFolder).deleteNode(destinationFolder.getNodeRef());
|
||||
restClient.authenticateUser(user).withPrivateAPI().usingNode(owningFolder).executeRules(rulesUtils.createRuleExecutionRequest());
|
||||
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
24
pom.xml
24
pom.xml
@@ -2,7 +2,7 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Alfresco Community Repo Parent</name>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
<properties>
|
||||
<acs.version.major>7</acs.version.major>
|
||||
<acs.version.minor>3</acs.version.minor>
|
||||
<acs.version.minor>4</acs.version.minor>
|
||||
<acs.version.revision>0</acs.version.revision>
|
||||
<acs.version.label />
|
||||
<amp.min.version>${acs.version.major}.0.0</amp.min.version>
|
||||
@@ -53,17 +53,17 @@
|
||||
<dependency.activiti.version>5.23.0</dependency.activiti.version>
|
||||
<dependency.alfresco-transform-service.version>2.0.0</dependency.alfresco-transform-service.version>
|
||||
<dependency.alfresco-transform-core.version>3.0.0</dependency.alfresco-transform-core.version>
|
||||
<dependency.alfresco-greenmail.version>6.4</dependency.alfresco-greenmail.version>
|
||||
<dependency.alfresco-greenmail.version>6.5</dependency.alfresco-greenmail.version>
|
||||
<dependency.acs-event-model.version>0.0.16</dependency.acs-event-model.version>
|
||||
|
||||
<dependency.spring.version>5.3.23</dependency.spring.version>
|
||||
<dependency.antlr.version>3.5.3</dependency.antlr.version>
|
||||
<dependency.jackson.version>2.14.0-rc1</dependency.jackson.version>
|
||||
<dependency.cxf.version>3.5.3</dependency.cxf.version>
|
||||
<dependency.cxf.version>3.5.4</dependency.cxf.version>
|
||||
<dependency.opencmis.version>1.0.0</dependency.opencmis.version>
|
||||
<dependency.webscripts.version>8.32</dependency.webscripts.version>
|
||||
<dependency.bouncycastle.version>1.70</dependency.bouncycastle.version>
|
||||
<dependency.mockito-core.version>4.6.1</dependency.mockito-core.version>
|
||||
<dependency.mockito-core.version>4.8.1</dependency.mockito-core.version>
|
||||
<dependency.assertj.version>3.23.1</dependency.assertj.version>
|
||||
<dependency.org-json.version>20220320</dependency.org-json.version>
|
||||
<dependency.commons-dbcp.version>2.9.0</dependency.commons-dbcp.version>
|
||||
@@ -77,7 +77,7 @@
|
||||
<dependency.gytheio.version>0.17</dependency.gytheio.version>
|
||||
<dependency.groovy.version>3.0.12</dependency.groovy.version>
|
||||
<dependency.tika.version>2.4.1</dependency.tika.version>
|
||||
<dependency.spring-security.version>5.7.3</dependency.spring-security.version>
|
||||
<dependency.spring-security.version>5.7.5</dependency.spring-security.version>
|
||||
<dependency.truezip.version>7.7.10</dependency.truezip.version>
|
||||
<dependency.poi.version>5.2.2</dependency.poi.version>
|
||||
<dependency.poi-ooxml-lite.version>5.2.3</dependency.poi-ooxml-lite.version>
|
||||
@@ -88,11 +88,11 @@
|
||||
<dependency.netty.qpid.version>4.1.72.Final</dependency.netty.qpid.version> <!-- must be in sync with camels transitive dependencies: native-unix-common/native-epoll/native-kqueue -->
|
||||
<dependency.netty-tcnative.version>2.0.53.Final</dependency.netty-tcnative.version> <!-- must be in sync with camels transitive dependencies -->
|
||||
<dependency.activemq.version>5.17.1</dependency.activemq.version>
|
||||
<dependency.apache-compress.version>1.21</dependency.apache-compress.version>
|
||||
<dependency.apache-compress.version>1.22</dependency.apache-compress.version>
|
||||
<dependency.apache.taglibs.version>1.2.5</dependency.apache.taglibs.version>
|
||||
<dependency.awaitility.version>4.2.0</dependency.awaitility.version>
|
||||
<dependency.swagger-ui.version>3.38.0</dependency.swagger-ui.version>
|
||||
<dependency.swagger-parser.version>1.0.61</dependency.swagger-parser.version>
|
||||
<dependency.swagger-parser.version>1.0.63</dependency.swagger-parser.version>
|
||||
<dependency.maven-filtering.version>3.1.1</dependency.maven-filtering.version>
|
||||
<dependency.maven-artifact.version>3.8.6</dependency.maven-artifact.version>
|
||||
<dependency.jdom2.version>2.0.6.1</dependency.jdom2.version>
|
||||
@@ -109,7 +109,7 @@
|
||||
<dependency.jakarta-json-path.version>2.7.0</dependency.jakarta-json-path.version>
|
||||
<dependency.jakarta-rpc-api.version>1.1.4</dependency.jakarta-rpc-api.version>
|
||||
|
||||
<alfresco.googledrive.version>3.3.0</alfresco.googledrive.version>
|
||||
<alfresco.googledrive.version>3.3.1-A2</alfresco.googledrive.version>
|
||||
<alfresco.aos-module.version>1.5.0</alfresco.aos-module.version>
|
||||
<alfresco.api-explorer.version>7.3.0</alfresco.api-explorer.version> <!-- Also in alfresco-enterprise-share -->
|
||||
|
||||
@@ -149,7 +149,7 @@
|
||||
<connection>scm:git:https://github.com/Alfresco/alfresco-community-repo.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/Alfresco/alfresco-community-repo.git</developerConnection>
|
||||
<url>https://github.com/Alfresco/alfresco-community-repo</url>
|
||||
<tag>17.183</tag>
|
||||
<tag>20.13</tag>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
@@ -651,7 +651,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.junrar</groupId>
|
||||
<artifactId>junrar</artifactId>
|
||||
<version>7.5.3</version>
|
||||
<version>7.5.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
@@ -736,7 +736,7 @@
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>2.11.1</version>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- provided dependencies -->
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@@ -295,7 +295,18 @@ public class AuditImpl implements Audit
|
||||
}
|
||||
else
|
||||
{
|
||||
totalItems = hasMoreItems ? getAuditEntriesCountByApp(auditApplication) : totalRetrievedItems;
|
||||
if (hasMoreItems) {
|
||||
if (q != null) {
|
||||
// filtering via "where" clause
|
||||
AuditEntryQueryWalker propertyWalker = new AuditEntryQueryWalker();
|
||||
QueryHelper.walk(q, propertyWalker);
|
||||
totalItems = getAuditEntriesCountByAppAndProperties(auditApplication, propertyWalker);
|
||||
} else {
|
||||
totalItems = getAuditEntriesCountByApp(auditApplication);
|
||||
}
|
||||
} else {
|
||||
totalItems = totalRetrievedItems;
|
||||
}
|
||||
}
|
||||
|
||||
entriesAudit = (skipCount >= totalRetrievedItems)
|
||||
@@ -895,4 +906,19 @@ public class AuditImpl implements Audit
|
||||
final String applicationName = auditApplication.getKey().substring(1);
|
||||
return auditService.getAuditEntriesCountByApp(applicationName);
|
||||
}
|
||||
|
||||
public int getAuditEntriesCountByAppAndProperties(AuditService.AuditApplication auditApplication, AuditEntryQueryWalker propertyWalker)
|
||||
{
|
||||
final String applicationName = auditApplication.getKey().substring(1);
|
||||
|
||||
AuditQueryParameters parameters = new AuditQueryParameters();
|
||||
parameters.setApplicationName(applicationName);
|
||||
parameters.setFromTime(propertyWalker.getFromTime());
|
||||
parameters.setToTime(propertyWalker.getToTime());
|
||||
parameters.setFromId(propertyWalker.getFromId());
|
||||
parameters.setToId(propertyWalker.getToId());
|
||||
parameters.setUser(propertyWalker.getCreatedByUser());
|
||||
|
||||
return auditService.getAuditEntriesCountByAppAndProperties(applicationName, parameters);
|
||||
}
|
||||
}
|
||||
|
@@ -64,6 +64,7 @@ public class RestRuleSimpleConditionModelMapper implements RestModelMapper<Simpl
|
||||
static final String FIELD_NOT_NULL = "Field in condition must not be blank";
|
||||
static final String PARAMETER_NOT_NULL = "Parameter in condition must not be blank";
|
||||
static final String COMPARATOR_NOT_NULL = "Comparator in condition must not be blank";
|
||||
static final String INVALID_COMPARATOR_VALUE = "Comparator value for condition is invalid: %s";
|
||||
private final NamespaceService namespaceService;
|
||||
private final Nodes nodes;
|
||||
|
||||
@@ -157,13 +158,23 @@ public class RestRuleSimpleConditionModelMapper implements RestModelMapper<Simpl
|
||||
parameterValues.put(ComparePropertyValueEvaluator.PARAM_PROPERTY, QName.createQName(field, namespaceService));
|
||||
}
|
||||
checkStringNotBlank(restModel.getComparator(), COMPARATOR_NOT_NULL);
|
||||
parameterValues.put(ComparePropertyValueEvaluator.PARAM_OPERATION, restModel.getComparator().toUpperCase());
|
||||
parameterValues.put(ComparePropertyValueEvaluator.PARAM_OPERATION, getComparatorValue(restModel.getComparator()));
|
||||
parameterValues.put(ComparePropertyValueEvaluator.PARAM_VALUE, parameter);
|
||||
break;
|
||||
}
|
||||
return new ActionConditionImpl(UUID.randomUUID().toString(), conditionDefinitionId, parameterValues);
|
||||
}
|
||||
|
||||
private String getComparatorValue(String comparator)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ComparePropertyValueOperation.valueOf(comparator.toUpperCase()).toString();
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new InvalidArgumentException(String.format(INVALID_COMPARATOR_VALUE, comparator));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStringNotBlank(final String string, final String message) {
|
||||
if (Strings.isBlank(string))
|
||||
{
|
||||
|
@@ -28,6 +28,7 @@ package org.alfresco.rest.api.impl.mapper.rules;
|
||||
|
||||
import static org.alfresco.rest.api.impl.mapper.rules.RestRuleSimpleConditionModelMapper.COMPARATOR_NOT_NULL;
|
||||
import static org.alfresco.rest.api.impl.mapper.rules.RestRuleSimpleConditionModelMapper.FIELD_NOT_NULL;
|
||||
import static org.alfresco.rest.api.impl.mapper.rules.RestRuleSimpleConditionModelMapper.INVALID_COMPARATOR_VALUE;
|
||||
import static org.alfresco.rest.api.impl.mapper.rules.RestRuleSimpleConditionModelMapper.PARAMETER_NOT_NULL;
|
||||
import static org.alfresco.rest.api.impl.mapper.rules.RestRuleSimpleConditionModelMapper.PARAM_CATEGORY;
|
||||
import static org.alfresco.rest.api.impl.mapper.rules.RestRuleSimpleConditionModelMapper.PARAM_MIMETYPE;
|
||||
@@ -366,6 +367,22 @@ public class RestRuleSimpleConditionModelMapperTest
|
||||
.hasMessageContaining(COMPARATOR_NOT_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToServiceModel_invalidComparator()
|
||||
{
|
||||
final String comparator = "greaterthan";
|
||||
final SimpleCondition simpleConditionNullComparator = SimpleCondition.builder()
|
||||
.field("size")
|
||||
.comparator(comparator)
|
||||
.parameter("65000")
|
||||
.create();
|
||||
|
||||
// when
|
||||
assertThatThrownBy(() -> objectUnderTest.toServiceModel(simpleConditionNullComparator))
|
||||
.isInstanceOf(InvalidArgumentException.class)
|
||||
.hasMessageContaining(String.format(INVALID_COMPARATOR_VALUE, comparator));
|
||||
}
|
||||
|
||||
private static ActionCondition createActionCondition(final String actionDefinitionName)
|
||||
{
|
||||
return new ActionConditionImpl("fake-id", actionDefinitionName, createParameterValues());
|
||||
|
@@ -34,6 +34,9 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.net.URL;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -386,6 +389,7 @@ public class AuditAppTest extends AbstractSingleNetworkSiteTest
|
||||
AuditApp auditApp = auditAppsProxy.getAuditApp("alfresco-access");
|
||||
|
||||
testGetAuditEntries(auditAppsProxy, auditApp);
|
||||
testGetAuditEntriesWhereCreatedAt(auditAppsProxy, auditApp);
|
||||
testAuditEntriesSorting(auditAppsProxy, auditApp);
|
||||
testAuditEntriesWhereDate(auditAppsProxy, auditApp);
|
||||
testAuditEntriesWhereId(auditAppsProxy, auditApp);
|
||||
@@ -396,6 +400,30 @@ public class AuditAppTest extends AbstractSingleNetworkSiteTest
|
||||
testDeleteAuditEntries(auditAppsProxy, auditApp);
|
||||
}
|
||||
|
||||
private void testGetAuditEntriesWhereCreatedAt(AuditApps auditAppsProxy, AuditApp auditApp) throws Exception
|
||||
{
|
||||
// get "totalItems" for a specific time interval
|
||||
Map<String, String> params = new HashMap<>();
|
||||
|
||||
final ZonedDateTime beginDate = ZonedDateTime.now().minusHours(1).truncatedTo(ChronoUnit.MINUTES);
|
||||
final ZonedDateTime endDate = ZonedDateTime.now().truncatedTo(ChronoUnit.MINUTES);
|
||||
params.put("where","(createdAt BETWEEN ('"+beginDate.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)+"' , '"+endDate.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)+"'))");
|
||||
|
||||
ListResponse<AuditEntry> auditEntries = auditAppsProxy.getAuditAppEntries(auditApp.getId(), params,
|
||||
HttpServletResponse.SC_OK);
|
||||
int totalItemsWithDefaultMaxSize = auditEntries.getPaging().getTotalItems();
|
||||
assertTrue( totalItemsWithDefaultMaxSize > 1 );
|
||||
|
||||
// get "totalItems" for a specific time internal (with maxSize=1)
|
||||
params.put("maxSize","1");
|
||||
auditEntries = auditAppsProxy.getAuditAppEntries(auditApp.getId(), params,
|
||||
HttpServletResponse.SC_OK);
|
||||
int totalItemsWithMaxSize1 = auditEntries.getPaging().getTotalItems();
|
||||
|
||||
// number of "totalItems" must be the same, regardless maxSize
|
||||
assertEquals(totalItemsWithMaxSize1, totalItemsWithDefaultMaxSize);
|
||||
}
|
||||
|
||||
private void testGetAuditEntries(AuditApps auditAppsProxy, AuditApp auditApp) throws Exception
|
||||
{
|
||||
// Positive tests
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>17.183</version>
|
||||
<version>20.13</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -126,7 +126,7 @@
|
||||
<dependency>
|
||||
<groupId>com.ibm.icu</groupId>
|
||||
<artifactId>icu4j</artifactId>
|
||||
<version>71.1</version>
|
||||
<version>72.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
@@ -374,7 +374,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.woodstox</groupId>
|
||||
<artifactId>woodstox-core</artifactId>
|
||||
<version>6.3.1</version>
|
||||
<version>6.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- GData -->
|
||||
|
@@ -272,4 +272,16 @@ public interface AuditComponent
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue an audit query to retrieve count of records for a given application and properties
|
||||
*
|
||||
* @param applicationName the name of the application
|
||||
* @param parameters audit parameters provided by the <code>where</code> clause on the ReST API
|
||||
* @return a map containing min/max and the associated value
|
||||
*/
|
||||
default int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@@ -955,4 +955,11 @@ public class AuditComponentImpl implements AuditComponent
|
||||
|
||||
return auditDAO.getAuditEntriesCountByApp(applicationId);
|
||||
}
|
||||
|
||||
@Override public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
|
||||
{
|
||||
org.alfresco.repo.domain.audit.AuditQueryParameters dbParameters = new org.alfresco.repo.domain.audit.AuditQueryParameters();
|
||||
|
||||
return auditDAO.getAuditEntriesCountByAppAndProperties(applicationName, parameters);
|
||||
}
|
||||
}
|
||||
|
@@ -186,4 +186,12 @@ public class AuditServiceImpl implements AuditService
|
||||
{
|
||||
return auditComponent.getAuditEntriesCountByApp(applicationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
|
||||
{
|
||||
return auditComponent.getAuditEntriesCountByAppAndProperties(applicationName, parameters);
|
||||
}
|
||||
}
|
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* 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%
|
||||
*/
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* 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.repo.domain.audit;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -452,37 +452,86 @@ public abstract class AbstractAuditDAOImpl implements AuditDAO
|
||||
org.alfresco.service.cmr.audit.AuditQueryParameters parameters,
|
||||
int maxResults)
|
||||
{
|
||||
String searchKey = null;
|
||||
Serializable searchValue = null;
|
||||
if (parameters.getSearchKeyValues().size() > 0)
|
||||
{
|
||||
// Only handle one pair for now
|
||||
Pair<String, Serializable> searchKeyValue = parameters.getSearchKeyValues().get(0);
|
||||
searchKey = searchKeyValue.getFirst();
|
||||
searchValue = searchKeyValue.getSecond();
|
||||
}
|
||||
|
||||
AuditQueryRowHandler rowHandler = new AuditQueryRowHandler(callback);
|
||||
findAuditEntries(
|
||||
rowHandler,
|
||||
parameters.isForward(),
|
||||
parameters.getApplicationName(),
|
||||
parameters.getUser(),
|
||||
parameters.getFromId(),
|
||||
parameters.getToId(),
|
||||
parameters.getFromTime(),
|
||||
parameters.getToTime(),
|
||||
maxResults,
|
||||
searchKey,
|
||||
searchValue);
|
||||
parameters);
|
||||
}
|
||||
|
||||
protected abstract void findAuditEntries(
|
||||
AuditQueryRowHandler rowHandler,
|
||||
boolean forward,
|
||||
String applicationName, String user,
|
||||
Long fromId, Long toId,
|
||||
Long fromTime, Long toTime,
|
||||
int maxResults,
|
||||
String searchKey, Serializable searchValue);
|
||||
org.alfresco.service.cmr.audit.AuditQueryParameters restParameters);
|
||||
|
||||
protected AuditQueryParameters convertFromRestAuditQueryParameters(org.alfresco.service.cmr.audit.AuditQueryParameters restParameters)
|
||||
{
|
||||
AuditQueryParameters dbParameters = new AuditQueryParameters();
|
||||
|
||||
String appName = restParameters.getApplicationName();
|
||||
if (appName != null)
|
||||
{
|
||||
// Look up the application's ID (this is unique)
|
||||
Pair<Long, Serializable> appNamePair = propertyValueDAO.getPropertyValue(appName);
|
||||
if (appNamePair == null)
|
||||
{
|
||||
// No such value
|
||||
return null;
|
||||
}
|
||||
dbParameters.setAuditAppNameId(appNamePair.getFirst());
|
||||
}
|
||||
|
||||
String user = restParameters.getUser();
|
||||
if (user != null)
|
||||
{
|
||||
// Look up the application's ID (this is unique)
|
||||
Pair<Long, Serializable> userPair = propertyValueDAO.getPropertyValue(user);
|
||||
if (userPair == null)
|
||||
{
|
||||
// No such value
|
||||
return null;
|
||||
}
|
||||
dbParameters.setAuditUserId(userPair.getFirst());
|
||||
}
|
||||
|
||||
dbParameters.setAuditFromId(restParameters.getFromId());
|
||||
dbParameters.setAuditToId(restParameters.getToId());
|
||||
dbParameters.setAuditFromTime(restParameters.getFromTime());
|
||||
dbParameters.setAuditToTime(restParameters.getToTime());
|
||||
|
||||
String searchKey = null;
|
||||
Serializable searchValue = null;
|
||||
if (restParameters.getSearchKeyValues().size() > 0)
|
||||
{
|
||||
// Only handle one pair for now
|
||||
Pair<String, Serializable> searchKeyValue = restParameters.getSearchKeyValues().get(0);
|
||||
searchKey = searchKeyValue.getFirst();
|
||||
searchValue = searchKeyValue.getSecond();
|
||||
}
|
||||
if (searchKey != null)
|
||||
{
|
||||
// Look up the ID of the search key
|
||||
Pair<Long, Serializable> searchKeyPair = propertyValueDAO.getPropertyValue(searchKey);
|
||||
if (searchKeyPair == null)
|
||||
{
|
||||
// No such value
|
||||
return null;
|
||||
}
|
||||
dbParameters.setSearchKeyId(searchKeyPair.getFirst());
|
||||
}
|
||||
if (searchValue != null)
|
||||
{
|
||||
// Look up the ID of the search key
|
||||
Pair<Long, Serializable> searchValuePair = propertyValueDAO.getPropertyValue(searchValue);
|
||||
if (searchValuePair == null)
|
||||
{
|
||||
// No such value
|
||||
return null;
|
||||
}
|
||||
dbParameters.setSearchValueId(searchValuePair.getFirst());
|
||||
}
|
||||
dbParameters.setForward(restParameters.isForward());
|
||||
|
||||
return dbParameters;
|
||||
}
|
||||
}
|
||||
|
@@ -244,4 +244,16 @@ public interface AuditDAO
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue an audit query to retrieve count of records for a given application and properties
|
||||
*
|
||||
* @param applicationName name of the application to be queried
|
||||
* @param parameters audit parameters provided by the <code>where</code> clause on the ReST API
|
||||
* @return a map containing min/max and the associated value
|
||||
*/
|
||||
default int getAuditEntriesCountByAppAndProperties(String applicationName, org.alfresco.service.cmr.audit.AuditQueryParameters parameters)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
@@ -66,6 +66,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
|
||||
private static final String INSERT_ENTRY = "alfresco.audit.insert.insert_AuditEntry";
|
||||
private static final String SELECT_MINMAX_ENTRY_FOR_APP = "alfresco.audit.select_MinMaxAuditEntryId";
|
||||
private static final String SELECT_COUNT_ENTRIES_FOR_APP = "alfresco.audit.select_CountAuditEntryId";
|
||||
private static final String SELECT_COUNT_ENTRIES_FOR_APP_WITH_PROPERTIES = "select_CountAuditEntryIdWithWhereClause";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String SELECT_ENTRIES_SIMPLE = "alfresco.audit.select_AuditEntriesSimple";
|
||||
@@ -235,68 +236,29 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAuditEntriesCountByAppAndProperties(String applicationName, org.alfresco.service.cmr.audit.AuditQueryParameters parameters)
|
||||
{
|
||||
AuditQueryParameters dbParameters = convertFromRestAuditQueryParameters(parameters);
|
||||
|
||||
int result = template.selectOne(SELECT_COUNT_ENTRIES_FOR_APP_WITH_PROPERTIES, dbParameters);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void findAuditEntries(
|
||||
final AuditQueryRowHandler rowHandler,
|
||||
boolean forward,
|
||||
String appName, String user,
|
||||
Long fromId, Long toId,
|
||||
Long fromTime, Long toTime,
|
||||
int maxResults,
|
||||
String searchKey, Serializable searchValue)
|
||||
org.alfresco.service.cmr.audit.AuditQueryParameters restParameters)
|
||||
{
|
||||
AuditQueryParameters params = new AuditQueryParameters();
|
||||
if (appName != null)
|
||||
AuditQueryParameters params = convertFromRestAuditQueryParameters(restParameters);
|
||||
if (params==null)
|
||||
{
|
||||
// Look up the application's ID (this is unique)
|
||||
Pair<Long, Serializable> appNamePair = propertyValueDAO.getPropertyValue(appName);
|
||||
if (appNamePair == null)
|
||||
{
|
||||
// No such value
|
||||
return;
|
||||
}
|
||||
params.setAuditAppNameId(appNamePair.getFirst());
|
||||
return;
|
||||
}
|
||||
if (user != null)
|
||||
{
|
||||
// Look up the application's ID (this is unique)
|
||||
Pair<Long, Serializable> userPair = propertyValueDAO.getPropertyValue(user);
|
||||
if (userPair == null)
|
||||
{
|
||||
// No such value
|
||||
return;
|
||||
}
|
||||
params.setAuditUserId(userPair.getFirst());
|
||||
}
|
||||
params.setAuditFromId(fromId);
|
||||
params.setAuditToId(toId);
|
||||
params.setAuditFromTime(fromTime);
|
||||
params.setAuditToTime(toTime);
|
||||
if (searchKey != null)
|
||||
{
|
||||
// Look up the ID of the search key
|
||||
Pair<Long, Serializable> searchKeyPair = propertyValueDAO.getPropertyValue(searchKey);
|
||||
if (searchKeyPair == null)
|
||||
{
|
||||
// No such value
|
||||
return;
|
||||
}
|
||||
params.setSearchKeyId(searchKeyPair.getFirst());
|
||||
}
|
||||
if (searchValue != null)
|
||||
{
|
||||
// Look up the ID of the search key
|
||||
Pair<Long, Serializable> searchValuePair = propertyValueDAO.getPropertyValue(searchValue);
|
||||
if (searchValuePair == null)
|
||||
{
|
||||
// No such value
|
||||
return;
|
||||
}
|
||||
params.setSearchValueId(searchValuePair.getFirst());
|
||||
}
|
||||
params.setForward(forward);
|
||||
|
||||
|
||||
if (maxResults > 0)
|
||||
{
|
||||
// Query without getting the values. We gather all the results and batch-fetch the audited
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* 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%
|
||||
*/
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* 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.repo.download;
|
||||
|
||||
import java.io.File;
|
||||
@@ -36,6 +36,7 @@ import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.model.RenditionModel;
|
||||
import org.alfresco.repo.action.executer.ActionExecuter;
|
||||
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||
import org.alfresco.repo.rule.RuleModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
@@ -203,7 +204,7 @@ public class CreateDownloadArchiveAction extends ActionExecuterAbstractBase
|
||||
crawlerParameters.setExportFrom(exportFrom);
|
||||
|
||||
crawlerParameters.setCrawlSelf(true);
|
||||
crawlerParameters.setExcludeChildAssocs(new QName[] {RenditionModel.ASSOC_RENDITION, ForumModel.ASSOC_DISCUSSION});
|
||||
crawlerParameters.setExcludeChildAssocs(new QName[] {RenditionModel.ASSOC_RENDITION, ForumModel.ASSOC_DISCUSSION, RuleModel.ASSOC_RULE_FOLDER });
|
||||
crawlerParameters.setExcludeAspects(new QName[] {ContentModel.ASPECT_WORKING_COPY});
|
||||
|
||||
// Get an estimate of the size for statuses
|
||||
|
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.repo.jscript;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mozilla.javascript.Callable;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.ContextFactory;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Custom factory that allows to apply configured limits during script executions
|
||||
*
|
||||
* @see ContextFactory
|
||||
*/
|
||||
public class AlfrescoContextFactory extends ContextFactory
|
||||
{
|
||||
private static final Log LOGGER = LogFactory.getLog(AlfrescoContextFactory.class);
|
||||
|
||||
private int optimizationLevel = -1;
|
||||
private int maxScriptExecutionSeconds = -1;
|
||||
private int maxStackDepth = -1;
|
||||
private long maxMemoryUsedInBytes = -1L;
|
||||
private int observeInstructionCount = -1;
|
||||
|
||||
private AlfrescoScriptThreadMxBeanWrapper threadMxBeanWrapper;
|
||||
|
||||
private final int INTERPRETIVE_MODE = -1;
|
||||
|
||||
@Override
|
||||
protected Context makeContext()
|
||||
{
|
||||
AlfrescoScriptContext context = new AlfrescoScriptContext();
|
||||
|
||||
context.setOptimizationLevel(optimizationLevel);
|
||||
|
||||
// Needed for both time and memory measurement
|
||||
if (maxScriptExecutionSeconds > 0 || maxMemoryUsedInBytes > 0L)
|
||||
{
|
||||
if (observeInstructionCount > 0)
|
||||
{
|
||||
LOGGER.info("Enabling observer count...");
|
||||
context.setGenerateObserverCount(true);
|
||||
context.setInstructionObserverThreshold(observeInstructionCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.info("Disabling observer count...");
|
||||
context.setGenerateObserverCount(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Memory limit
|
||||
if (maxMemoryUsedInBytes > 0)
|
||||
{
|
||||
context.setThreadId(Thread.currentThread().getId());
|
||||
}
|
||||
|
||||
// Max stack depth
|
||||
if (maxStackDepth > 0)
|
||||
{
|
||||
if (optimizationLevel != INTERPRETIVE_MODE)
|
||||
{
|
||||
LOGGER.warn("Changing optimization level from " + optimizationLevel + " to " + INTERPRETIVE_MODE);
|
||||
}
|
||||
// stack depth can only be set when no optimizations are applied
|
||||
context.setOptimizationLevel(INTERPRETIVE_MODE);
|
||||
context.setMaximumInterpreterStackDepth(maxStackDepth);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void observeInstructionCount(Context cx, int instructionCount)
|
||||
{
|
||||
AlfrescoScriptContext acx = (AlfrescoScriptContext) cx;
|
||||
|
||||
if (acx.isLimitsEnabled())
|
||||
{
|
||||
// Time limit
|
||||
if (maxScriptExecutionSeconds > 0)
|
||||
{
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (currentTime - acx.getStartTime() > maxScriptExecutionSeconds * 1000)
|
||||
{
|
||||
throw new Error("Maximum script time of " + maxScriptExecutionSeconds + " seconds exceeded");
|
||||
}
|
||||
}
|
||||
|
||||
// Memory
|
||||
if (maxMemoryUsedInBytes > 0 && threadMxBeanWrapper != null && threadMxBeanWrapper.isThreadAllocatedMemorySupported())
|
||||
{
|
||||
|
||||
if (acx.getStartMemory() <= 0)
|
||||
{
|
||||
acx.setStartMemory(threadMxBeanWrapper.getThreadAllocatedBytes(acx.getThreadId()));
|
||||
}
|
||||
else
|
||||
{
|
||||
long currentAllocatedBytes = threadMxBeanWrapper.getThreadAllocatedBytes(acx.getThreadId());
|
||||
if (currentAllocatedBytes - acx.getStartMemory() >= maxMemoryUsedInBytes)
|
||||
{
|
||||
throw new Error("Memory limit of " + maxMemoryUsedInBytes + " bytes reached");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
|
||||
{
|
||||
AlfrescoScriptContext acx = (AlfrescoScriptContext) cx;
|
||||
acx.setStartTime(System.currentTimeMillis());
|
||||
return super.doTopCall(callable, cx, scope, thisObj, args);
|
||||
}
|
||||
|
||||
public int getOptimizationLevel()
|
||||
{
|
||||
return optimizationLevel;
|
||||
}
|
||||
|
||||
public void setOptimizationLevel(int optimizationLevel)
|
||||
{
|
||||
this.optimizationLevel = optimizationLevel;
|
||||
}
|
||||
|
||||
public int getMaxScriptExecutionSeconds()
|
||||
{
|
||||
return maxScriptExecutionSeconds;
|
||||
}
|
||||
|
||||
public void setMaxScriptExecutionSeconds(int maxScriptExecutionSeconds)
|
||||
{
|
||||
this.maxScriptExecutionSeconds = maxScriptExecutionSeconds;
|
||||
}
|
||||
|
||||
public int getMaxStackDepth()
|
||||
{
|
||||
return maxStackDepth;
|
||||
}
|
||||
|
||||
public void setMaxStackDepth(int maxStackDepth)
|
||||
{
|
||||
this.maxStackDepth = maxStackDepth;
|
||||
}
|
||||
|
||||
public long getMaxMemoryUsedInBytes()
|
||||
{
|
||||
return maxMemoryUsedInBytes;
|
||||
}
|
||||
|
||||
public void setMaxMemoryUsedInBytes(long maxMemoryUsedInBytes)
|
||||
{
|
||||
this.maxMemoryUsedInBytes = maxMemoryUsedInBytes;
|
||||
if (maxMemoryUsedInBytes > 0)
|
||||
{
|
||||
this.threadMxBeanWrapper = new AlfrescoScriptThreadMxBeanWrapper();
|
||||
if (!threadMxBeanWrapper.isThreadAllocatedMemorySupported())
|
||||
{
|
||||
LOGGER.warn("com.sun.management.ThreadMXBean was not found on the classpath. "
|
||||
+ "This means that the limiting the memory usage for a script will NOT work.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getObserveInstructionCount()
|
||||
{
|
||||
return observeInstructionCount;
|
||||
}
|
||||
|
||||
public void setObserveInstructionCount(int observeInstructionCount)
|
||||
{
|
||||
this.observeInstructionCount = observeInstructionCount;
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.repo.jscript;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
|
||||
/**
|
||||
* Custom Rhino context that holds data as start time and memory
|
||||
*
|
||||
* @see Context
|
||||
*/
|
||||
public class AlfrescoScriptContext extends Context
|
||||
{
|
||||
private long startTime;
|
||||
private long threadId;
|
||||
private long startMemory;
|
||||
private boolean limitsEnabled = false;
|
||||
|
||||
public long getStartTime()
|
||||
{
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(long startTime)
|
||||
{
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public long getThreadId()
|
||||
{
|
||||
return threadId;
|
||||
}
|
||||
|
||||
public void setThreadId(long threadId)
|
||||
{
|
||||
this.threadId = threadId;
|
||||
}
|
||||
|
||||
public long getStartMemory()
|
||||
{
|
||||
return startMemory;
|
||||
}
|
||||
|
||||
public void setStartMemory(long startMemory)
|
||||
{
|
||||
this.startMemory = startMemory;
|
||||
}
|
||||
|
||||
public boolean isLimitsEnabled()
|
||||
{
|
||||
return limitsEnabled;
|
||||
}
|
||||
|
||||
public void setLimitsEnabled(boolean limitsEnabled)
|
||||
{
|
||||
this.limitsEnabled = limitsEnabled;
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.repo.jscript;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
|
||||
/**
|
||||
* Allows to monitor memory usage
|
||||
*/
|
||||
public class AlfrescoScriptThreadMxBeanWrapper
|
||||
{
|
||||
|
||||
private ThreadMXBean threadMXBean = null;
|
||||
private boolean threadAllocatedMemorySupported = false;
|
||||
|
||||
private final String THREAD_MX_BEAN_SUN = "com.sun.management.ThreadMXBean";
|
||||
|
||||
public AlfrescoScriptThreadMxBeanWrapper()
|
||||
{
|
||||
checkThreadAllocatedMemory();
|
||||
}
|
||||
|
||||
public long getThreadAllocatedBytes(long threadId)
|
||||
{
|
||||
if (threadMXBean != null && threadAllocatedMemorySupported)
|
||||
{
|
||||
return ((com.sun.management.ThreadMXBean) threadMXBean).getThreadAllocatedBytes(threadId);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void checkThreadAllocatedMemory()
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> clazz = Class.forName(THREAD_MX_BEAN_SUN);
|
||||
if (clazz != null)
|
||||
{
|
||||
this.threadAllocatedMemorySupported = true;
|
||||
this.threadMXBean = (com.sun.management.ThreadMXBean) ManagementFactory.getThreadMXBean();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.threadAllocatedMemorySupported = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isThreadAllocatedMemorySupported()
|
||||
{
|
||||
return threadAllocatedMemorySupported;
|
||||
}
|
||||
}
|
@@ -57,10 +57,12 @@ import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.ContextFactory;
|
||||
import org.mozilla.javascript.ImporterTopLevel;
|
||||
import org.mozilla.javascript.Script;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.mozilla.javascript.Undefined;
|
||||
import org.mozilla.javascript.WrapFactory;
|
||||
import org.mozilla.javascript.WrappedException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -108,7 +110,24 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
|
||||
/** Cache of runtime compiled script instances */
|
||||
private final Map<String, Script> scriptCache = new ConcurrentHashMap<String, Script>(256);
|
||||
|
||||
|
||||
/** Rhino optimization level */
|
||||
private int optimizationLevel = -1;
|
||||
|
||||
/** Maximum seconds a script is allowed to run */
|
||||
private int maxScriptExecutionSeconds = -1;
|
||||
|
||||
/** Maximum of call stack depth (in terms of number of call frames) */
|
||||
private int maxStackDepth = -1;
|
||||
|
||||
/** Maximum memory (bytes) a script can use */
|
||||
private long maxMemoryUsedInBytes = -1L;
|
||||
|
||||
/** Number of (bytecode) instructions that will trigger the observer */
|
||||
private int observerInstructionCount = 100;
|
||||
|
||||
/** Custom context factory */
|
||||
public static AlfrescoContextFactory contextFactory;
|
||||
|
||||
/**
|
||||
* Set the default store reference
|
||||
*
|
||||
@@ -143,6 +162,51 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
|
||||
{
|
||||
this.shareSealedScopes = shareSealedScopes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param optimizationLevel
|
||||
* -1 interpretive mode, 0 no optimizations, 1-9 optimizations performed
|
||||
*/
|
||||
public void setOptimizationLevel(int optimizationLevel)
|
||||
{
|
||||
this.optimizationLevel = optimizationLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxScriptExecutionSeconds
|
||||
* the number of seconds a script is allowed to run
|
||||
*/
|
||||
public void setMaxScriptExecutionSeconds(int maxScriptExecutionSeconds)
|
||||
{
|
||||
this.maxScriptExecutionSeconds = maxScriptExecutionSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxStackDepth
|
||||
* the number of call stack depth allowed
|
||||
*/
|
||||
public void setMaxStackDepth(int maxStackDepth)
|
||||
{
|
||||
this.maxStackDepth = maxStackDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxMemoryUsedInBytes
|
||||
* the number of memory a script can use
|
||||
*/
|
||||
public void setMaxMemoryUsedInBytes(long maxMemoryUsedInBytes)
|
||||
{
|
||||
this.maxMemoryUsedInBytes = maxMemoryUsedInBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param observerInstructionCount
|
||||
* the number of instructions that will trigger {@link ContextFactory#observeInstructionCount}
|
||||
*/
|
||||
public void setObserverInstructionCount(int observerInstructionCount)
|
||||
{
|
||||
this.observerInstructionCount = observerInstructionCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.repository.ScriptProcessor#reset()
|
||||
@@ -449,6 +513,8 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
|
||||
private Object executeScriptImpl(Script script, Map<String, Object> model, boolean secure, String debugScriptName)
|
||||
throws AlfrescoRuntimeException
|
||||
{
|
||||
Scriptable scope = null;
|
||||
|
||||
long startTime = 0;
|
||||
if (callLogger.isDebugEnabled())
|
||||
{
|
||||
@@ -465,14 +531,16 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
|
||||
// Create a thread-specific scope from one of the shared scopes.
|
||||
// See http://www.mozilla.org/rhino/scopes.html
|
||||
cx.setWrapFactory(secure ? wrapFactory : sandboxFactory);
|
||||
Scriptable scope;
|
||||
|
||||
// Enables or disables execution limits based on secure flag
|
||||
enableLimits(cx, secure);
|
||||
|
||||
if (this.shareSealedScopes)
|
||||
{
|
||||
Scriptable sharedScope = secure ? this.nonSecureScope : this.secureScope;
|
||||
scope = cx.newObject(sharedScope);
|
||||
scope.setPrototype(sharedScope);
|
||||
scope.setParentScope(null);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -545,7 +613,8 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
|
||||
throw new AlfrescoRuntimeException(err.getMessage(), err);
|
||||
}
|
||||
finally
|
||||
{
|
||||
{
|
||||
unsetScope(model, scope);
|
||||
Context.exit();
|
||||
|
||||
if (callLogger.isDebugEnabled())
|
||||
@@ -638,6 +707,9 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
// Initialize context factory
|
||||
initContextFactory();
|
||||
|
||||
// Initialize the secure scope
|
||||
Context cx = Context.enter();
|
||||
try
|
||||
@@ -695,4 +767,129 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean supplied scope and unset it from any model instance where it has been injected before
|
||||
*
|
||||
* @param model
|
||||
* Data model containing objects from where scope will be unset
|
||||
* @param scope
|
||||
* The scope to clean
|
||||
*/
|
||||
private void unsetScope(Map<String, Object> model, Scriptable scope)
|
||||
{
|
||||
if (scope != null)
|
||||
{
|
||||
Object[] ids = scope.getIds();
|
||||
if (ids != null)
|
||||
{
|
||||
for (Object id : ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
deleteProperty(scope, id.toString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.info("Unable to delete id: " + id, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
for (String key : model.keySet())
|
||||
{
|
||||
try
|
||||
{
|
||||
deleteProperty(scope, key);
|
||||
|
||||
Object obj = model.get(key);
|
||||
if (obj instanceof Scopeable)
|
||||
{
|
||||
((Scopeable) obj).setScope(null);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.info("Unable to unset model object " + key + " : ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a property from the supplied scope, if property is not removable, then is set to null
|
||||
*
|
||||
* @param scope
|
||||
* the scope object from where property will be removed
|
||||
* @param name
|
||||
* the property name to delete
|
||||
*/
|
||||
private void deleteProperty(Scriptable scope, String name)
|
||||
{
|
||||
if (scope != null && name != null)
|
||||
{
|
||||
if (!ScriptableObject.deleteProperty(scope, name))
|
||||
{
|
||||
ScriptableObject.putProperty(scope, name, null);
|
||||
}
|
||||
scope.delete(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the context factory with limits configuration
|
||||
*/
|
||||
private synchronized void initContextFactory()
|
||||
{
|
||||
if (contextFactory == null)
|
||||
{
|
||||
contextFactory = new AlfrescoContextFactory();
|
||||
contextFactory.setOptimizationLevel(optimizationLevel);
|
||||
|
||||
if (maxScriptExecutionSeconds > 0)
|
||||
{
|
||||
contextFactory.setMaxScriptExecutionSeconds(maxScriptExecutionSeconds);
|
||||
}
|
||||
|
||||
if (maxMemoryUsedInBytes > 0L)
|
||||
{
|
||||
contextFactory.setMaxMemoryUsedInBytes(maxMemoryUsedInBytes);
|
||||
}
|
||||
|
||||
if (maxStackDepth > 0)
|
||||
{
|
||||
contextFactory.setMaxStackDepth(maxStackDepth);
|
||||
}
|
||||
|
||||
if (maxScriptExecutionSeconds > 0 || maxMemoryUsedInBytes > 0L)
|
||||
{
|
||||
contextFactory.setObserveInstructionCount(observerInstructionCount);
|
||||
}
|
||||
|
||||
ContextFactory.initGlobal(contextFactory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If script is considered secure no limits will be applied, otherwise, the limits are enabled and the script can be
|
||||
* interrupted in case a limit has been reached.
|
||||
*
|
||||
* @param cx
|
||||
* the Rhino scope
|
||||
* @param secure
|
||||
* true if script execution is considered secure (e.g, deployed at classpath level)
|
||||
*/
|
||||
private void enableLimits(Context cx, boolean secure)
|
||||
{
|
||||
if (cx != null)
|
||||
{
|
||||
if (cx instanceof AlfrescoScriptContext)
|
||||
{
|
||||
((AlfrescoScriptContext) cx).setLimitsEnabled(!secure);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -267,8 +267,12 @@ public class SolrJSONResultSet implements SearchEngineResultSet {
|
||||
ArrayList<Pair<String, Integer>> facetValues = new ArrayList<Pair<String, Integer>>(facetArraySize/2);
|
||||
for(int i = 0; i < facetArraySize; i+=2)
|
||||
{
|
||||
String facetEntryName = facets.getString(i);
|
||||
Integer facetEntryCount = Integer.valueOf(facets.getInt(i+1));
|
||||
String facetEntryName = "Null";
|
||||
if(!facets.isNull(i))
|
||||
{
|
||||
facetEntryName = facets.getString(i);
|
||||
}
|
||||
Integer facetEntryCount = Integer.valueOf(facets.getInt(i + 1));
|
||||
Pair<String, Integer> pair = new Pair<String, Integer>(facetEntryName, facetEntryCount);
|
||||
facetValues.add(pair);
|
||||
}
|
||||
|
@@ -252,4 +252,16 @@ public interface AuditService
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue an audit query to retrieve min / max audit record id for a given application and properties
|
||||
*
|
||||
* @param applicationName the name of the application
|
||||
* @param parameters audit parameters provided by the <code>where</code> clause on the ReST API
|
||||
* @return a map containing min/max and the associated value
|
||||
*/
|
||||
default int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@@ -50,6 +50,15 @@
|
||||
<!-- Parameter Maps -->
|
||||
<!-- -->
|
||||
|
||||
<parameterMap id="parameter_AuditAppId_WhereClauseMap" type="map">
|
||||
<parameter property="auditAppNameId" jdbcType="BIGINT" javaType="Long"/>
|
||||
<parameter property="auditUserId" jdbcType="BIGINT" javaType="Long"/>
|
||||
<parameter property="auditFromTime" jdbcType="BIGINT" javaType="Long"/>
|
||||
<parameter property="auditToTime" jdbcType="BIGINT" javaType="Long"/>
|
||||
<parameter property="auditFromId" jdbcType="BIGINT" javaType="Long"/>
|
||||
<parameter property="auditToId" jdbcType="BIGINT" javaType="Long"/>
|
||||
</parameterMap>
|
||||
|
||||
<parameterMap id="parameter_IdMap" type="map">
|
||||
<parameter property="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
|
||||
</parameterMap>
|
||||
@@ -291,6 +300,20 @@
|
||||
alf_audit_entry.audit_app_id = #{auditAppId}
|
||||
</select>
|
||||
|
||||
<select id="select_CountAuditEntryIdWithWhereClause" parameterMap="parameter_AuditAppId_WhereClauseMap" resultType="int">
|
||||
select
|
||||
COUNT(entry.id)
|
||||
from
|
||||
alf_audit_entry as entry
|
||||
<if test="auditAppNameId != null">
|
||||
join alf_audit_app app on (entry.audit_app_id = app.id)
|
||||
</if>
|
||||
<if test="keyOrValueSearch == true">
|
||||
join alf_prop_link sp_pl on (sp_pl.root_prop_id = entry.audit_values_id)
|
||||
</if>
|
||||
<include refid="select_AuditEntriesWhereSnippet"/>
|
||||
</select>
|
||||
|
||||
<!-- Get the maximum/minimum audit entry id for application -->
|
||||
<select id="select_MinMaxAuditEntryId" parameterMap="parameter_IdMinMaxMap" resultMap="result_minMaxMap">
|
||||
select
|
||||
|
@@ -3,7 +3,7 @@
|
||||
repository.name=Main Repository
|
||||
|
||||
# Schema number
|
||||
version.schema=17000
|
||||
version.schema=18000
|
||||
|
||||
# Directory configuration
|
||||
|
||||
@@ -1351,3 +1351,18 @@ import.zip.compressionRatioThreshold=100
|
||||
# "zip bomb" and the import extraction process cancelled. No value (or a negative long) will be taken to mean that no
|
||||
# limit should be applied.
|
||||
import.zip.uncompressedBytesLimit=
|
||||
|
||||
# Rhino optimization level
|
||||
scripts.execution.optimizationLevel=0
|
||||
|
||||
# Max seconds a script is allowed to run
|
||||
scripts.execution.maxScriptExecutionSeconds=-1
|
||||
|
||||
# Max call stack depth
|
||||
scripts.execution.maxStackDepth=-1
|
||||
|
||||
# Max memory (bytes) a script can use
|
||||
scripts.execution.maxMemoryUsedInBytes=-1
|
||||
|
||||
# Number of instructions that will trigger the observer
|
||||
scripts.execution.observerInstructionCount=-1
|
||||
|
@@ -45,6 +45,21 @@
|
||||
<property name="storePath">
|
||||
<value>${spaces.company_home.childname}</value>
|
||||
</property>
|
||||
<property name="optimizationLevel">
|
||||
<value>${scripts.execution.optimizationLevel}</value>
|
||||
</property>
|
||||
<property name="maxScriptExecutionSeconds">
|
||||
<value>${scripts.execution.maxScriptExecutionSeconds}</value>
|
||||
</property>
|
||||
<property name="maxStackDepth">
|
||||
<value>${scripts.execution.maxStackDepth}</value>
|
||||
</property>
|
||||
<property name="maxMemoryUsedInBytes">
|
||||
<value>${scripts.execution.maxMemoryUsedInBytes}</value>
|
||||
</property>
|
||||
<property name="observerInstructionCount">
|
||||
<value>${scripts.execution.observerInstructionCount}</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- base config implementation that script extension beans extend from - for auto registration
|
||||
|
@@ -77,6 +77,7 @@ import org.junit.runners.Suite;
|
||||
org.alfresco.repo.rule.RuleServiceImplUnitTest.class,
|
||||
org.alfresco.repo.service.StoreRedirectorProxyFactoryTest.class,
|
||||
org.alfresco.repo.site.RoleComparatorImplTest.class,
|
||||
org.alfresco.repo.template.UnsafeMethodsTest.class,
|
||||
org.alfresco.repo.tenant.MultiTAdminServiceImplTest.class,
|
||||
org.alfresco.repo.thumbnail.ThumbnailServiceImplParameterTest.class,
|
||||
org.alfresco.repo.transfer.ContentChunkerImplTest.class,
|
||||
|
@@ -27,6 +27,7 @@ package org.alfresco.repo.download;
|
||||
|
||||
import net.sf.acegisecurity.Authentication;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.executer.AddFeaturesActionExecuter;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.node.SystemNodeUtils;
|
||||
import org.alfresco.repo.node.integrity.IntegrityChecker;
|
||||
@@ -34,6 +35,8 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.admin.RepoAdminService;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.download.DownloadService;
|
||||
@@ -47,6 +50,8 @@ import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.service.cmr.rule.RuleType;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
@@ -75,6 +80,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -82,6 +88,7 @@ import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
@@ -128,6 +135,8 @@ public class DownloadServiceIntegrationTest
|
||||
private static RetryingTransactionHelper TRANSACTION_HELPER;
|
||||
private static IntegrityChecker INTEGRITY_CHECKER;
|
||||
private static RepoAdminService REPO_ADMIN_SERVICE;
|
||||
private static RuleService RULE_SERVICE;
|
||||
private static ActionService ACTION_SERVICE;
|
||||
|
||||
// Test Content
|
||||
private NodeRef rootFolder;
|
||||
@@ -192,6 +201,8 @@ public class DownloadServiceIntegrationTest
|
||||
INTEGRITY_CHECKER.setFailOnViolation(true);
|
||||
INTEGRITY_CHECKER.setTraceOn(true);
|
||||
REPO_ADMIN_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("RepoAdminService", RepoAdminService.class);
|
||||
RULE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("ruleService", RuleService.class);
|
||||
ACTION_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("actionService", ActionService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,28 +218,49 @@ public class DownloadServiceIntegrationTest
|
||||
NodeRef COMPANY_HOME = repositoryHelper.getCompanyHome();
|
||||
|
||||
// Create some static test content
|
||||
rootFolder = testNodes.createNode(COMPANY_HOME, "rootFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
|
||||
allEntries.add("rootFolder/");
|
||||
rootFolder = testNodes.createNode(COMPANY_HOME, "rootFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
|
||||
allEntries.add("rootFolder/");
|
||||
|
||||
TRANSACTION_HELPER.doInTransaction(() -> {
|
||||
org.alfresco.service.cmr.rule.Rule parentRule = new org.alfresco.service.cmr.rule.Rule();
|
||||
parentRule.setRuleTypes(Collections.singletonList(RuleType.INBOUND));
|
||||
parentRule.setTitle("DownloadServiceIntegrationTest" + GUID.generate());
|
||||
parentRule.setDescription("Add Classifiable");
|
||||
Action action = ACTION_SERVICE.createAction(AddFeaturesActionExecuter.NAME);
|
||||
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
|
||||
parentRule.setAction(action);
|
||||
parentRule.applyToChildren(true);
|
||||
|
||||
RULE_SERVICE.saveRule(rootFolder, parentRule);
|
||||
|
||||
return null;
|
||||
}, false, true);
|
||||
|
||||
rootFile = testNodes.createNodeWithTextContent(COMPANY_HOME, "rootFile.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Root file content");
|
||||
allEntries.add("rootFile.txt");
|
||||
|
||||
testNodes.createNodeWithTextContent(rootFolder, "level1File.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 1 file content");
|
||||
|
||||
NodeRef createdNode = testNodes.createNodeWithTextContent(rootFolder, "level1File.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 1 file content");
|
||||
assertTrue(NODE_SERVICE.hasAspect(createdNode, ContentModel.ASPECT_CLASSIFIABLE));
|
||||
allEntries.add("rootFolder/level1File.txt");
|
||||
|
||||
level1Folder1 = testNodes.createNode(rootFolder, "level1Folder1", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
|
||||
assertTrue(NODE_SERVICE.hasAspect(level1Folder1, ContentModel.ASPECT_CLASSIFIABLE));
|
||||
allEntries.add("rootFolder/level1Folder1/");
|
||||
|
||||
level1Folder2 = testNodes.createNode(rootFolder, "level1Folder2", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
|
||||
assertTrue(NODE_SERVICE.hasAspect(level1Folder2, ContentModel.ASPECT_CLASSIFIABLE));
|
||||
allEntries.add("rootFolder/level1Folder2/");
|
||||
|
||||
testNodes.createNode(rootFolder, "level1EmptyFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
|
||||
createdNode = testNodes.createNode(rootFolder, "level1EmptyFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
|
||||
assertTrue(NODE_SERVICE.hasAspect(createdNode, ContentModel.ASPECT_CLASSIFIABLE));
|
||||
allEntries.add("rootFolder/level1EmptyFolder/");
|
||||
|
||||
testNodes.createNodeWithTextContent(level1Folder1, "level2File.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 2 file content");
|
||||
createdNode = testNodes.createNodeWithTextContent(level1Folder1, "level2File.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 2 file content");
|
||||
assertTrue(NODE_SERVICE.hasAspect(createdNode, ContentModel.ASPECT_CLASSIFIABLE));
|
||||
allEntries.add("rootFolder/level1Folder1/level2File.txt");
|
||||
|
||||
testNodes.createNodeWithTextContent(level1Folder2, "level2File.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 2 file content");
|
||||
createdNode = testNodes.createNodeWithTextContent(level1Folder2, "level2File.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 2 file content");
|
||||
assertTrue(NODE_SERVICE.hasAspect(createdNode, ContentModel.ASPECT_CLASSIFIABLE));
|
||||
allEntries.add("rootFolder/level1Folder2/level2File.txt");
|
||||
|
||||
secondaryNode = testNodes.createNodeWithTextContent(COMPANY_HOME, "secondaryNodeFile.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Secondary node");
|
||||
@@ -240,6 +272,7 @@ public class DownloadServiceIntegrationTest
|
||||
// Add the lock and version aspects to the created node
|
||||
NODE_SERVICE.addAspect(fileToCheckout, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
NODE_SERVICE.addAspect(fileToCheckout, ContentModel.ASPECT_LOCKABLE, null);
|
||||
assertTrue(NODE_SERVICE.hasAspect(fileToCheckout, ContentModel.ASPECT_CLASSIFIABLE));
|
||||
|
||||
allEntries.add("rootFolder/level1Folder2/fileToCheckout.txt");
|
||||
PERMISSION_SERVICE.setPermission(level1Folder2, TEST_USER.getUsername(), PermissionService.ALL_PERMISSIONS, true);
|
||||
|
@@ -44,7 +44,6 @@ import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.ScriptProcessor;
|
||||
import org.alfresco.service.cmr.repository.ScriptService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -53,8 +52,11 @@ import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.ImporterTopLevel;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.mozilla.javascript.Undefined;
|
||||
import org.mozilla.javascript.UniqueTag;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
@@ -445,6 +447,67 @@ public class RhinoScriptTest extends TestCase
|
||||
assertTrue("Script should have been executed (secure = true)", executed);
|
||||
}
|
||||
|
||||
// MNT-23158
|
||||
public void testScopeData()
|
||||
{
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||
new RetryingTransactionCallback<Object>()
|
||||
{
|
||||
public Object execute() throws Exception
|
||||
{
|
||||
Context cx = Context.enter();
|
||||
try
|
||||
{
|
||||
Scriptable sharedScope = new ImporterTopLevel(cx, true);
|
||||
Scriptable scope = cx.newObject(sharedScope);
|
||||
scope.setPrototype(sharedScope);
|
||||
scope.setParentScope(null);
|
||||
|
||||
// Executes a first script
|
||||
Object result = cx.evaluateString(scope, "var a = 10; var b = 20; var sum = a+b;", "TestJS1", 1, null);
|
||||
assertTrue(Undefined.isUndefined(result));
|
||||
|
||||
// Test sum value
|
||||
Object sum = scope.get("sum", scope);
|
||||
assertEquals(30.0, Context.toNumber(sum));
|
||||
|
||||
// No 'sum' property should be found in the shared scope
|
||||
sum = sharedScope.get("sum", sharedScope);
|
||||
assertEquals(sum, UniqueTag.NOT_FOUND);
|
||||
|
||||
// No 'b' property should be found in the shared scope
|
||||
Object b = ScriptableObject.getProperty(sharedScope, "b");
|
||||
assertEquals(b, UniqueTag.NOT_FOUND);
|
||||
|
||||
// Cleans scope
|
||||
unsetScope(scope);
|
||||
|
||||
// Executes a second script using the same scope
|
||||
result = cx.evaluateString(scope, "var test = 'test';", "TestJS2", 1, null);
|
||||
|
||||
// 'sum' property should be null
|
||||
sum = scope.get("sum", scope);
|
||||
assertNull(sum);
|
||||
|
||||
// New scope initialization
|
||||
scope = cx.newObject(sharedScope);
|
||||
scope.setPrototype(sharedScope);
|
||||
scope.setParentScope(null);
|
||||
|
||||
// check 'test' property
|
||||
Object test = scope.get("test", scope);
|
||||
assertEquals(test, UniqueTag.NOT_FOUND);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Context.exit();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean executeSecureScriptString(String script, Boolean secure)
|
||||
{
|
||||
return transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Boolean>()
|
||||
@@ -475,6 +538,41 @@ public class RhinoScriptTest extends TestCase
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void unsetScope(Scriptable scope)
|
||||
{
|
||||
if (scope != null)
|
||||
{
|
||||
Object[] ids = scope.getIds();
|
||||
|
||||
if (ids != null)
|
||||
{
|
||||
for (Object id : ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
deleteProperty(scope, id.toString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteProperty(Scriptable scope, String name)
|
||||
{
|
||||
if (scope != null && name != null)
|
||||
{
|
||||
if (!ScriptableObject.deleteProperty(scope, name))
|
||||
{
|
||||
ScriptableObject.putProperty(scope, name, null);
|
||||
}
|
||||
scope.delete(name);
|
||||
}
|
||||
}
|
||||
|
||||
private static final String TESTSCRIPT_CLASSPATH1 = "org/alfresco/repo/jscript/test_script1.js";
|
||||
private static final String TESTSCRIPT_CLASSPATH2 = "org/alfresco/repo/jscript/test_script2.js";
|
||||
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.repo.template;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import freemarker.template.TemplateExceptionHandler;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class UnsafeMethodsTest extends TestCase
|
||||
{
|
||||
private static final String TEST_TEMPLATES_PACKAGE = "/org/alfresco/repo/template/templates/";
|
||||
private static final String ALLOWED_TEXT = ": ALLOWED";
|
||||
private static final String BLOCKED_TEXT = ": BLOCKED";
|
||||
private static final String EXPECTED_RESULT = "Freemarker Unsafe Methods Testing\n" +
|
||||
"=================================\n" +
|
||||
"java.lang.Thread.getId(): ALLOWED\n" +
|
||||
"java.lang.Thread.interrupt(): BLOCKED\n" +
|
||||
"java.lang.Thread.currentThread(): BLOCKED\n";
|
||||
|
||||
private final Configuration configuration = new Configuration(Configuration.VERSION_2_3_31);
|
||||
|
||||
public void testUnsafeMethods() throws Exception
|
||||
{
|
||||
configuration.setClassForTemplateLoading(getClass(), TEST_TEMPLATES_PACKAGE);
|
||||
configuration.setDefaultEncoding("UTF-8");
|
||||
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
|
||||
Template template = configuration.getTemplate("unsafemethods.ftl");
|
||||
|
||||
Thread currentThread = Thread.currentThread();
|
||||
Map<String, Object> model = Map.of(
|
||||
"allowedText", ALLOWED_TEXT,
|
||||
"blockedText", BLOCKED_TEXT,
|
||||
"thread", currentThread);
|
||||
|
||||
String result = applyTemplate(template, model);
|
||||
|
||||
assertFalse(currentThread.isInterrupted());
|
||||
assertEquals(EXPECTED_RESULT, result);
|
||||
}
|
||||
|
||||
private String applyTemplate(Template template, Map<String, Object> inputModel ) throws TemplateException, IOException
|
||||
{
|
||||
try (StringWriter stringWriter = new StringWriter())
|
||||
{
|
||||
template.process(inputModel, stringWriter);
|
||||
return stringWriter.toString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
Freemarker Unsafe Methods Testing
|
||||
=================================
|
||||
java.lang.Thread.getId()<#if (thread.getId())??>${allowedText}<#else>${blockedText}</#if>
|
||||
java.lang.Thread.interrupt()<#if (thread.interrupt())??>${allowedText}<#else>${blockedText}</#if>
|
||||
java.lang.Thread.currentThread()<#if (thread.currentThread())??>${allowedText}<#else>${blockedText}</#if>
|
Reference in New Issue
Block a user