RM-3114: Prevent access to custom map before it is ready

- remove public init method from AdministrationService
- make admin service impl ordered listener, always goes last
- protect execution of service behaviours until custom map init'ed
This commit is contained in:
Roy Wetherall
2016-03-29 13:09:56 +11:00
parent 69db6fc3dd
commit 08e2ae4042
6 changed files with 185 additions and 158 deletions

1
.gitignore vendored
View File

@@ -24,6 +24,7 @@ test-output
/rm-server/alfresco-solr.zip /rm-server/alfresco-solr.zip
/rm-server/solr /rm-server/solr
/rm-server/shared /rm-server/shared
/rm-server/alf_data
# /rm-server/config/ # /rm-server/config/
/rm-server/config/alfresco-global.properties /rm-server/config/alfresco-global.properties

View File

@@ -168,7 +168,6 @@
<!-- init caveatConfig behaviours --> <!-- init caveatConfig behaviours -->
<property name="caveatConfigService" ref="caveatConfigService"/> <property name="caveatConfigService" ref="caveatConfigService"/>
<property name="customEmailMappingService" ref="customEmailMappingService"/> <property name="customEmailMappingService" ref="customEmailMappingService"/>
<property name="recordsManagementAdminService" ref="RecordsManagementAdminService"/>
</bean> </bean>
<!-- Java script interface for rm caveat config--> <!-- Java script interface for rm caveat config-->

View File

@@ -813,7 +813,6 @@
<property name="objectDefinitionSource"> <property name="objectDefinitionSource">
<value> <value>
<![CDATA[ <![CDATA[
org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.initialiseCustomModel=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.getCustomisable=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.getCustomisable=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.isCustomisable=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.isCustomisable=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.makeCustomisable=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.makeCustomisable=RM_ALLOW

View File

@@ -42,11 +42,6 @@ import org.alfresco.service.namespace.QName;
*/ */
public interface RecordsManagementAdminService public interface RecordsManagementAdminService
{ {
/**
* Initialise the custom model
*/
void initialiseCustomModel();
/** /**
* Get a list of all registered customisable types and aspects. * Get a list of all registered customisable types and aspects.
* *

View File

@@ -86,6 +86,9 @@ import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.Ordered;
import org.springframework.extensions.surf.util.I18NUtil; import org.springframework.extensions.surf.util.I18NUtil;
import org.springframework.extensions.surf.util.ParameterCheck; import org.springframework.extensions.surf.util.ParameterCheck;
import org.springframework.extensions.surf.util.URLDecoder; import org.springframework.extensions.surf.util.URLDecoder;
@@ -100,7 +103,9 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
RecordsManagementCustomModel, RecordsManagementCustomModel,
NodeServicePolicies.OnAddAspectPolicy, NodeServicePolicies.OnAddAspectPolicy,
NodeServicePolicies.OnRemoveAspectPolicy, NodeServicePolicies.OnRemoveAspectPolicy,
NodeServicePolicies.OnCreateNodePolicy NodeServicePolicies.OnCreateNodePolicy,
ApplicationListener<ContextRefreshedEvent>,
Ordered
{ {
/** Logger */ /** Logger */
private static Log logger = LogFactory.getLog(RecordsManagementAdminServiceImpl.class); private static Log logger = LogFactory.getLog(RecordsManagementAdminServiceImpl.class);
@@ -163,6 +168,9 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
private List<QName> pendingCustomisableTypes; private List<QName> pendingCustomisableTypes;
private Map<QName, QName> customisableTypes; private Map<QName, QName> customisableTypes;
/** indicates whether the custom map has been initialised or not */
private boolean isCustomMapInit = false;
/** /**
* @param dictionaryService the dictionary service * @param dictionaryService the dictionary service
*/ */
@@ -225,6 +233,30 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
onRemoveReferenceDelegate = policyComponent.registerClassPolicy(OnRemoveReference.class); onRemoveReferenceDelegate = policyComponent.registerClassPolicy(OnRemoveReference.class);
} }
/**
* Indicate that this application content listener must be executed with the highest
* precedence.
*
* @see Ordered#getOrder()
*/
@Override
public int getOrder()
{
return Ordered.LOWEST_PRECEDENCE;
}
/**
* Load the custom properties map
*
* @see ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
@Override
public void onApplicationEvent(ContextRefreshedEvent event)
{
// initialise custom properties
initCustomMap();
}
/** /**
* Invoke before create reference policy * Invoke before create reference policy
* *
@@ -300,6 +332,8 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
notificationFrequency = NotificationFrequency.FIRST_EVENT notificationFrequency = NotificationFrequency.FIRST_EVENT
) )
public void onAddAspect(final NodeRef nodeRef, final QName aspectTypeQName) public void onAddAspect(final NodeRef nodeRef, final QName aspectTypeQName)
{
if (isCustomMapInit)
{ {
AuthenticationUtil.runAs(new RunAsWork<Void>() AuthenticationUtil.runAs(new RunAsWork<Void>()
{ {
@@ -318,6 +352,7 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
} }
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
} }
}
/** /**
* @see org.alfresco.repo.node.NodeServicePolicies.OnRemoveAspectPolicy#onRemoveAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName) * @see org.alfresco.repo.node.NodeServicePolicies.OnRemoveAspectPolicy#onRemoveAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
@@ -330,6 +365,8 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
notificationFrequency = NotificationFrequency.FIRST_EVENT notificationFrequency = NotificationFrequency.FIRST_EVENT
) )
public void onRemoveAspect(final NodeRef nodeRef, final QName aspectTypeQName) public void onRemoveAspect(final NodeRef nodeRef, final QName aspectTypeQName)
{
if (isCustomMapInit)
{ {
AuthenticationUtil.runAs(new RunAsWork<Void>() AuthenticationUtil.runAs(new RunAsWork<Void>()
{ {
@@ -347,6 +384,7 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
} }
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
} }
}
/** /**
* Make sure any custom property aspects are applied to newly created nodes. * Make sure any custom property aspects are applied to newly created nodes.
@@ -361,6 +399,8 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
notificationFrequency = NotificationFrequency.FIRST_EVENT notificationFrequency = NotificationFrequency.FIRST_EVENT
) )
public void onCreateNode(final ChildAssociationRef childAssocRef) public void onCreateNode(final ChildAssociationRef childAssocRef)
{
if (isCustomMapInit)
{ {
AuthenticationUtil.runAs(new RunAsWork<Void>() AuthenticationUtil.runAs(new RunAsWork<Void>()
{ {
@@ -395,14 +435,6 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
} }
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
} }
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#initialiseCustomModel()
*/
public void initialiseCustomModel()
{
// Initialise the map
getCustomisableMap();
} }
/** /**
@@ -485,13 +517,9 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
} }
/** /**
* Gets a map containing all the customisable types * Initialise custom type map
*
* @return map from the customisable type to its custom aspect
*/ */
private Map<QName, QName> getCustomisableMap() private void initCustomMap()
{
if (customisableTypes == null)
{ {
customisableTypes = new HashMap<QName, QName>(7); customisableTypes = new HashMap<QName, QName>(7);
Collection<QName> aspects = dictionaryService.getAspects(RM_CUSTOM_MODEL); Collection<QName> aspects = dictionaryService.getAspects(RM_CUSTOM_MODEL);
@@ -569,6 +597,21 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
writeCustomContentModel(modelRef, model); writeCustomContentModel(modelRef, model);
} }
} }
// indicate map is initialised
isCustomMapInit = true;
}
/**
* Gets a map containing all the customisable types
*
* @return map from the customisable type to its custom aspect
*/
private Map<QName, QName> getCustomisableMap()
{
if (customisableTypes == null)
{
throw AlfrescoRuntimeException.create("Customisable map has not been initialised correctly.");
} }
return customisableTypes; return customisableTypes;
} }

