use of org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditEntry in project records-management by Alfresco.
the class RecordsManagementAuditServiceImplTest method xtestAuditAuthentication.
// TODO testAuditRMAction
// TODO testGetAuditTrailFile
// TODO testFileAuditTrailAsRecord
public void xtestAuditAuthentication() {
rmAuditService.stopAuditLog(filePlan);
rmAuditService.clearAuditLog(filePlan);
rmAuditService.startAuditLog(filePlan);
try {
personService.deletePerson("baboon");
authenticationService.deleteAuthentication("baboon");
} catch (Throwable e) {
// Not serious
}
// Failed login attempt ...
try {
AuthenticationUtil.pushAuthentication();
authenticationService.authenticate("baboon", "lskdfj".toCharArray());
fail("Expected authentication failure");
} catch (AuthenticationException e) {
// Good
} finally {
AuthenticationUtil.popAuthentication();
}
rmAuditService.stopAuditLog(filePlan);
List<RecordsManagementAuditEntry> result1 = getAuditTrail(ADMIN_USER);
// 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;
for (RecordsManagementAuditEntry entry : result1) {
String userName = entry.getUserName();
if (userName.equals("baboon")) {
found = true;
break;
}
}
assertTrue("Expected to hit failed login attempt for user", found);
// Test successful authentication
try {
personService.deletePerson("cdickons");
authenticationService.deleteAuthentication("cdickons");
} catch (Throwable e) {
// Not serious
}
authenticationService.createAuthentication("cdickons", getName().toCharArray());
Map<QName, Serializable> personProperties = new HashMap<QName, Serializable>();
personProperties.put(ContentModel.PROP_USERNAME, "cdickons");
personProperties.put(ContentModel.PROP_FIRSTNAME, "Charles");
personProperties.put(ContentModel.PROP_LASTNAME, "Dickons");
personService.createPerson(personProperties);
rmAuditService.clearAuditLog(filePlan);
rmAuditService.startAuditLog(filePlan);
try {
AuthenticationUtil.pushAuthentication();
authenticationService.authenticate("cdickons", getName().toCharArray());
} finally {
AuthenticationUtil.popAuthentication();
}
rmAuditService.stopAuditLog(filePlan);
List<RecordsManagementAuditEntry> result2 = getAuditTrail(ADMIN_USER);
found = false;
for (RecordsManagementAuditEntry entry : result2) {
String userName = entry.getUserName();
String fullName = entry.getFullName();
if (userName.equals("cdickons") && EqualsHelper.nullSafeEquals(fullName, "Charles Dickons")) {
found = true;
break;
}
}
assertTrue("Expected to hit successful login attempt for Charles Dickons (cdickons)", found);
}
use of org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditEntry in project records-management by Alfresco.
the class RecordsManagementAuditServiceImplTest method testGetAuditTrail.
/**
* Test getAuditTrail method and parameter filters.
*/
public void testGetAuditTrail() {
// show the audit is empty
getAuditTrail(1, ADMIN_USER);
// make a change
final String updatedProperty = updateTitle(filePlan, ADMIN_USER);
// show the audit has been updated
List<RecordsManagementAuditEntry> entries = getAuditTrail(3, ADMIN_USER);
final RecordsManagementAuditEntry entry = entries.get(0);
assertNotNull(entry);
// investigate the contents of the audit entry
doTestInTransaction(new Test<Void>() {
@SuppressWarnings("unchecked")
@Override
public Void run() throws Exception {
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;
}
}, ADMIN_USER);
// add some more title updates
updateTitle(rmContainer, ADMIN_USER);
updateTitle(rmFolder, ADMIN_USER);
updateTitle(record, ADMIN_USER);
// show the audit has been updated
getAuditTrail(7, ADMIN_USER);
// snap shot date
Date snapShot = new Date();
// show the audit results can be limited
RecordsManagementAuditQueryParameters params = new RecordsManagementAuditQueryParameters();
params.setMaxEntries(2);
getAuditTrail(params, 2, ADMIN_USER);
// test filter by user
updateTitle(rmContainer, recordsManagerName);
updateTitle(rmFolder, recordsManagerName);
updateTitle(record, recordsManagerName);
params = new RecordsManagementAuditQueryParameters();
params.setUser(recordsManagerName);
getAuditTrail(params, 3, ADMIN_USER);
// test filter by date
params = new RecordsManagementAuditQueryParameters();
params.setDateFrom(snapShot);
getAuditTrail(params, 13, ADMIN_USER);
params = new RecordsManagementAuditQueryParameters();
params.setDateTo(snapShot);
getAuditTrail(params, 14, ADMIN_USER);
params.setDateFrom(testStartTime);
getAuditTrail(params, 15, ADMIN_USER);
// test filter by object
updateTitle(record, ADMIN_USER);
updateTitle(record, ADMIN_USER);
updateTitle(record, ADMIN_USER);
params = new RecordsManagementAuditQueryParameters();
params.setNodeRef(record);
getAuditTrail(params, 5, ADMIN_USER);
// test filter by event
params = new RecordsManagementAuditQueryParameters();
// params.setEvent("cutoff");
// getAuditTrail(params, 0, ADMIN_USER);
params.setEvent("Update RM Object");
getAuditTrail(params, 10, ADMIN_USER);
// test filter by property
// params = new RecordsManagementAuditQueryParameters();
// params.setProperty(PROP_ADDRESSEES);
// getAuditTrail(params, 0, ADMIN_USER);
// params.setProperty(PROP_TITLE);
// getAuditTrail(params, 10, ADMIN_USER);
}
Aggregations