mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
AuditModelRegistryImpl refactored as dynamic subsystem
- Modules such as RM can now drop in their own config - should fix some unit tests - Picks up config from classpath*:alfresco/audit/*.xml classpath*:alfresco/enterprise/audit/*.xml classpath*:alfresco/module/*/audit/*.xml classpath*:alfresco/extension/audit/*.xml - One audit.{applicationkey}.enabled property for each application in the config, defaulting to true - One audit.enabled global enablement property defaulting to false - Still controllable by alfresco-global.properties and JMX git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18841 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -117,16 +117,7 @@
|
||||
<property name="nodeService" ref="nodeService" />
|
||||
</bean>
|
||||
|
||||
<!-- Mount registry from Audit subsystem -->
|
||||
<bean id="auditModel.modelRegistry" class="org.alfresco.repo.management.subsystems.SubsystemProxyFactory">
|
||||
<property name="sourceApplicationContextFactory">
|
||||
<ref bean="Audit" />
|
||||
</property>
|
||||
<property name="interfaces">
|
||||
<list>
|
||||
<value>org.alfresco.repo.audit.model.AuditModelRegistry</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
<!-- Reference in the audit registry managed bean -->
|
||||
<alias name="Audit" alias="auditModel.modelRegistry"/>
|
||||
|
||||
</beans>
|
@@ -552,7 +552,19 @@
|
||||
</bean>
|
||||
|
||||
<!-- Start Auditing -->
|
||||
<bean id="Audit" class="org.alfresco.repo.management.subsystems.ChildApplicationContextFactory" parent="abstractPropertyBackedBean">
|
||||
<bean id="Audit" class="org.alfresco.repo.audit.model.AuditModelRegistryImpl" parent="abstractPropertyBackedBean">
|
||||
<property name="searchPath">
|
||||
<list>
|
||||
<value>classpath*:alfresco/audit/*.xml</value>
|
||||
<value>classpath*:alfresco/enterprise/audit/*.xml</value>
|
||||
<value>classpath*:alfresco/module/*/audit/*.xml</value>
|
||||
<value>classpath*:alfresco/extension/audit/*.xml</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="transactionService" ref="transactionService" />
|
||||
<property name="auditDAO" ref="auditDAO" />
|
||||
<property name="dataExtractors" ref="auditModel.extractorRegistry" />
|
||||
<property name="dataGenerators" ref="auditModel.generatorRegistry" />
|
||||
<property name="autoStart">
|
||||
<value>true</value>
|
||||
</property>
|
||||
|
@@ -251,7 +251,7 @@ db.pool.abandoned.time=300
|
||||
# Audit configuration
|
||||
audit.enabled=false
|
||||
audit.repository.enabled=true
|
||||
audit.cmis.enabled=true
|
||||
audit.cmischangelog.enabled=true
|
||||
audit.useNewConfig=true
|
||||
|
||||
# Email configuration
|
||||
|
@@ -1,43 +0,0 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
|
||||
|
||||
<beans>
|
||||
|
||||
<!-- Start Auditing -->
|
||||
<bean id="audit.bootstrap" class="org.alfresco.repo.audit.AuditBootstrap">
|
||||
<property name="active">
|
||||
<value>${audit.enabled}</value>
|
||||
</property>
|
||||
<property name="transactionService" ref="transactionService"/>
|
||||
<property name="auditModelRegistry" ref="auditModel.modelRegistry"/>
|
||||
</bean>
|
||||
|
||||
<!-- Models -->
|
||||
<bean id="auditModel.modelRegistry" class="org.alfresco.repo.audit.model.AuditModelRegistryImpl">
|
||||
<property name="transactionService" ref="transactionService"/>
|
||||
<property name="auditDAO" ref="auditDAO"/>
|
||||
<property name="dataExtractors" ref="auditModel.extractorRegistry"/>
|
||||
<property name="dataGenerators" ref="auditModel.generatorRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="auditModel.repository" class="org.alfresco.repo.audit.model.AuditModelReader">
|
||||
<property name="active">
|
||||
<value>${audit.repository.enabled}</value>
|
||||
</property>
|
||||
<property name="auditModelUrl">
|
||||
<value>classpath:alfresco/audit/alfresco-audit-repository.xml</value>
|
||||
</property>
|
||||
<property name="auditModelRegistry" ref="auditModel.modelRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="auditModel.cmis" class="org.alfresco.repo.audit.model.AuditModelReader">
|
||||
<property name="active">
|
||||
<value>${audit.cmis.enabled}</value>
|
||||
</property>
|
||||
<property name="auditModelUrl">
|
||||
<value>classpath:alfresco/audit/alfresco-audit-cmis.xml</value>
|
||||
</property>
|
||||
<property name="auditModelRegistry" ref="auditModel.modelRegistry"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
@@ -1,3 +0,0 @@
|
||||
audit.enabled=false
|
||||
audit.repository.enabled=true
|
||||
audit.cmis.enabled=true
|
@@ -39,7 +39,7 @@ import org.alfresco.cmis.CMISChangeType;
|
||||
import org.alfresco.cmis.mapping.BaseCMISTest;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
|
||||
import org.alfresco.repo.audit.model.AuditModelRegistryImpl;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -76,7 +76,7 @@ public class CMISChangeLogServiceTest extends BaseCMISTest
|
||||
EXPECTED_AMOUNTS.put(CMISChangeType.UPDATED, 6);
|
||||
}
|
||||
|
||||
private ApplicationContextFactory auditSubsystem;
|
||||
private AuditModelRegistryImpl auditSubsystem;
|
||||
private CMISChangeLogService changeLogService;
|
||||
|
||||
private int actualCount = 0;
|
||||
@@ -88,14 +88,14 @@ public class CMISChangeLogServiceTest extends BaseCMISTest
|
||||
{
|
||||
auditSubsystem.stop();
|
||||
auditSubsystem.setProperty("audit.enabled", "true");
|
||||
auditSubsystem.setProperty("audit.cmis.enabled", "false");
|
||||
auditSubsystem.setProperty("audit.cmischangelog.enabled", "false");
|
||||
}
|
||||
|
||||
private void enableAudit()
|
||||
{
|
||||
auditSubsystem.stop();
|
||||
auditSubsystem.setProperty("audit.enabled", "true");
|
||||
auditSubsystem.setProperty("audit.cmis.enabled", "true");
|
||||
auditSubsystem.setProperty("audit.cmischangelog.enabled", "true");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -407,7 +407,7 @@ public class CMISChangeLogServiceTest extends BaseCMISTest
|
||||
nodeService = (NodeService) applicationContext.getBean("NodeService");
|
||||
permissionService = (PermissionService) applicationContext.getBean("PermissionService");
|
||||
fileFolderService = (FileFolderService) applicationContext.getBean("FileFolderService");
|
||||
auditSubsystem = (ApplicationContextFactory) applicationContext.getBean("Audit");
|
||||
auditSubsystem = (AuditModelRegistryImpl) applicationContext.getBean("Audit");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -415,5 +415,6 @@ public class CMISChangeLogServiceTest extends BaseCMISTest
|
||||
{
|
||||
deleteTestData();
|
||||
super.tearDown();
|
||||
auditSubsystem.destroy();
|
||||
}
|
||||
}
|
||||
|
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.audit;
|
||||
|
||||
import org.alfresco.repo.audit.model.AuditModelRegistry;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* Starts all the necessary audit functionality once the repository has started.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @since 3.2
|
||||
*/
|
||||
public class AuditBootstrap extends AbstractLifecycleBean
|
||||
{
|
||||
private TransactionService transactionService;
|
||||
private AuditModelRegistry auditModelRegistry;
|
||||
private boolean isActive = true;
|
||||
|
||||
public void setTransactionService(TransactionService transactionService)
|
||||
{
|
||||
this.transactionService = transactionService;
|
||||
}
|
||||
|
||||
public void setAuditModelRegistry(AuditModelRegistry registry)
|
||||
{
|
||||
this.auditModelRegistry = registry;
|
||||
}
|
||||
|
||||
public void setActive(boolean isActive)
|
||||
{
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AuditModelRegistry#loadAuditModels()
|
||||
*/
|
||||
@Override
|
||||
protected void onBootstrap(ApplicationEvent event)
|
||||
{
|
||||
// Don't bootstrap if the system is read-only
|
||||
if (transactionService.isReadOnly())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't start if we've been configured out
|
||||
if (!this.isActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
auditModelRegistry.loadAuditModels();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(callback, transactionService.isReadOnly());
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op
|
||||
*/
|
||||
@Override
|
||||
protected void onShutdown(ApplicationEvent event)
|
||||
{
|
||||
}
|
||||
}
|
@@ -34,7 +34,6 @@ import org.alfresco.repo.audit.generator.DataGenerator;
|
||||
import org.alfresco.repo.audit.model.AuditApplication;
|
||||
import org.alfresco.repo.audit.model.AuditModelException;
|
||||
import org.alfresco.repo.audit.model.AuditModelRegistryImpl;
|
||||
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.PathMapper;
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -63,17 +62,21 @@ public class AuditBootstrapTest extends TestCase
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
// We have to look inside the subsystem for this test
|
||||
ApplicationContextFactory subsystem = (ApplicationContextFactory) ctx.getBean("Audit");
|
||||
ApplicationContext subCtx = subsystem.getApplicationContext();
|
||||
auditModelRegistry = (AuditModelRegistryImpl) subCtx.getBean("auditModel.modelRegistry");
|
||||
auditModelRegistry = (AuditModelRegistryImpl) ctx.getBean("auditModel.modelRegistry");
|
||||
|
||||
// Register a new model
|
||||
URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/audit/alfresco-audit-test.xml");
|
||||
URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test.xml");
|
||||
auditModelRegistry.registerModel(testModelUrl);
|
||||
auditModelRegistry.loadAuditModels();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
// Throw away the reconfigured registry state
|
||||
auditModelRegistry.destroy();
|
||||
}
|
||||
|
||||
public void testSetUp()
|
||||
{
|
||||
// Just here to fail if the basic startup fails
|
||||
@@ -97,32 +100,32 @@ public class AuditBootstrapTest extends TestCase
|
||||
|
||||
public void testModelLoading_NoDataExtractor() throws Exception
|
||||
{
|
||||
loadBadModel("classpath:alfresco/audit/alfresco-audit-test-bad-01.xml");
|
||||
loadBadModel("classpath:alfresco/testaudit/alfresco-audit-test-bad-01.xml");
|
||||
}
|
||||
|
||||
public void testModelLoading_NoDataGenerator() throws Exception
|
||||
{
|
||||
loadBadModel("classpath:alfresco/audit/alfresco-audit-test-bad-02.xml");
|
||||
loadBadModel("classpath:alfresco/testaudit/alfresco-audit-test-bad-02.xml");
|
||||
}
|
||||
|
||||
public void testModelLoading_DuplicatePath() throws Exception
|
||||
{
|
||||
loadBadModel("classpath:alfresco/audit/alfresco-audit-test-bad-03.xml");
|
||||
loadBadModel("classpath:alfresco/testaudit/alfresco-audit-test-bad-03.xml");
|
||||
}
|
||||
|
||||
public void testModelLoading_UppercasePath() throws Exception
|
||||
{
|
||||
loadBadModel("classpath:alfresco/audit/alfresco-audit-test-bad-04.xml");
|
||||
loadBadModel("classpath:alfresco/testaudit/alfresco-audit-test-bad-04.xml");
|
||||
}
|
||||
|
||||
public void testModelLoading_InvalidDataGeneratorName() throws Exception
|
||||
{
|
||||
loadBadModel("classpath:alfresco/audit/alfresco-audit-test-bad-05.xml");
|
||||
loadBadModel("classpath:alfresco/testaudit/alfresco-audit-test-bad-05.xml");
|
||||
}
|
||||
|
||||
public void testModelLoading_BadGeneratorRegisteredName() throws Exception
|
||||
{
|
||||
loadBadModel("classpath:alfresco/audit/alfresco-audit-test-bad-06.xml");
|
||||
loadBadModel("classpath:alfresco/testaudit/alfresco-audit-test-bad-06.xml");
|
||||
}
|
||||
|
||||
public void testGetApplicationId()
|
||||
|
@@ -39,7 +39,6 @@ import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.audit.model.AuditApplication;
|
||||
import org.alfresco.repo.audit.model.AuditModelException;
|
||||
import org.alfresco.repo.audit.model.AuditModelRegistryImpl;
|
||||
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
@@ -80,7 +79,6 @@ public class AuditComponentTest extends TestCase
|
||||
|
||||
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
||||
|
||||
private ApplicationContextFactory subsystem;
|
||||
private AuditModelRegistryImpl auditModelRegistry;
|
||||
private AuditComponent auditComponent;
|
||||
private AuditService auditService;
|
||||
@@ -94,10 +92,7 @@ public class AuditComponentTest extends TestCase
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
// We have to look inside the subsystem for this test
|
||||
subsystem = (ApplicationContextFactory) ctx.getBean("Audit");
|
||||
ApplicationContext subCtx = subsystem.getApplicationContext();
|
||||
auditModelRegistry = (AuditModelRegistryImpl) subCtx.getBean("auditModel.modelRegistry");
|
||||
auditModelRegistry = (AuditModelRegistryImpl) ctx.getBean("auditModel.modelRegistry");
|
||||
auditComponent = (AuditComponent) ctx.getBean("auditComponent");
|
||||
serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
auditService = serviceRegistry.getAuditService();
|
||||
@@ -105,7 +100,7 @@ public class AuditComponentTest extends TestCase
|
||||
nodeService = serviceRegistry.getNodeService();
|
||||
|
||||
// Register the test model
|
||||
URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/audit/alfresco-audit-test.xml");
|
||||
URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test.xml");
|
||||
auditModelRegistry.registerModel(testModelUrl);
|
||||
auditModelRegistry.loadAuditModels();
|
||||
|
||||
@@ -138,8 +133,8 @@ public class AuditComponentTest extends TestCase
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
// Throw away the reconfigured registry in the subsystem
|
||||
subsystem.stop();
|
||||
// Throw away the reconfigured registry state
|
||||
auditModelRegistry.destroy();
|
||||
}
|
||||
|
||||
public void testSetUp()
|
||||
@@ -479,7 +474,7 @@ public class AuditComponentTest extends TestCase
|
||||
params.setApplicationName(APPLICATION_API_TEST);
|
||||
|
||||
// Load in the config for this specific test: alfresco-audit-test-authenticationservice.xml
|
||||
URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/audit/alfresco-audit-test-authenticationservice.xml");
|
||||
URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test-authenticationservice.xml");
|
||||
auditModelRegistry.registerModel(testModelUrl);
|
||||
auditModelRegistry.loadAuditModels();
|
||||
|
||||
|
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing
|
||||
*/
|
||||
package org.alfresco.repo.audit.model;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.springframework.extensions.surf.util.PropertyCheck;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
/**
|
||||
* A component used to load Audit model XML documents.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @since 3.2
|
||||
*/
|
||||
public class AuditModelReader implements InitializingBean
|
||||
{
|
||||
private URL auditModelUrl;
|
||||
private AuditModelRegistryImpl auditModelRegistry;
|
||||
private boolean isActive = true;
|
||||
|
||||
/**
|
||||
* Set the XML location using <b>file:</b>, <b>classpath:</b> or any of the
|
||||
* {@link ResourceUtils Spring-supported} formats.
|
||||
*
|
||||
* @param auditModelUrl the location of the XML file
|
||||
*/
|
||||
public void setAuditModelUrl(URL auditModelUrl)
|
||||
{
|
||||
this.auditModelUrl = auditModelUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param auditModelRegistry the registry that combines all loaded models
|
||||
*/
|
||||
public void setAuditModelRegistry(AuditModelRegistryImpl auditModelRegistry)
|
||||
{
|
||||
this.auditModelRegistry = auditModelRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether or not this bean registers its model with the registry on initialization.
|
||||
*
|
||||
* @param isActive
|
||||
* <code>true</code> if this bean should register its model with the registry on initialization.
|
||||
*/
|
||||
public void setActive(boolean isActive)
|
||||
{
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulls in the configuration and registers it
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
if (!this.isActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PropertyCheck.mandatory(this, "configUrl", auditModelUrl);
|
||||
PropertyCheck.mandatory(this, "auditModelRegistry", auditModelRegistry);
|
||||
|
||||
auditModelRegistry.registerModel(auditModelUrl);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -66,7 +66,7 @@ public class ResourceFinder extends ServletContextResourcePatternResolver
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public Resource[] getResources(String[] locationPatterns) throws IOException
|
||||
public Resource[] getResources(String... locationPatterns) throws IOException
|
||||
{
|
||||
List<Resource> resources = new LinkedList<Resource>();
|
||||
for (String locationPattern : locationPatterns)
|
||||
|
Reference in New Issue
Block a user