View File

@@ -18,7 +18,6 @@
*/ */
package org.alfresco.module.org_alfresco_module_rm.bootstrap; package org.alfresco.module.org_alfresco_module_rm.bootstrap;
import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
import org.alfresco.module.org_alfresco_module_rm.action.impl.SplitEmailAction; import org.alfresco.module.org_alfresco_module_rm.action.impl.SplitEmailAction;
import org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigService; import org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigService;
import org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService; import org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService;
@@ -40,7 +39,6 @@ public class RecordsManagementBootstrap extends AbstractLifecycleBean
private TransactionService transactionService; private TransactionService transactionService;
private RMCaveatConfigService caveatConfigService; private RMCaveatConfigService caveatConfigService;
private CustomEmailMappingService customEmailMappingService; private CustomEmailMappingService customEmailMappingService;
private RecordsManagementAdminService adminService;
public void setTransactionService(TransactionService transactionService) public void setTransactionService(TransactionService transactionService)
{ {
@@ -57,11 +55,6 @@ public class RecordsManagementBootstrap extends AbstractLifecycleBean
this.customEmailMappingService = customEmailMappingService; this.customEmailMappingService = customEmailMappingService;
} }
public void setRecordsManagementAdminService(RecordsManagementAdminService adminService)
{
this.adminService = adminService;
}
public CustomEmailMappingService getCustomEmailMappingService() public CustomEmailMappingService getCustomEmailMappingService()
{ {
return customEmailMappingService; return customEmailMappingService;
@@ -82,9 +75,6 @@ public class RecordsManagementBootstrap extends AbstractLifecycleBean
// initialise caveat config // initialise caveat config
caveatConfigService.init(); caveatConfigService.init();
// Initialise the custom model
adminService.initialiseCustomModel();
// Initialise the SplitEmailAction // Initialise the SplitEmailAction
SplitEmailAction action = (SplitEmailAction)getApplicationContext().getBean("splitEmail"); SplitEmailAction action = (SplitEmailAction)getApplicationContext().getBean("splitEmail");
action.bootstrap(); action.bootstrap();