SAIL-240 (SAIL-294) AuditDAO: AuditService enhancements

- Added isAuditEnabled and enableAudit for global case (system-wide)
 - Some neatening up of Audit SQL (common WHERE and ORDER BY clauses)
 - AuditService enforces 'admin' role for all methods


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21471 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-07-28 17:40:17 +00:00
parent 67fc407496
commit 44e18c2d81
5 changed files with 111 additions and 176 deletions

View File

@@ -512,10 +512,10 @@ public class AuditComponentTest extends TestCase
}
};
auditService.clearAudit(APPLICATION_API_TEST);
clearAuditLog(APPLICATION_API_TEST);
results.clear();
sb.delete(0, sb.length());
auditService.auditQuery(auditQueryCallback, params, -1);
queryAuditLog(auditQueryCallback, params, -1);
logger.debug(sb.toString());
assertTrue("There should be no audit entries for the API test after a clear", results.isEmpty());
@@ -535,7 +535,7 @@ public class AuditComponentTest extends TestCase
AuthenticationUtil.runAs(createAuthenticationWork, AuthenticationUtil.getSystemUserName());
// Clear everything out and do a successful authentication
auditService.clearAudit(APPLICATION_API_TEST);
clearAuditLog(APPLICATION_API_TEST);
try
{
AuthenticationUtil.pushAuthentication();
@@ -549,12 +549,12 @@ public class AuditComponentTest extends TestCase
// Check that the call was audited
results.clear();
sb.delete(0, sb.length());
auditService.auditQuery(auditQueryCallback, params, -1);
queryAuditLog(auditQueryCallback, params, -1);
logger.debug(sb.toString());
assertFalse("Did not get any audit results after successful login", results.isEmpty());
// Clear everything and check that unsuccessful authentication was audited
auditService.clearAudit(APPLICATION_API_TEST);
clearAuditLog(APPLICATION_API_TEST);
try
{
authenticationService.authenticate("banana", "****".toCharArray());
@@ -566,7 +566,7 @@ public class AuditComponentTest extends TestCase
}
results.clear();
sb.delete(0, sb.length());
auditService.auditQuery(auditQueryCallback, params, -1);
queryAuditLog(auditQueryCallback, params, -1);
logger.debug(sb.toString());
assertFalse("Did not get any audit results after failed login", results.isEmpty());
}
@@ -606,7 +606,40 @@ public class AuditComponentTest extends TestCase
params.setApplicationName(APPLICATION_API_TEST);
params.setForward(false);
params.setToId(Long.MAX_VALUE);
auditService.auditQuery(auditQueryCallback, params, 1);
queryAuditLog(auditQueryCallback, params, 1);
}
/**
* Clearn the audit log as 'admin'
*/
private void clearAuditLog(final String applicationName)
{
RunAsWork<Void> work = new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
auditService.clearAudit(applicationName);
return null;
}
};
AuthenticationUtil.runAs(work, AuthenticationUtil.getAdminRoleName());
}
/**
* Clearn the audit log as 'admin'
*/
private void queryAuditLog(final AuditQueryCallback callback, final AuditQueryParameters parameters, final int maxResults)
{
RunAsWork<Void> work = new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
auditService.auditQuery(callback, parameters, maxResults);
return null;
}
};
AuthenticationUtil.runAs(work, AuthenticationUtil.getAdminRoleName());
}
}