Merge branch 'feature-2.4/RM-3293_Audit_not_log_default_scheduled' into 'release/V2.4'

Feature 2.4/rm 3293 audit not log default scheduled

See merge request !242
This commit is contained in:
Mihai Cozma
2016-06-24 15:24:52 +01:00
4 changed files with 115 additions and 58 deletions

View File

@@ -17,6 +17,9 @@ imap.server.attachments.extraction.enabled=false
#
audit.enabled=true
audit.rm.enabled=true
#audit.rm.runas=admin
#audit.filter.alfresco-access.transaction.user=~null;.*
#
# Extended permission service cache sizing
@@ -46,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,12 +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="runAuditAs" value="${audit.rm.runas}" />
<entry key="jobLockService">
<ref bean="jobLockService" />
</entry>
@@ -83,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

@@ -46,8 +46,7 @@ import org.quartz.JobExecutionException;
/**
* Base records management job implementation.
* <p>
* Delegates job execution and ensures locking
* is enforced.
* Delegates job execution and ensures locking is enforced.
*
* @author Roy Wetherall
*/
@@ -55,11 +54,14 @@ public class RecordsManagementJob implements Job
{
private static Log logger = LogFactory.getLog(RecordsManagementJob.class);
/** 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;
@@ -85,7 +87,6 @@ public class RecordsManagementJob implements Job
}
}
/**
* Attempts to get the lock. If the lock couldn't be taken, then <tt>null</tt> is returned.
*
@@ -103,31 +104,54 @@ 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.");
}
if (jobLockService == null) { throw new AlfrescoRuntimeException("Job lock service has not been specified."); }
// get the job executer
jobExecuter = (RecordsManagementJobExecuter) context.getJobDetail().getJobDataMap().get("jobExecuter");
if (jobExecuter == null)
{
throw new AlfrescoRuntimeException("Job executer has not been specified.");
}
if (jobExecuter == null) { throw new AlfrescoRuntimeException("Job executer has not been specified."); }
// get the job name
jobName = (String) context.getJobDetail().getJobDataMap().get("jobName");
if (jobName == null)
if (jobName == null) { throw new AlfrescoRuntimeException("Job name has not been specified."); }
if (jobName.compareTo("dispositionLifecycle") == 0)
{
throw new AlfrescoRuntimeException("Job name has not been specified.");
//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();
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
public Void doWork()
@@ -154,7 +178,8 @@ public class RecordsManagementJob implements Job
// Ignore
if (logger.isDebugEnabled())
{
logger.debug("Lock release failed: " + getLockQName() + ": " + lockToken + "(" + e.getMessage() + ")");
logger.debug("Lock release failed: " + getLockQName() + ": " + lockToken + "("
+ e.getMessage() + ")");
}
}
}
@@ -163,6 +188,18 @@ public class RecordsManagementJob implements Job
// return
return null;
}
}, AuthenticationUtil.getSystemUserName());
}, getRunAuditAs());
}
public String getRunAuditAs()
{
return runAuditAs;
}
public void setRunAuditAs(String runAuditAs)
{
this.runAuditAs = runAuditAs;
}
}