use of org.alfresco.repo.audit.model.AuditApplication in project alfresco-repository by Alfresco.
the class AuditComponentImpl method recordAuditValuesImpl.
/**
* @since 3.2
*/
public Map<String, Serializable> recordAuditValuesImpl(Map<String, Serializable> mappedValues) {
// Group the values by root path
Map<String, Map<String, Serializable>> mappedValuesByRootKey = new HashMap<String, Map<String, Serializable>>();
for (Map.Entry<String, Serializable> entry : mappedValues.entrySet()) {
String path = entry.getKey();
String rootKey = AuditApplication.getRootKey(path);
Map<String, Serializable> rootKeyMappedValues = mappedValuesByRootKey.get(rootKey);
if (rootKeyMappedValues == null) {
rootKeyMappedValues = new HashMap<String, Serializable>(7);
mappedValuesByRootKey.put(rootKey, rootKeyMappedValues);
}
rootKeyMappedValues.put(path, entry.getValue());
}
Map<String, Serializable> allAuditedValues = new HashMap<String, Serializable>(mappedValues.size() * 2 + 1);
// Now audit for each of the root keys
for (Map.Entry<String, Map<String, Serializable>> entry : mappedValuesByRootKey.entrySet()) {
String rootKey = entry.getKey();
Map<String, Serializable> rootKeyMappedValues = entry.getValue();
// Get the application
AuditApplication application = auditModelRegistry.getAuditApplicationByKey(rootKey);
if (application == null) {
// There is no application that uses the root key
logger.debug("There is no application for root key: " + rootKey);
continue;
}
// Get the disabled paths
Set<String> disabledPaths = getDisabledPaths(application);
// Do a quick elimination if the root path is disabled
if (disabledPaths.contains(AuditApplication.buildPath(rootKey))) {
// The root key has been disabled for this application
if (logger.isDebugEnabled()) {
logger.debug("Audit values root path has been excluded by disabled paths: \n" + " Application: " + application + "\n" + " Root Path: " + AuditApplication.buildPath(rootKey));
}
continue;
}
// Do the audit
Map<String, Serializable> rootKeyAuditValues = audit(application, disabledPaths, rootKeyMappedValues);
allAuditedValues.putAll(rootKeyAuditValues);
}
// Done
return allAuditedValues;
}
use of org.alfresco.repo.audit.model.AuditApplication in project alfresco-repository by Alfresco.
the class AuditComponentTest method testApplication.
/**
* Test for MNT-10070 and MNT-14136
*/
public void testApplication() throws Exception {
// Register the test model
URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test-mnt-10070.xml");
auditModelRegistry.registerModel(testModelUrl);
auditModelRegistry.loadAuditModels();
auditModelRegistry.setProperty("audit.enabled", "true");
auditModelRegistry.setProperty("audit.app1.enabled", "true");
auditModelRegistry.setProperty("audit.filter.app1.default.enabled", "true");
auditModelRegistry.setProperty("audit.filter.app1.login.user", "~System;~null;.*");
auditModelRegistry.setProperty("audit.app2.enabled", "true");
auditModelRegistry.setProperty("audit.filter.app2.default.enabled", "true");
auditModelRegistry.setProperty("audit.filter.app2.login.user", "~System;~null;~admin;.*");
auditModelRegistry.setProperty("audit.app3.enabled", "true");
auditModelRegistry.setProperty("audit.filter.app3.default.enabled", "true");
auditModelRegistry.setProperty("audit.filter.app3.login.user", "~System;~null;.*");
auditModelRegistry.afterPropertiesSet();
AuthenticationUtil.setRunAsUserSystem();
AuditApplication applicationOne = auditModelRegistry.getAuditApplicationByName(APPLICATION_ONE);
assertNotNull("Application 'app1' dosn't exist", applicationOne);
AuditApplication applicationTwo = auditModelRegistry.getAuditApplicationByName(APPLICATION_TWO);
assertNotNull("Application 'app2' dosn't exist", applicationTwo);
AuditApplication applicationThree = auditModelRegistry.getAuditApplicationByName(APPLICATION_THREE);
assertNotNull("Application 'app3' dosn't exist", applicationThree);
// auditComponent
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
PropertyAuditFilter filter = new PropertyAuditFilter();
Properties properties = new Properties();
properties.put("audit.enabled", "true");
properties.put("audit.app1.enabled", "true");
properties.put("audit.filter.app1.default.enabled", "true");
properties.put("audit.filter.app1.default.user", "~System;~null;.*");
properties.put("audit.app2.enabled", "true");
properties.put("audit.filter.app2.default.enabled", "true");
properties.put("audit.filter.app2.default.user", "~System;~null;~admin;.*");
properties.put("audit.app3.enabled", "true");
properties.put("audit.filter.app3.default.enabled", "true");
properties.put("audit.filter.app3.default.user", "~System;~null;.*");
filter.setProperties(properties);
auditComponent.setAuditFilter(filter);
Map<String, Serializable> auditMap = new HashMap<String, Serializable>();
auditMap.put("/transaction/user", AuthenticationUtil.getFullyAuthenticatedUser());
auditMap.put("/transaction/action", "CREATE");
auditMap.put("/transaction/type", "cm:content");
Map<String, Serializable> recordedAuditMap = auditComponent.recordAuditValues("/alfresco-access", auditMap);
assertFalse("Audit values is empty.", recordedAuditMap.isEmpty());
Map<String, Serializable> expected = new HashMap<String, Serializable>();
// There should not be app2
expected.put("/" + APPLICATION_ONE + "/transaction/action", "CREATE");
expected.put("/" + APPLICATION_THREE + "/transaction/type", "cm:content");
String failure = EqualsHelper.getMapDifferenceReport(recordedAuditMap, expected);
if (failure != null) {
fail(failure);
}
}
use of org.alfresco.repo.audit.model.AuditApplication in project alfresco-repository by Alfresco.
the class AuditBootstrapTest method testGetApplicationByKey.
public void testGetApplicationByKey() {
AuditApplication app = auditModelRegistry.getAuditApplicationByKey(KEY_TEST);
assertNotNull(app);
}
use of org.alfresco.repo.audit.model.AuditApplication in project alfresco-repository by Alfresco.
the class AuditBootstrapTest method testAuditApplication_Path.
public void testAuditApplication_Path() {
AuditApplication app = auditModelRegistry.getAuditApplicationByName(APPLICATION_TEST);
assertNotNull(app);
// Check that path checks are working
testBadPath(app, null);
testBadPath(app, "");
testBadPath(app, "test");
testBadPath(app, "/Test");
testBadPath(app, "/test/");
}
Aggregations