ALF-4106 (ALF-4103): AuditService enhancements

- Additional methods to get all available applications
 - Web Script retrieval of applications and enabled/disabled states
 - Tests


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21485 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-07-29 12:15:27 +00:00
parent 77967ef61b
commit 73bdab1db9
7 changed files with 154 additions and 97 deletions

View File

@@ -130,6 +130,12 @@ public class AuditBootstrapTest extends TestCase
assertNotNull("No audit application ID for " + APPLICATION_TEST, appId);
}
public void testGetApplications()
{
Map<String, AuditApplication> apps = auditModelRegistry.getAuditApplications();
assertTrue("Application map not complete", apps.containsKey(APPLICATION_TEST));
}
public void testGetApplicationByKey()
{
AuditApplication app = auditModelRegistry.getAuditApplicationByKey(KEY_TEST);

View File

@@ -20,6 +20,7 @@ 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;
@@ -29,19 +30,26 @@ import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback;
/**
* The audit component. Used by the AuditService and AuditMethodInterceptor to insert audit entries.
* <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.
*
* @author Andy Hind
* @author Derek Hulley
*/
public interface AuditComponent
{
/**
* Get all registered audit applications, whether active or not.
*
* @return Returns a set of registered audit applications
*
* @since 3.4
*/
public Set<String> getAuditApplications();
/**
* Determines whether audit is globally enabled or disabled.
*
* @return <code>true</code>, if audit is enabled
* @return Returns <code>true</code> if audit is enabled
*
* @since 3.3
*/
public boolean isAuditEnabled();
@@ -49,7 +57,9 @@ public interface AuditComponent
* Determines whether the given source path is mapped to any audit applications. Allows optimizations to be made in
* calling components.
*
* @return <code>true</code> if the given source path is mapped to one or more audit applications
* @return Returns <code>true</code> if the given source path is mapped to one or more
* audit applications
*
* @since 3.3
*/
public boolean isSourcePathMapped(String sourcePath);
@@ -114,7 +124,7 @@ public interface AuditComponent
* Remove all disabled paths i.e. enable all per-path based auditing. Auditing may still be
* disabled globally. This is primarily for test purposes; applications should know which
* paths need {@link #enableAudit(String, String) enabling} or
* {@link #disableAudit(String, String) disabling}.
* {@link #disableAudit(String, String) disabled}.
*
* @param applicationName the name of the application
*
@@ -125,7 +135,7 @@ public interface AuditComponent
/**
* Create an audit entry for the given map of values. The map key is a path - starting with '/'
* ({@link AuditApplication#AUDIT_PATH_SEPARATOR}) - relative to the root path provided.
*
* <p/>
* The root path and value keys are combined to produce a map of data keyed by full path. This
* fully-pathed map is then passed through the
* {@link AuditModelRegistry#getAuditPathMapper() audit path mapper}. The result may yield data
@@ -145,7 +155,7 @@ public interface AuditComponent
* @param values the values to audit mapped by {@link AuditPath} key relative to root path
* (may be <tt>null</tt>)
* @return Returns the values that were actually persisted, keyed by their full path.
* @throws IllegalStateException if there is not a writable transaction present
* @throws IllegalStateException if the transaction state could not be determined
*
* @since 3.2
*/

View File

@@ -157,6 +157,16 @@ public class AuditComponentImpl implements AuditComponent
}
}
/**
* {@inheritDoc}
* @since 3.4
*/
public Set<String> getAuditApplications()
{
Map<String, AuditApplication> auditApps = auditModelRegistry.getAuditApplications();
return auditApps.keySet();
}
/**
* {@inheritDoc}
* @since 3.2
@@ -199,7 +209,7 @@ public class AuditComponentImpl implements AuditComponent
Set<String> disabledPaths = getDisabledPaths(application);
// Check if there are any entries that match or superced the given path
// Check if there are any entries that match or supercede the given path
String disablingPath = null;;
for (String disabledPath : disabledPaths)
{

View File

@@ -18,6 +18,8 @@
*/
package org.alfresco.repo.audit;
import java.util.Set;
import org.alfresco.service.cmr.audit.AuditQueryParameters;
import org.alfresco.service.cmr.audit.AuditService;
@@ -41,6 +43,16 @@ public class AuditServiceImpl implements AuditService
this.auditComponent = auditComponent;
}
/**
* {@inheritDoc}
* @since 3.4
*/
@Override
public Set<String> getAuditApplications()
{
return auditComponent.getAuditApplications();
}
/**
* {@inheritDoc}
* @since 3.4

View File

@@ -18,6 +18,8 @@
*/
package org.alfresco.repo.audit.model;
import java.util.Map;
import org.alfresco.util.PathMapper;
/**
@@ -43,9 +45,18 @@ public interface AuditModelRegistry
/**
* Determines whether audit is globally enabled or disabled.
*
* @return <code>true</code>, if audit is enabled
* @return <code>true</code> if audit is enabled
*/
public boolean isAuditEnabled();
/**
* Get a map of all audit applications key by name
*
* @return the audit applications
*
* @since 3.4
*/
public Map<String, AuditApplication> getAuditApplications();
/**
* Get the application model for the given root key (as defined on the application)
@@ -65,7 +76,7 @@ public interface AuditModelRegistry
/**
* Get the path mapper.
* @return the path mapper
* @return the path mapper
*/
public PathMapper getAuditPathMapper();
}

View File

@@ -90,6 +90,54 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
private NamedObjectRegistry<DataGenerator> dataGenerators;
private final ObjectFactory objectFactory;
/**
* Default constructor.
*/
public AuditModelRegistryImpl()
{
objectFactory = new ObjectFactory();
}
/**
* Sets the search path for config files.
*/
public void setSearchPath(String[] searchPath)
{
this.searchPath = searchPath;
}
/**
* Service to ensure DAO calls are transactionally wrapped.
*/
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
/**
* Set the DAO used to persisted the registered audit models.
*/
public void setAuditDAO(AuditDAO auditDAO)
{
this.auditDAO = auditDAO;
}
/**
* Set the registry of {@link DataExtractor data extractors}.
*/
public void setDataExtractors(NamedObjectRegistry<DataExtractor> dataExtractors)
{
this.dataExtractors = dataExtractors;
}
/**
* Set the registry of {@link DataGenerator data generators}.
*/
public void setDataGenerators(NamedObjectRegistry<DataGenerator> dataGenerators)
{
this.dataGenerators = dataGenerators;
}
/**
* {@inheritDoc}
*/
@@ -116,6 +164,16 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
/**
* {@inheritDoc}
*/
@Override
public Map<String, AuditApplication> getAuditApplications()
{
return getState(true).getAuditApplications();
}
/**
* {@inheritDoc}
*/
@Override
public AuditApplication getAuditApplicationByKey(String key)
{
return getState(true).getAuditApplicationByKey(key);
@@ -124,6 +182,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
/**
* {@inheritDoc}
*/
@Override
public AuditApplication getAuditApplicationByName(String applicationName)
{
return getState(true).getAuditApplicationByName(applicationName);
@@ -132,6 +191,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
/**
* {@inheritDoc}
*/
@Override
public PathMapper getAuditPathMapper()
{
return getState(true).getAuditPathMapper();
@@ -140,6 +200,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
/**
* {@inheritDoc}
*/
@Override
public void loadAuditModels()
{
stop();
@@ -149,6 +210,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
/**
* {@inheritDoc}
*/
@Override
public boolean isAuditEnabled()
{
String value = getProperty(PROPERTY_AUDIT_ENABLED);
@@ -159,8 +221,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
* Enables audit and registers an audit model at a given URL. Does not register across the cluster and should only
* be used for unit test purposes.
*
* @param auditModelUrl
* the source of the model
* @param auditModelUrl the source of the model
*/
public synchronized void registerModel(URL auditModelUrl)
{
@@ -176,20 +237,15 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
{
/** The audit models. */
private final Map<URL, Audit> auditModels;
/** Used to lookup path translations. */
private PathMapper auditPathMapper;
/** Used to lookup the audit application java hierarchy. */
private Map<String, AuditApplication> auditApplicationsByKey;
/** Used to lookup the audit application java hierarchy. */
private Map<String, AuditApplication> auditApplicationsByName;
/** The exposed configuration properties. */
private final Map<String, Boolean> properties;
/**
* Instantiates a new audit model registry state.
*/
@@ -220,8 +276,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
/**
* Register an audit model at a given URL.
*
* @param auditModelUrl
* the source of the model
* @param auditModelUrl the source of the model
*/
public void registerModel(URL auditModelUrl)
{
@@ -250,11 +305,11 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
}
/**
* Gets the name of an enablement property.
* Helper method to convert an application key into a <b>enabled-disabled</b> property.
*
* @param key
* an application key
* @return the property name
* @param key an application key e.g. for "My App" the key might be "myapp",
* but is defined in the audit model config.
* @return the property name of the for "audit.myapp.enabled"
*/
private String getEnabledProperty(String key)
{
@@ -262,11 +317,12 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
}
/**
* Checks if an application enabled.
* Checks if an application key is enabled. Each application has a name and a root key
* value. It is the key (which will be used as the root of all logged paths) that is
* used here.
*
* @param key
* the application key
* @return true, if the application is enabled
* @param key the application key
* @return <tt>true</tt> if the application key is enabled
*/
private boolean isApplicationEnabled(String key)
{
@@ -311,7 +367,6 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
Boolean enabled = properties.get(PROPERTY_AUDIT_ENABLED);
if (enabled != null && enabled)
{
final RetryingTransactionCallback<Void> loadModelsCallback = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
@@ -366,13 +421,17 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
auditPathMapper = null;
}
/**
* Gets all audit applications keyed by name.
* @see org.alfresco.repo.audit.model.AuditModelRegistry#getAuditApplications()
*/
public Map<String, AuditApplication> getAuditApplications()
{
return auditApplicationsByName;
}
/**
* Gets an audit application by key.
*
* @param key
* the application key
* @return the audit application
* @see org.alfresco.repo.audit.model.AuditModelRegistry#getAuditApplicationByKey(java.lang.String)
*/
public AuditApplication getAuditApplicationByKey(String key)
@@ -382,10 +441,6 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
/**
* Gets an audit application by name.
*
* @param applicationName
* the application name
* @return the audit application
* @see org.alfresco.repo.audit.model.AuditModelRegistry#getAuditApplicationByName(java.lang.String)
*/
public AuditApplication getAuditApplicationByName(String applicationName)
@@ -396,7 +451,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
/**
* Gets the audit path mapper.
*
* @return the audit path mapper
* @return the audit path mapper
* @see org.alfresco.repo.audit.model.AuditModelRegistry#getAuditPathMapper()
*/
public PathMapper getAuditPathMapper()
@@ -406,11 +461,6 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
/**
* Caches audit elements from a model.
*
* @param auditModelId
* the audit model id
* @param audit
* the audit model
*/
private void cacheAuditElements(Long auditModelId, Audit audit)
{
@@ -576,9 +626,6 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
/**
* Construct the reverse lookup maps for quick conversion of data to target maps.
*
* @param audit
* the audit model
*/
private void buildAuditPathMap(Audit audit)
{
@@ -615,55 +662,6 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement
return new AuditModelRegistryState();
}
/**
* Default constructor.
*/
public AuditModelRegistryImpl()
{
objectFactory = new ObjectFactory();
}
/**
* Sets the search path for config files.
*/
public void setSearchPath(String[] searchPath)
{
this.searchPath = searchPath;
}
/**
* Service to ensure DAO calls are transactionally wrapped.
*/
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
/**
* Set the DAO used to persisted the registered audit models.
*/
public void setAuditDAO(AuditDAO auditDAO)
{
this.auditDAO = auditDAO;
}
/**
* Set the registry of {@link DataExtractor data extractors}.
*/
public void setDataExtractors(NamedObjectRegistry<DataExtractor> dataExtractors)
{
this.dataExtractors = dataExtractors;
}
/**
* Set the registry of {@link DataGenerator data generators}.
*/
public void setDataGenerators(NamedObjectRegistry<DataGenerator> dataGenerators)
{
this.dataGenerators = dataGenerators;
}
/**
* Unmarshalls the Audit model from the URL.
*

View File

@@ -20,6 +20,7 @@ package org.alfresco.service.cmr.audit;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
import org.alfresco.service.PublicService;
@@ -31,6 +32,15 @@ import org.alfresco.service.PublicService;
@PublicService
public interface AuditService
{
/**
* Get all registered audit applications
*
* @return Returns a set of all available audit applications
*
* @since 3.4
*/
Set<String> getAuditApplications();
/**
* @return Returns <tt>true</tt> if auditing is globally enabled
*