RM-3293 RM Audit History does not log

This commit is contained in:
Mihai Cozma
2016-06-23 12:10:06 +03:00
parent 69a20b7adf
commit bf83f34716
4 changed files with 91 additions and 45 deletions

View File

@@ -17,7 +17,8 @@ imap.server.attachments.extraction.enabled=false
#
audit.enabled=true
audit.rm.enabled=true
audit.rm.runasadmin=false
#audit.rm.runas=admin
#audit.filter.alfresco-access.transaction.user=~null;.*
#
@@ -48,7 +49,7 @@ rm.autocompletesuggestion.nodeParameterSuggester.aspectsAndTypes=rma:record,cm:c
#
# Global RM disposition lifecycle trigger cron job expression
#
rm.dispositionlifecycletrigger.cronexpression=0 0/5 * * * ?
rm.dispositionlifecycletrigger.cronexpression=0 0/2 * * * ?
#
# Records contributors group

View File

@@ -53,13 +53,14 @@
<!-- Disposition Lifecycle Job -->
<bean id="scheduledDispositionLifecyceleJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>org.alfresco.module.org_alfresco_module_rm.job.RecordsManagementJob</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="jobName" value="dispositionLifecycle"/>
<entry key="runAsAdmin" value="${audit.rm.runasadmin}"/>
<entry key="jobName" value="dispositionLifecycle" />
<entry key="runAuditAs" value="${audit.rm.runas}" />
<entry key="jobLockService">
<ref bean="jobLockService" />
</entry>
@@ -84,6 +85,7 @@
<property name="nodeService" ref="nodeService" />
<property name="searchService" ref="searchService" />
<property name="authenticationService" ref="authenticationService" />
<property name="recordsManagementActionService" ref="recordsManagementActionService" />
</bean>

View File

@@ -43,16 +43,13 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* The Disposition Lifecycle Job Finds all disposition action nodes which are
* for disposition actions specified Where asOf > now OR
* dispositionEventsEligible = true;
*
* Runs the cut off or retain action for
* eligible records.
* The Disposition Lifecycle Job Finds all disposition action nodes which are for disposition actions specified Where
* asOf > now OR dispositionEventsEligible = true; Runs the cut off or retain action for eligible records.
*
* @author mrogers
* @author Roy Wetherall
@@ -77,6 +74,9 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
/** search service */
private SearchService searchService;
/** authenticationService service */
private AuthenticationService authenticationService;
/**
* List of disposition actions to automatically execute when eligible.
*
@@ -165,7 +165,8 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
if (dispositionActions != null && !dispositionActions.isEmpty())
{
// execute search
ResultSet results = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_FTS_ALFRESCO, getQuery());
ResultSet results = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
SearchService.LANGUAGE_FTS_ALFRESCO, getQuery());
List<NodeRef> resultNodes = results.getNodeRefs();
results.close();
@@ -183,7 +184,8 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
{
public Boolean execute()
{
final String dispAction = (String) nodeService.getProperty(currentNode, RecordsManagementModel.PROP_DISPOSITION_ACTION);
final String dispAction = (String) nodeService.getProperty(currentNode,
RecordsManagementModel.PROP_DISPOSITION_ACTION);
// Run disposition action
if (dispAction != null && dispositionActions.contains(dispAction))
@@ -192,12 +194,14 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
if (parent.getTypeQName().equals(RecordsManagementModel.ASSOC_NEXT_DISPOSITION_ACTION))
{
Map<String, Serializable> props = new HashMap<String, Serializable>(1);
props.put(RMDispositionActionExecuterAbstractBase.PARAM_NO_ERROR_CHECK, Boolean.FALSE);
props.put(RMDispositionActionExecuterAbstractBase.PARAM_NO_ERROR_CHECK,
Boolean.FALSE);
try
{
// execute disposition action
recordsManagementActionService.executeRecordsManagementAction(parent.getParentRef(), dispAction, props);
recordsManagementActionService.executeRecordsManagementAction(
parent.getParentRef(), dispAction, props);
if (logger.isDebugEnabled())
{
@@ -236,4 +240,14 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute
}
}
}
public AuthenticationService getAuthenticationService()
{
return authenticationService;
}
public void setAuthenticationService(AuthenticationService authenticationService)
{
this.authenticationService = authenticationService;
}
}

View File

@@ -42,7 +42,6 @@ import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
/**
* Base records management job implementation.
@@ -55,14 +54,14 @@ public class RecordsManagementJob implements Job
{
private static Log logger = LogFactory.getLog(RecordsManagementJob.class);
/** indicates whether the audit history should be run as admin or not */
private boolean runAsAdmin = false;
/** which user should be used to log audit */
private String runAuditAs = AuthenticationUtil.getSystemUserName();
private static final long DEFAULT_TIME = 30000L;
private JobLockService jobLockService;
private RecordsManagementJobExecuter jobExecuter;
private RecordsManagementJobExecuter jobExecuter = null;
private String jobName;
@@ -105,9 +104,12 @@ public class RecordsManagementJob implements Job
}
}
@Override
/**
* @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
*/
public void execute(JobExecutionContext context) throws JobExecutionException
{
// get the job lock service
jobLockService = (JobLockService) context.getJobDetail().getJobDataMap().get("jobLockService");
if (jobLockService == null) { throw new AlfrescoRuntimeException("Job lock service has not been specified."); }
@@ -118,9 +120,35 @@ public class RecordsManagementJob implements Job
// get the job name
jobName = (String) context.getJobDetail().getJobDataMap().get("jobName");
if (jobName == null) { throw new AlfrescoRuntimeException("Job name has not been specified."); }
setRunAsAdmin(Boolean.parseBoolean((String) context.getJobDetail().getJobDataMap().get("runAsAdmin")));
if (jobName.compareTo("dispositionLifecycle") == 0)
{
//RM-3293 - set user for audit
if (jobExecuter instanceof DispositionLifecycleJobExecuter)
{
String auditUser = (String) context.getJobDetail().getJobDataMap().get("runAuditAs");
if (((DispositionLifecycleJobExecuter) jobExecuter).getAuthenticationService()
.authenticationExists(auditUser))
{
setRunAuditAs(auditUser);
}
else
{
setRunAuditAs(AuthenticationUtil.getSystemUserName());
}
}
if (logger.isDebugEnabled())
{
logger.debug("DispositionLifecycleJobExecuter() logged audit history with user: " + getRunAuditAs());
}
}
final LockCallback lockCallback = new LockCallback();
@@ -160,17 +188,18 @@ public class RecordsManagementJob implements Job
// return
return null;
}
}, this.runAsAdmin ? AuthenticationUtil.getAdminUserName() : AuthenticationUtil.getSystemUserName());
}, getRunAuditAs());
}
public boolean isRunAsAdmin()
public String getRunAuditAs()
{
return runAsAdmin;
return runAuditAs;
}
public void setRunAsAdmin(boolean runAsAdmin)
public void setRunAuditAs(String runAuditAs)
{
this.runAsAdmin = runAsAdmin;
this.runAuditAs = runAuditAs;
}
}