ALF-4106 AuditService enhancements and fixes

- Enabling DEBUG logging for 'org.alfresco.repo.audit.inbound' will dump all auditable data
 - Fixed values output so that Serializable map entries are converted to Strings
 - Made plain the pre-audit client check (i.e. it doesn't need a path for checking)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22203 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-09-02 20:15:36 +00:00
parent 66486c56c3
commit ae3044bb7f
4 changed files with 47 additions and 25 deletions

View File

@@ -62,15 +62,20 @@ public interface AuditComponent
public Map<String, AuditApplication> getAuditApplications();
/**
* Determines whether the given source path is mapped to any audit applications. Allows optimizations to be made in
* calling components.
* Determine whether the audit infrastructure expects audit values to be passed in.
* This is a helper method to allow optimizations in the client code. Reasons why
* this method might return <tt>false</tt> are: auditing is disabled; no audit applications
* have been registered. Sometimes, depending on the log level, this method may always
* return <tt>true</tt>.
*
* @return Returns <code>true</code> if the given source path is mapped to one or more
* audit applications
*
* @return Returns <code>true</code> if the calling code (data producers)
* should go ahead and generate the data for
* {@link #recordAuditValues(String, Map) recording}.
*
* @since 3.3
*/
public boolean isSourcePathMapped(String sourcePath);
public boolean areAuditValuesRequired();
/**
* Delete audit entries for the given application and time range

View File

@@ -50,19 +50,22 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.ParameterCheck;
/**
* The default audit component implementation.
* <TODO: Implement before, after and exception filtering. At the moment
* these filters are ignored. TODO: Respect audit internal - at the moment audit internal is fixed to false.
* Component that records audit values as well as providing the query implementation.
* <p>
* To turn on logging of all <i>potentially auditable</i> data, turn on logging for:<br/>
* <strong>{@link #INBOUND_LOGGER org.alfresco.repo.audit.inbound}</strong>.
* <p/>
* The V3.2 audit functionality is contained within the same component. When the newer audit
* implementation has been tested and approved, then older ones will be deprecated as necessary.
* TODO: Respect audit internal - at the moment audit internal is fixed to false.
*
* @author Andy Hind
* @author Derek Hulley
* @since 3.2 (in its current form)
*/
public class AuditComponentImpl implements AuditComponent
{
private static final String INBOUND_LOGGER = "org.alfresco.repo.audit.inbound";
private static Log logger = LogFactory.getLog(AuditComponentImpl.class);
private static Log loggerInbound = LogFactory.getLog(INBOUND_LOGGER);
private AuditModelRegistryImpl auditModelRegistry;
private PropertyValueDAO propertyValueDAO;
@@ -203,11 +206,17 @@ public class AuditComponentImpl implements AuditComponent
/**
* {@inheritDoc}
* <p/>
* Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt>
* will always be returned.
*
* @since 3.2
*/
public boolean isSourcePathMapped(String sourcePath)
public boolean areAuditValuesRequired()
{
return isAuditEnabled() && !auditModelRegistry.getAuditPathMapper().isEmpty();
return
(loggerInbound.isDebugEnabled()) ||
(isAuditEnabled() && !auditModelRegistry.getAuditPathMapper().isEmpty());
}
/**
@@ -438,8 +447,24 @@ public class AuditComponentImpl implements AuditComponent
{
ParameterCheck.mandatory("rootPath", rootPath);
AuditApplication.checkPathFormat(rootPath);
// Log inbound values
if (loggerInbound.isDebugEnabled())
{
StringBuilder sb = new StringBuilder(values.size()*64);
sb.append("\n")
.append("Inbound audit values:");
for (Map.Entry<String, Serializable> entry : values.entrySet())
{
String pathElement = entry.getKey();
String path = AuditApplication.buildPath(rootPath, pathElement);
Serializable value = entry.getValue();
sb.append("\n\t").append(path).append("=").append(value);
}
loggerInbound.debug(sb.toString());
}
if (values == null || values.isEmpty() || !isSourcePathMapped(rootPath))
if (values == null || values.isEmpty() || !areAuditValuesRequired())
{
return Collections.emptyMap();
}

View File

@@ -126,14 +126,14 @@ public class AuditMethodInterceptor implements MethodInterceptor
public Object invoke(MethodInvocation mi) throws Throwable
{
if(!auditComponent.isAuditEnabled())
if(!auditComponent.areAuditValuesRequired())
{
// No auditing
return mi.proceed();
}
else
{
// New configuration will be used and optionally old configuration if useNewConfig=false
// New configuration will be used
return proceed(mi);
}
}
@@ -160,14 +160,6 @@ public class AuditMethodInterceptor implements MethodInterceptor
return mi.proceed();
}
// If there are no mapped paths, there is nothing to do
if (!this.auditComponent.isSourcePathMapped(AUDIT_PATH_API_ROOT))
{
// We can ignore the rest of the stack too
inAudit.set(Boolean.TRUE);
return mi.proceed();
}
Auditable auditableDef = mi.getMethod().getAnnotation(Auditable.class);
if (auditableDef == null)
{

View File

@@ -94,7 +94,7 @@ public class NodeAuditor implements InitializingBean, NodeServicePolicies.Before
{
// Only continue if there is something listening for our events (note this may change depending on audit
// subsystem configuration)
if (!auditComponent.isSourcePathMapped(BEFORE_DELETE_NODE_PATH))
if (!auditComponent.areAuditValuesRequired())
{
return;
}