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());
}
}

View File

@@ -18,16 +18,14 @@
*/
package org.alfresco.repo.audit;
import java.io.Serializable;
import org.alfresco.service.cmr.audit.AuditQueryParameters;
import org.alfresco.service.cmr.audit.AuditService;
import org.springframework.extensions.surf.util.ParameterCheck;
/**
* The implementation of the AuditService for application auditing.
*
* @author Andy Hind
* @author Derek Hulley
* @since 3.2
*/
public class AuditServiceImpl implements AuditService
{
@@ -43,6 +41,15 @@ public class AuditServiceImpl implements AuditService
this.auditComponent = auditComponent;
}
/**
* {@inheritDoc}
* @since 3.4
*/
public boolean isAuditEnabled()
{
return auditComponent.isAuditEnabled();
}
/**
* {@inheritDoc}
* @since 3.2
@@ -89,55 +96,4 @@ public class AuditServiceImpl implements AuditService
{
auditComponent.auditQuery(callback, parameters, maxResults);
}
/**
* {@inheritDoc}
* @since 3.2
*/
public void auditQuery(
AuditQueryCallback callback,
boolean forward,
String applicationName, String user, Long from, Long to,
int maxResults)
{
ParameterCheck.mandatory("callback", callback);
AuditQueryParameters params = new AuditQueryParameters();
params.setForward(true);
params.setApplicationName(applicationName);
params.setUser(user);
params.setFromTime(from);
params.setToTime(to);
auditComponent.auditQuery(callback, params, maxResults);
}
/**
* {@inheritDoc}
* @since 3.2
*/
public void auditQuery(
AuditQueryCallback callback,
boolean forward,
String applicationName, String user, Long from, Long to,
String searchKey, Serializable searchValue,
int maxResults)
{
ParameterCheck.mandatory("callback", callback);
AuditQueryParameters params = new AuditQueryParameters();
params.setForward(true);
params.setApplicationName(applicationName);
params.setUser(user);
params.setFromTime(from);
params.setToTime(to);
if (searchKey != null || searchValue != null)
{
params.addSearchKey(searchKey, searchValue);
}
auditComponent.auditQuery(callback, params, maxResults);
}
}

View File

@@ -31,6 +31,13 @@ import org.alfresco.service.PublicService;
@PublicService
public interface AuditService
{
/**
* @return Returns <tt>true</tt> if auditing is globally enabled
*
* @since 3.4
*/
boolean isAuditEnabled();
/**
* @param applicationName the name of the application to check
* @param path the path to check
@@ -122,49 +129,4 @@ public interface AuditService
* @since 3.3
*/
void auditQuery(AuditQueryCallback callback, AuditQueryParameters parameters, int maxResults);
/**
* Get the audit entries that match the given criteria.
*
* @param callback the callback that will handle results
* @param forward <tt>true</tt> for results to ordered from first to last,
* or <tt>false</tt> to order from last to first
* @param applicationName if not <tt>null</tt>, find entries logged against this application
* @param user if not <tt>null</tt>, find entries logged against this user
* @param from the start search time (<tt>null</tt> to start at the beginning)
* @param to the end search time (<tt>null</tt> for no limit)
* @param maxResults the maximum number of results to retrieve (zero or negative to ignore)
*
* @since 3.2
* @deprecated Use {@link #auditQuery(AuditQueryCallback, AuditQueryParameters)}
*/
void auditQuery(
AuditQueryCallback callback,
boolean forward,
String applicationName, String user, Long from, Long to,
int maxResults);
/**
* Get the audit entries that match the given criteria.
*
* @param callback the callback that will handle results
* @param forward <tt>true</tt> for results to ordered from first to last,
* or <tt>false</tt> to order from last to first
* @param applicationName if not <tt>null</tt>, find entries logged against this application
* @param user if not <tt>null</tt>, find entries logged against this user
* @param from the start search time (<tt>null</tt> to start at the beginning)
* @param to the end search time (<tt>null</tt> for no limit)
* @param searchKey the audit key path that must exist (<tt>null</tt> to ignore)
* @param searchValue an audit value that must exist (<tt>null</tt> to ignore)
* @param maxResults the maximum number of results to retrieve (zero or negative to ignore)
*
* @since 3.2
* @deprecated Use {@link #auditQuery(AuditQueryCallback, AuditQueryParameters)}
*/
void auditQuery(
AuditQueryCallback callback,
boolean forward,
String applicationName, String user, Long from, Long to,
String searchKey, Serializable searchValue,
int maxResults);
}