ALF-4106 (ALF-4103): AuditService REST API

- Full start/stop/status using WebScripts
 - AuditService API additions to support
 - .ftl to generate json response
 - Some javadoc and debug additions


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21802 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-08-14 20:42:26 +00:00
parent 370e88e732
commit 6f8af6485f
7 changed files with 85 additions and 42 deletions

View File

@@ -9,43 +9,33 @@
>
<DataExtractors>
<DataExtractor name="simpleValue" class="org.alfresco.repo.audit.extractor.SimpleValueDataExtractor"/>
<!--
<DataExtractor name="stackTrace" class="org.alfresco.repo.audit.extractor.StackTraceDataExtractor"/>
<DataExtractor name="storeRootNode" class="org.alfresco.repo.audit.extractor.StoreRootNodeDataExtractor"/>
-->
<DataExtractor name="simpleValue" registeredName="auditModel.extractor.simpleValue"/>
<DataExtractor name="nullValue" registeredName="auditModel.extractor.nullValue"/>
</DataExtractors>
<DataGenerators>
<DataGenerator name="transactionId" class="org.alfresco.repo.audit.generator.TransactionIdDataGenerator"/>
<DataGenerator name="personFullName" registeredName="auditModel.generator.personFullName"/>
</DataGenerators>
<PathMappings>
<PathMap source="/repository" target="/repository"/>
<PathMap source="/alfresco-api/post/AuthenticationService/authenticate" target="/repository/login"/>
</PathMappings>
<Application name="Alfresco Repository" key="repository">
<AuditPath key="services">
<GenerateValue key="txn" dataGenerator="transactionId"/>
<AuditPath key="nodeservice">
<AuditPath key="createstore">
<AuditPath key="protocol">
<RecordValue key="value" dataExtractor="simpleValue"/>
</AuditPath>
<AuditPath key="identifier">
<RecordValue key="value" dataExtractor="simpleValue"/>
</AuditPath>
<AuditPath key="return">
<RecordValue key="value" dataExtractor="simpleValue"/>
<!--
<RecordValue key="root-node" dataExtractor="storeRootNode"/>
</AuditPath>
<AuditPath key="error">
<RecordValue key="value" dataExtractor="stackTrace"/>
-->
</AuditPath>
<Application name="AlfrescoRepository" key="repository">
<AuditPath key="login">
<AuditPath key="args">
<AuditPath key="userName">
<RecordValue key="value" dataExtractor="simpleValue"/>
</AuditPath>
</AuditPath>
<!--
<AuditPath key="no-error">
<GenerateValue key="fullName" dataGenerator="personFullName"/>
</AuditPath>
-->
<AuditPath key="error">
<RecordValue key="value" dataExtractor="nullValue"/>
</AuditPath>
</AuditPath>
</Application>

View File

@@ -20,7 +20,6 @@ package org.alfresco.repo.audit;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.audit.model.AuditApplication;
import org.alfresco.repo.audit.model.AuditModelRegistry;
@@ -56,11 +55,11 @@ public interface AuditComponent
/**
* Get all registered audit applications, whether active or not.
*
* @return Returns a set of registered audit applications
* @return Returns a map of registered audit applications keyed by name
*
* @since 3.4
*/
public Set<String> getAuditApplications();
public Map<String, AuditApplication> getAuditApplications();
/**
* Determines whether the given source path is mapped to any audit applications. Allows optimizations to be made in

View File

@@ -48,7 +48,8 @@ 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
* 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.
* <p/>
* The V3.2 audit functionality is contained within the same component. When the newer audit
@@ -190,10 +191,9 @@ public class AuditComponentImpl implements AuditComponent
* {@inheritDoc}
* @since 3.4
*/
public Set<String> getAuditApplications()
public Map<String, AuditApplication> getAuditApplications()
{
Map<String, AuditApplication> auditApps = auditModelRegistry.getAuditApplications();
return auditApps.keySet();
return auditModelRegistry.getAuditApplications();
}
/**

View File

@@ -18,7 +18,8 @@
*/
package org.alfresco.repo.audit;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.audit.AuditQueryParameters;
import org.alfresco.service.cmr.audit.AuditService;
@@ -67,9 +68,20 @@ public class AuditServiceImpl implements AuditService
* @since 3.4
*/
@Override
public Set<String> getAuditApplications()
public Map<String, AuditApplication> getAuditApplications()
{
return auditComponent.getAuditApplications();
Map<String, org.alfresco.repo.audit.model.AuditApplication> apps = auditComponent.getAuditApplications();
Map<String, AuditApplication> ret = new HashMap<String, AuditApplication>(apps.size() * 2);
for (String app : apps.keySet())
{
String name = app;
String key = org.alfresco.repo.audit.model.AuditApplication.AUDIT_PATH_SEPARATOR + apps.get(app).getApplicationKey();
boolean enabled = auditComponent.isAuditPathEnabled(app, key);
AuditApplication auditApplication = new AuditApplication(name, key, enabled);
ret.put(name, auditApplication);
}
return ret;
}
/**

View File

@@ -199,11 +199,12 @@ public class AuditApplication
{
if (path == null || path.length() == 0)
{
throw new AuditModelException("Empty or null audit path");
throw new AuditModelException("Empty or null audit path: " + path);
}
else if (!path.matches(AUDIT_PATH_REGEX))
{
throw new AuditModelException("An audit must match regular expression: " + AUDIT_PATH_REGEX);
throw new AuditModelException(
"Audit path '" + path + "' does not match regular expression: " + AUDIT_PATH_REGEX);
}
}

View File

@@ -37,6 +37,14 @@ import org.alfresco.util.PropertyCheck;
* A listener that ensures that an event is audited for every deleted node in a tree of nodes, not just the top one
* captured by {@link AuditMethodInterceptor}!
*
* The values passed to the audit component are:
* <pre>
* /alfresco-node
* /beforeDeleteNode
* /node=&lt;nodeRef&gt;
*
* </pre>
*
* @author dward
*/
public class NodeAuditor implements InitializingBean, NodeServicePolicies.BeforeDeleteNodePolicy

View File

@@ -20,7 +20,6 @@ package org.alfresco.service.cmr.audit;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
import org.alfresco.service.PublicService;
@@ -48,14 +47,48 @@ public interface AuditService
*/
void setAuditEnabled(boolean enable);
/**
* Helper bean to carry information about an audit application.
*
* @author Derek Hulley
* @since 3.4
*/
public static class AuditApplication
{
private final String name;
private final String key;
private final boolean enabled;
/**
* Constructor for final variables
*/
public AuditApplication(String name, String key, boolean enabled)
{
this.name = name;
this.key = key;
this.enabled = enabled;
}
public String getName()
{
return name;
}
public String getKey()
{
return key;
}
public boolean isEnabled()
{
return enabled;
}
}
/**
* Get all registered audit applications
*
* @return Returns a set of all available audit applications
* @return Returns a map of audit applications keyed by their name
*
* @since 3.4
*/
Set<String> getAuditApplications();
Map<String, AuditApplication> getAuditApplications();
/**
* @param applicationName the name of the application to check