diff --git a/source/java/org/alfresco/repo/audit/AuditComponent.java b/source/java/org/alfresco/repo/audit/AuditComponent.java index b6c6123f7c..3c742ac2d9 100644 --- a/source/java/org/alfresco/repo/audit/AuditComponent.java +++ b/source/java/org/alfresco/repo/audit/AuditComponent.java @@ -62,15 +62,20 @@ public interface AuditComponent public Map 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 false are: auditing is disabled; no audit applications + * have been registered. Sometimes, depending on the log level, this method may always + * return true. * - * @return Returns true if the given source path is mapped to one or more - * audit applications + * + * @return Returns true 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 diff --git a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java index e63daabd0d..a42db82028 100644 --- a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java +++ b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java @@ -50,19 +50,22 @@ import org.apache.commons.logging.LogFactory; import org.springframework.extensions.surf.util.ParameterCheck; /** - * The default audit component implementation. - * + * To turn on logging of all potentially auditable data, turn on logging for:
+ * {@link #INBOUND_LOGGER org.alfresco.repo.audit.inbound}. *

- * 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} + *

+ * Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then true + * 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 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(); } diff --git a/source/java/org/alfresco/repo/audit/AuditMethodInterceptor.java b/source/java/org/alfresco/repo/audit/AuditMethodInterceptor.java index 0310bc7130..b867dffdf3 100644 --- a/source/java/org/alfresco/repo/audit/AuditMethodInterceptor.java +++ b/source/java/org/alfresco/repo/audit/AuditMethodInterceptor.java @@ -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) { diff --git a/source/java/org/alfresco/repo/node/NodeAuditor.java b/source/java/org/alfresco/repo/node/NodeAuditor.java index 7ac10fef92..97b7be0169 100644 --- a/source/java/org/alfresco/repo/node/NodeAuditor.java +++ b/source/java/org/alfresco/repo/node/NodeAuditor.java @@ -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; }