mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-100: Audit tool is not working
* Refactored server side unit tests (exposed at least one bug and shows that the event and property filters are still not working) * Fixed up admin and object audit views (formatting is still terrible, but it's functional) * Will close out the related issue, since formatting and other issues are covered by other bugs. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.0@36483 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -216,7 +216,7 @@ public final class RecordsManagementAuditEntry
|
||||
*/
|
||||
public Map<QName, Serializable> getAfterProperties()
|
||||
{
|
||||
return this.beforeProperties;
|
||||
return this.afterProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -42,7 +42,7 @@ import org.quartz.JobExecutionException;
|
||||
*/
|
||||
public class RecordsManagementJob implements Job
|
||||
{
|
||||
private static long DEFAULT_TIME = 2000L;
|
||||
private static long DEFAULT_TIME = 30000L;
|
||||
|
||||
private JobLockService jobLockService;
|
||||
|
||||
|
@@ -22,296 +22,283 @@ import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.audit.AuditEvent;
|
||||
import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditEntry;
|
||||
import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditQueryParameters;
|
||||
import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.TestUtilities;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* @see RecordsManagementAuditService
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @author Roy Wetherall
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public class RecordsManagementAuditServiceImplTest extends TestCase
|
||||
public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase implements RMPermissionModel
|
||||
{
|
||||
private ApplicationContext ctx;
|
||||
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private NodeService nodeService;
|
||||
private TransactionService transactionService;
|
||||
private RetryingTransactionHelper txnHelper;
|
||||
private RecordsManagementAuditService rmAuditService;
|
||||
/** Records management audit service */
|
||||
private RecordsManagementAuditService auditService;
|
||||
|
||||
/** Test record */
|
||||
private NodeRef record;
|
||||
|
||||
/** Test start time */
|
||||
private Date testStartTime;
|
||||
private NodeRef filePlan;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#setUp()
|
||||
*/
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
// test start time recorded
|
||||
testStartTime = new Date();
|
||||
|
||||
// We require that records management auditing is enabled
|
||||
// This gets done by the AMP, but as we're not running from
|
||||
// and AMP, we need to do it ourselves!
|
||||
System.setProperty("audit.rm.enabled", "true");
|
||||
|
||||
// Now we can fetch the context
|
||||
ctx = ApplicationContextHelper.getApplicationContext();
|
||||
|
||||
this.serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
this.transactionService = serviceRegistry.getTransactionService();
|
||||
this.txnHelper = transactionService.getRetryingTransactionHelper();
|
||||
|
||||
this.rmAuditService = (RecordsManagementAuditService) ctx.getBean("RecordsManagementAuditService");
|
||||
|
||||
this.nodeService = serviceRegistry.getNodeService();
|
||||
|
||||
|
||||
// Set the current security context as admin
|
||||
AuthenticationUtil.setRunAsUser(AuthenticationUtil.getSystemUserName());
|
||||
|
||||
// Stop and clear the log
|
||||
rmAuditService.stop();
|
||||
rmAuditService.clear();
|
||||
rmAuditService.start();
|
||||
auditService.stop();
|
||||
auditService.clear();
|
||||
auditService.start();
|
||||
|
||||
RetryingTransactionCallback<Void> setUpCallback = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
if (filePlan == null)
|
||||
{
|
||||
filePlan = TestUtilities.loadFilePlanData(ctx);
|
||||
}
|
||||
updateFilePlan();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
txnHelper.doInTransaction(setUpCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown()
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
try
|
||||
{
|
||||
rmAuditService.start();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
// Not too important
|
||||
}
|
||||
// check that audit service is started
|
||||
assertTrue(auditService.isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a full query audit for RM
|
||||
* @return Returns all the results
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#initServices()
|
||||
*/
|
||||
private List<RecordsManagementAuditEntry> queryAll()
|
||||
@Override
|
||||
protected void initServices()
|
||||
{
|
||||
RetryingTransactionCallback<List<RecordsManagementAuditEntry>> testCallback =
|
||||
new RetryingTransactionCallback<List<RecordsManagementAuditEntry>>()
|
||||
{
|
||||
public List<RecordsManagementAuditEntry> execute() throws Throwable
|
||||
{
|
||||
RecordsManagementAuditQueryParameters params = new RecordsManagementAuditQueryParameters();
|
||||
List<RecordsManagementAuditEntry> entries = rmAuditService.getAuditTrail(params);
|
||||
return entries;
|
||||
}
|
||||
};
|
||||
return txnHelper.doInTransaction(testCallback);
|
||||
super.initServices();
|
||||
|
||||
// get the audit service
|
||||
auditService = (RecordsManagementAuditService)applicationContext.getBean("RecordsManagementAuditService");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new fileplan
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#tearDown()
|
||||
*/
|
||||
private void updateFilePlan()
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
RetryingTransactionCallback<Void> updateCallback = new RetryingTransactionCallback<Void>()
|
||||
super.tearDown();
|
||||
|
||||
// ensure the audit is restarted
|
||||
auditService.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#isUserTest()
|
||||
*/
|
||||
@Override
|
||||
protected boolean isUserTest()
|
||||
{
|
||||
public Void execute() throws Throwable
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#setupTestDataImpl()
|
||||
*/
|
||||
@Override
|
||||
protected void setupTestDataImpl()
|
||||
{
|
||||
// Do some stuff
|
||||
nodeService.setProperty(filePlan, ContentModel.PROP_TITLE, "File Plan - " + System.currentTimeMillis());
|
||||
super.setupTestDataImpl();
|
||||
|
||||
record = utils.createRecord(rmFolder, "AuditTest.txt");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#setupTestUsersImpl(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
protected void setupTestUsersImpl(NodeRef filePlan)
|
||||
{
|
||||
super.setupTestUsersImpl(filePlan);
|
||||
|
||||
// Give all the users file permission objects
|
||||
for (String user : testUsers)
|
||||
{
|
||||
securityService.setPermission(filePlan, user, FILING);
|
||||
securityService.setPermission(rmContainer, user, FILING);
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetAuditEvents()
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
List<AuditEvent> events = auditService.getAuditEvents();
|
||||
|
||||
System.out.println("Found audit events:");
|
||||
for (AuditEvent event : events)
|
||||
{
|
||||
System.out.println(" - " + event.getName() + " (" + event.getLabel() + ")");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
txnHelper.doInTransaction(updateCallback);
|
||||
}, rmAdminName);
|
||||
}
|
||||
|
||||
public void testSetUp()
|
||||
/**
|
||||
* Test getAuditTrail method and parameter filters.
|
||||
*/
|
||||
public void testGetAuditTrail()
|
||||
{
|
||||
// Just to get get the fileplan set up
|
||||
}
|
||||
// show the audit is empty
|
||||
getAuditTrail(0, rmAdminName);
|
||||
|
||||
public void testQuery_All()
|
||||
{
|
||||
queryAll();
|
||||
}
|
||||
// make a change
|
||||
final String updatedProperty = updateTitle(filePlan, rmAdminName);
|
||||
|
||||
public void testQuery_UserLimited()
|
||||
{
|
||||
// Make sure that something has been done
|
||||
updateFilePlan();
|
||||
// show the audit has been updated
|
||||
List<RecordsManagementAuditEntry> entries = getAuditTrail(1, rmAdminName);
|
||||
final RecordsManagementAuditEntry entry = entries.get(0);
|
||||
assertNotNull(entry);
|
||||
|
||||
final int limit = 1;
|
||||
final String user = AuthenticationUtil.getSystemUserName(); // The user being tested
|
||||
|
||||
RetryingTransactionCallback<List<RecordsManagementAuditEntry>> testCallback =
|
||||
new RetryingTransactionCallback<List<RecordsManagementAuditEntry>>()
|
||||
{
|
||||
public List<RecordsManagementAuditEntry> execute() throws Throwable
|
||||
{
|
||||
RecordsManagementAuditQueryParameters params = new RecordsManagementAuditQueryParameters();
|
||||
params.setUser(user);
|
||||
params.setMaxEntries(limit);
|
||||
List<RecordsManagementAuditEntry> entries = rmAuditService.getAuditTrail(params);
|
||||
return entries;
|
||||
}
|
||||
};
|
||||
List<RecordsManagementAuditEntry> entries = txnHelper.doInTransaction(testCallback);
|
||||
assertNotNull(entries);
|
||||
assertEquals("Expected results to be limited", limit, entries.size());
|
||||
}
|
||||
|
||||
public void testQuery_Node() throws InterruptedException
|
||||
{
|
||||
RetryingTransactionCallback<List<RecordsManagementAuditEntry>> allResultsCallback =
|
||||
new RetryingTransactionCallback<List<RecordsManagementAuditEntry>>()
|
||||
{
|
||||
public List<RecordsManagementAuditEntry> execute() throws Throwable
|
||||
{
|
||||
RecordsManagementAuditQueryParameters params = new RecordsManagementAuditQueryParameters();
|
||||
params.setDateFrom(testStartTime);
|
||||
List<RecordsManagementAuditEntry> entries = rmAuditService.getAuditTrail(params);
|
||||
return entries;
|
||||
}
|
||||
};
|
||||
List<RecordsManagementAuditEntry> entries = txnHelper.doInTransaction(allResultsCallback);
|
||||
assertNotNull("Expect a list of results for the query", entries);
|
||||
|
||||
// Find all results for a given node
|
||||
NodeRef chosenNodeRef = null;
|
||||
int count = 0;
|
||||
for (RecordsManagementAuditEntry entry : entries)
|
||||
{
|
||||
NodeRef nodeRef = entry.getNodeRef();
|
||||
assertNotNull("Found entry with null nodeRef: " + entry, nodeRef);
|
||||
if (chosenNodeRef == null)
|
||||
{
|
||||
chosenNodeRef = nodeRef;
|
||||
count++;
|
||||
}
|
||||
else if (nodeRef.equals(chosenNodeRef))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
final NodeRef chosenNodeRefFinal = chosenNodeRef;
|
||||
// Now search again, but for the chosen node
|
||||
RetryingTransactionCallback<List<RecordsManagementAuditEntry>> nodeResultsCallback =
|
||||
new RetryingTransactionCallback<List<RecordsManagementAuditEntry>>()
|
||||
{
|
||||
public List<RecordsManagementAuditEntry> execute() throws Throwable
|
||||
{
|
||||
RecordsManagementAuditQueryParameters params = new RecordsManagementAuditQueryParameters();
|
||||
params.setDateFrom(testStartTime);
|
||||
params.setNodeRef(chosenNodeRefFinal);
|
||||
List<RecordsManagementAuditEntry> entries = rmAuditService.getAuditTrail(params);
|
||||
return entries;
|
||||
}
|
||||
};
|
||||
entries = txnHelper.doInTransaction(nodeResultsCallback);
|
||||
assertNotNull("Expect a list of results for the query", entries);
|
||||
assertTrue("No results were found for node: " + chosenNodeRefFinal, entries.size() > 0);
|
||||
// We can't check the size because we need entries for the node and any children as well
|
||||
|
||||
Thread.sleep(5000);
|
||||
|
||||
// Clear the log
|
||||
rmAuditService.clear();
|
||||
|
||||
entries = txnHelper.doInTransaction(nodeResultsCallback);
|
||||
assertTrue("Should have cleared all audit entries", entries.isEmpty());
|
||||
|
||||
// Delete the node
|
||||
txnHelper.doInTransaction(new RetryingTransactionCallback<Void>()
|
||||
// investigate the contents of the audit entry
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
public Void run() throws Exception
|
||||
{
|
||||
return AuthenticationUtil.runAs(new RunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
nodeService.deleteNode(chosenNodeRefFinal);
|
||||
assertEquals(filePlan, entry.getNodeRef());
|
||||
|
||||
String id = (String)nodeService.getProperty(filePlan, PROP_IDENTIFIER);
|
||||
assertEquals(id, entry.getIdentifier());
|
||||
|
||||
Map<QName, Serializable> after = entry.getAfterProperties();
|
||||
Map<QName, Pair<Serializable, Serializable>> changed = entry.getChangedProperties();
|
||||
|
||||
assertTrue(after.containsKey(PROP_TITLE));
|
||||
assertTrue(changed.containsKey(PROP_TITLE));
|
||||
|
||||
Serializable value = ((Map<Locale, Serializable>)after.get(PROP_TITLE)).get(Locale.ENGLISH);
|
||||
assertEquals(updatedProperty, value);
|
||||
value = ((Map<Locale, Serializable>)changed.get(PROP_TITLE).getSecond()).get(Locale.ENGLISH);
|
||||
assertEquals(updatedProperty, value);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
});
|
||||
}, rmAdminName);
|
||||
|
||||
Thread.sleep(5000);
|
||||
// add some more title updates
|
||||
updateTitle(rmContainer, rmAdminName);
|
||||
updateTitle(rmFolder, rmAdminName);
|
||||
updateTitle(record, rmAdminName);
|
||||
|
||||
entries = txnHelper.doInTransaction(nodeResultsCallback);
|
||||
assertFalse("Should have recorded node deletion", entries.isEmpty());
|
||||
// show the audit has been updated
|
||||
getAuditTrail(4, rmAdminName);
|
||||
|
||||
// snap shot date
|
||||
Date snapShot = new Date();
|
||||
|
||||
// show the audit results can be limited
|
||||
RecordsManagementAuditQueryParameters params = new RecordsManagementAuditQueryParameters();
|
||||
params.setMaxEntries(2);
|
||||
getAuditTrail(params, 2, rmAdminName);
|
||||
|
||||
// test filter by user
|
||||
updateTitle(rmContainer, recordsManagerName);
|
||||
updateTitle(rmFolder, recordsManagerName);
|
||||
updateTitle(record, recordsManagerName);
|
||||
|
||||
params = new RecordsManagementAuditQueryParameters();
|
||||
params.setUser(recordsManagerName);
|
||||
getAuditTrail(params, 3, rmAdminName);
|
||||
|
||||
// test filter by date
|
||||
params = new RecordsManagementAuditQueryParameters();
|
||||
params.setDateFrom(snapShot);
|
||||
getAuditTrail(params, 3, rmAdminName);
|
||||
params = new RecordsManagementAuditQueryParameters();
|
||||
params.setDateTo(snapShot);
|
||||
getAuditTrail(params, 4, rmAdminName);
|
||||
params.setDateFrom(testStartTime);
|
||||
getAuditTrail(params, 4, rmAdminName);
|
||||
|
||||
// test filter by object
|
||||
updateTitle(record, rmAdminName);
|
||||
updateTitle(record, rmAdminName);
|
||||
updateTitle(record, rmAdminName);
|
||||
params = new RecordsManagementAuditQueryParameters();
|
||||
params.setNodeRef(record);
|
||||
getAuditTrail(params, 5, rmAdminName);
|
||||
|
||||
// test filter by event
|
||||
params = new RecordsManagementAuditQueryParameters();
|
||||
// params.setEvent("cutoff");
|
||||
// getAuditTrail(params, 0, rmAdminName);
|
||||
params.setEvent("Update RM Object");
|
||||
getAuditTrail(params, 10, rmAdminName);
|
||||
|
||||
// test filter by property
|
||||
params = new RecordsManagementAuditQueryParameters();
|
||||
//params.setProperty(PROP_ADDRESSEES);
|
||||
//getAuditTrail(params, 0, rmAdminName);
|
||||
params.setProperty(PROP_TITLE);
|
||||
getAuditTrail(params, 10, rmAdminName);
|
||||
}
|
||||
|
||||
public void testStartStopDelete() throws InterruptedException
|
||||
/**
|
||||
* Tests the following methods:
|
||||
* - start()
|
||||
* - stop()
|
||||
* - clear()
|
||||
* - isEnabled()
|
||||
* - getDateLastStopped()
|
||||
* - getDateLastStarted()
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void testAdminMethods() throws InterruptedException
|
||||
{
|
||||
// Stop the audit
|
||||
rmAuditService.stop();
|
||||
auditService.stop();
|
||||
|
||||
Thread.sleep(5000);
|
||||
|
||||
List<RecordsManagementAuditEntry> result1 = queryAll();
|
||||
List<RecordsManagementAuditEntry> result1 = getAuditTrail(rmAdminName);
|
||||
assertNotNull(result1);
|
||||
|
||||
// Update the fileplan
|
||||
updateFilePlan();
|
||||
updateTitle(filePlan, rmAdminName);
|
||||
|
||||
Thread.sleep(5000);
|
||||
|
||||
// There should be no new audit entries
|
||||
List<RecordsManagementAuditEntry> result2 = queryAll();
|
||||
List<RecordsManagementAuditEntry> result2 = getAuditTrail(rmAdminName);
|
||||
assertNotNull(result2);
|
||||
assertEquals(
|
||||
"Audit results should not have changed after auditing was disabled",
|
||||
result1.size(), result2.size());
|
||||
|
||||
// repeat with a start
|
||||
rmAuditService.start();
|
||||
updateFilePlan();
|
||||
auditService.start();
|
||||
updateTitle(filePlan, rmAdminName);
|
||||
|
||||
Thread.sleep(5000);
|
||||
|
||||
List<RecordsManagementAuditEntry> result3 = queryAll();
|
||||
List<RecordsManagementAuditEntry> result3 = getAuditTrail(rmAdminName);
|
||||
assertNotNull(result3);
|
||||
assertTrue(
|
||||
"Expected more results after enabling audit",
|
||||
@@ -320,25 +307,31 @@ public class RecordsManagementAuditServiceImplTest extends TestCase
|
||||
Thread.sleep(5000);
|
||||
|
||||
// Stop and delete all entries
|
||||
rmAuditService.stop();
|
||||
rmAuditService.clear();
|
||||
auditService.stop();
|
||||
auditService.clear();
|
||||
|
||||
// There should be no entries
|
||||
List<RecordsManagementAuditEntry> result4 = queryAll();
|
||||
List<RecordsManagementAuditEntry> result4 = getAuditTrail(rmAdminName);
|
||||
assertNotNull(result4);
|
||||
assertEquals(
|
||||
"Audit entries should have been cleared",
|
||||
0, result4.size());
|
||||
}
|
||||
|
||||
// TODO testAuditRMAction
|
||||
|
||||
// TODO testGetAuditTrailFile
|
||||
|
||||
// TODO testFileAuditTrailAsRecord
|
||||
|
||||
public void xtestAuditAuthentication()
|
||||
{
|
||||
rmAuditService.stop();
|
||||
rmAuditService.clear();
|
||||
rmAuditService.start();
|
||||
auditService.stop();
|
||||
auditService.clear();
|
||||
auditService.start();
|
||||
|
||||
MutableAuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
|
||||
PersonService personService = serviceRegistry.getPersonService();
|
||||
//MutableAuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
|
||||
//PersonService personService = serviceRegistry.getPersonService();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -365,8 +358,8 @@ public class RecordsManagementAuditServiceImplTest extends TestCase
|
||||
{
|
||||
AuthenticationUtil.popAuthentication();
|
||||
}
|
||||
rmAuditService.stop();
|
||||
List<RecordsManagementAuditEntry> result1 = queryAll();
|
||||
auditService.stop();
|
||||
List<RecordsManagementAuditEntry> result1 = getAuditTrail(rmAdminName);
|
||||
// Check that the username is reflected correctly in the results
|
||||
assertFalse("No audit results were generated for the failed login.", result1.isEmpty());
|
||||
boolean found = false;
|
||||
@@ -398,8 +391,8 @@ public class RecordsManagementAuditServiceImplTest extends TestCase
|
||||
personProperties.put(ContentModel.PROP_LASTNAME, "Dickons");
|
||||
personService.createPerson(personProperties);
|
||||
|
||||
rmAuditService.clear();
|
||||
rmAuditService.start();
|
||||
auditService.clear();
|
||||
auditService.start();
|
||||
try
|
||||
{
|
||||
AuthenticationUtil.pushAuthentication();
|
||||
@@ -409,8 +402,8 @@ public class RecordsManagementAuditServiceImplTest extends TestCase
|
||||
{
|
||||
AuthenticationUtil.popAuthentication();
|
||||
}
|
||||
rmAuditService.stop();
|
||||
List<RecordsManagementAuditEntry> result2 = queryAll();
|
||||
auditService.stop();
|
||||
List<RecordsManagementAuditEntry> result2 = getAuditTrail(rmAdminName);
|
||||
found = false;
|
||||
for (RecordsManagementAuditEntry entry : result2)
|
||||
{
|
||||
@@ -424,4 +417,52 @@ public class RecordsManagementAuditServiceImplTest extends TestCase
|
||||
}
|
||||
assertTrue("Expected to hit successful login attempt for Charles Dickons (cdickons)", found);
|
||||
}
|
||||
|
||||
/** === Helper methods === */
|
||||
|
||||
private List<RecordsManagementAuditEntry> getAuditTrail(String asUser)
|
||||
{
|
||||
return getAuditTrail(-1, asUser);
|
||||
}
|
||||
|
||||
private List<RecordsManagementAuditEntry> getAuditTrail(final int expectedCount, String asUser)
|
||||
{
|
||||
return getAuditTrail(new RecordsManagementAuditQueryParameters(), expectedCount, asUser);
|
||||
}
|
||||
|
||||
private List<RecordsManagementAuditEntry> getAuditTrail(final RecordsManagementAuditQueryParameters params, final int expectedCount, final String asUser)
|
||||
{
|
||||
return doTestInTransaction(new Test<List<RecordsManagementAuditEntry>>()
|
||||
{
|
||||
@Override
|
||||
public List<RecordsManagementAuditEntry> run() throws Exception
|
||||
{
|
||||
return auditService.getAuditTrail(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test(List<RecordsManagementAuditEntry> result) throws Exception
|
||||
{
|
||||
assertNotNull(result);
|
||||
if (expectedCount != -1)
|
||||
{
|
||||
assertEquals(expectedCount, result.size());
|
||||
}
|
||||
}
|
||||
}, asUser);
|
||||
}
|
||||
|
||||
private String updateTitle(final NodeRef nodeRef, final String asUser)
|
||||
{
|
||||
return doTestInTransaction(new Test<String>()
|
||||
{
|
||||
@Override
|
||||
public String run() throws Exception
|
||||
{
|
||||
String updatedProperty = "Updated - " + System.currentTimeMillis();
|
||||
nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, updatedProperty);
|
||||
return updatedProperty;
|
||||
}
|
||||
}, asUser);
|
||||
}
|
||||
}
|
||||
|
@@ -19,17 +19,13 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.action.impl.FreezeAction;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
|
||||
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
|
||||
@@ -39,15 +35,12 @@ import org.alfresco.module.org_alfresco_module_rm.model.RmSiteType;
|
||||
import org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.security.RecordsManagementSecurityService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordService;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
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.StoreRef;
|
||||
@@ -60,6 +53,7 @@ import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.RetryingTransactionHelperTestCase;
|
||||
@@ -106,6 +100,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
|
||||
protected MutableAuthenticationService authenticationService;
|
||||
protected AuthorityService authorityService;
|
||||
protected PersonService personService;
|
||||
protected TransactionService transactionService;
|
||||
|
||||
/** RM Services */
|
||||
protected RecordsManagementService rmService;
|
||||
@@ -259,6 +254,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
|
||||
authorityService = (AuthorityService)this.applicationContext.getBean("AuthorityService");
|
||||
authenticationService = (MutableAuthenticationService)this.applicationContext.getBean("AuthenticationService");
|
||||
personService = (PersonService)this.applicationContext.getBean("PersonService");
|
||||
transactionService = (TransactionService)applicationContext.getBean("TransactionService");
|
||||
|
||||
// Get RM services
|
||||
rmService = (RecordsManagementService)applicationContext.getBean("RecordsManagementService");
|
||||
@@ -462,24 +458,24 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
|
||||
|
||||
// Level 1
|
||||
mhContainer11 = rmService.createRecordCategory(mhContainer, "mhContainer11");
|
||||
mhDispositionSchedule11 = utils.createBasicDispositionSchedule(mhContainer11, "ds11", utils.DEFAULT_DISPOSITION_AUTHORITY, false, true);
|
||||
mhDispositionSchedule11 = utils.createBasicDispositionSchedule(mhContainer11, "ds11", CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, false, true);
|
||||
mhContainer12 = rmService.createRecordCategory(mhContainer, "mhContainer12");
|
||||
mhDispositionSchedule12 = utils.createBasicDispositionSchedule(mhContainer12, "ds12", utils.DEFAULT_DISPOSITION_AUTHORITY, false, true);
|
||||
mhDispositionSchedule12 = utils.createBasicDispositionSchedule(mhContainer12, "ds12", CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, false, true);
|
||||
|
||||
// Level 2
|
||||
mhContainer21 = rmService.createRecordCategory(mhContainer11, "mhContainer21");
|
||||
mhContainer22 = rmService.createRecordCategory(mhContainer12, "mhContainer22");
|
||||
mhContainer23 = rmService.createRecordCategory(mhContainer12, "mhContainer23");
|
||||
mhDispositionSchedule23 = utils.createBasicDispositionSchedule(mhContainer23, "ds23", utils.DEFAULT_DISPOSITION_AUTHORITY, false, true);
|
||||
mhDispositionSchedule23 = utils.createBasicDispositionSchedule(mhContainer23, "ds23", CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, false, true);
|
||||
|
||||
// Level 3
|
||||
mhContainer31 = rmService.createRecordCategory(mhContainer21, "mhContainer31");
|
||||
mhContainer32 = rmService.createRecordCategory(mhContainer22, "mhContainer32");
|
||||
mhContainer33 = rmService.createRecordCategory(mhContainer22, "mhContainer33");
|
||||
mhDispositionSchedule33 = utils.createBasicDispositionSchedule(mhContainer33, "ds33", utils.DEFAULT_DISPOSITION_AUTHORITY, true, true);
|
||||
mhDispositionSchedule33 = utils.createBasicDispositionSchedule(mhContainer33, "ds33", CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, true, true);
|
||||
mhContainer34 = rmService.createRecordCategory(mhContainer23, "mhContainer34");
|
||||
mhContainer35 = rmService.createRecordCategory(mhContainer23, "mhContainer35");
|
||||
mhDispositionSchedule35 = utils.createBasicDispositionSchedule(mhContainer35, "ds35", utils.DEFAULT_DISPOSITION_AUTHORITY, true, true);
|
||||
mhDispositionSchedule35 = utils.createBasicDispositionSchedule(mhContainer35, "ds35", CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, true, true);
|
||||
|
||||
// Record folders
|
||||
mhRecordFolder41 = rmService.createRecordFolder(mhContainer31, "mhFolder41");
|
||||
|
@@ -1048,7 +1048,7 @@ public class RmRestApiTest extends BaseRMWebScriptTestCase implements RecordsMan
|
||||
assertEquals("application/json", rsp.getContentType());
|
||||
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
|
||||
|
||||
checkAuditStatus(false);
|
||||
checkAuditStatus(true);
|
||||
|
||||
// start the RM audit log
|
||||
JSONObject jsonPostData = new JSONObject();
|
||||
|
Reference in New Issue
Block a user