Reputation: 31
I have a functionality in Alfresco where, through a workflow, I need to perform a password change. I migrated from Alfresco 5 Community Edition to Alfresco 7 Community Edition, and it worked correctly in Alfresco 5. Below is the BPMN class:
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
<process id="activitiRipristinaPassword" name="Ripristina Password Alfresco" isExecutable="true">
<startEvent id="start" activiti:formKey="wfCdr:start"/>
<sequenceFlow id="flow1" sourceRef="start" targetRef="review" />
<userTask id="review" name="Review" activiti:formKey="wfCdr:review" activiti:assignee="${bpm_assignee.properties.userName}">
<extensionElements>
<activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string><![CDATA[<import resource="classpath:alfresco/extension/templates/webscripts/it/cdr/scripts/ripristinaPassword.js">
logger.log(">>WF [Ripristina Password Alfresco] - create INIZIO");
// code....
]]></activiti:string>
</activiti:field>
</activiti:taskListener>
<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string><![CDATA[<import resource="classpath:alfresco/extension/templates/webscripts/it/cdr/scripts/ripristinaPassword.js">
logger.log(">>WF [Ripristina Password Alfresco] - complete INIZIO");
var ctx = null;
var alfrescoRepoHelper = null;
var obj = null;
try {
ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
alfrescoRepoHelper = ctx.getBean("alfrescoRepoHelper", Packages.it.comune.r.alfresco.cms.util.AlfrescoRepoHelper);
obj = new RipristinaPassword();
sudo.asTenant(bpm_assignee.properties.userName, obj.reviewComplete, obj);
// Update field "cm:passwordExpiryDate"
alfrescoRepoHelper.setCustomUserProperties(bpm_assignee.properties.userName);
} catch (e) {
logger.log("Errore: " + e);
}
]]></activiti:string>
</activiti:field>
</activiti:taskListener>
</extensionElements>
</userTask>
<boundaryEvent id="timer" name="Timer" attachedToRef="review">
<timerEventDefinition>
<timeDuration>PT24H</timeDuration>
</timerEventDefinition>
</boundaryEvent>
<sequenceFlow id="flow2" sourceRef="review" targetRef="theEnd" />
<sequenceFlow id="flow3" sourceRef="timer" targetRef="theEnd" />
<endEvent id="theEnd"/>
</process>
</definitions>
My issue occurs when I execute the following code:
ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
alfrescoRepoHelper = ctx.getBean("alfrescoRepoHelper", Packages.it.comune.r.alfresco.cms.util.AlfrescoRepoHelper);
The problem is that "Packages" is not found. The task is executed outside of the login (the button triggering the workflow is "forgot password," so it does not require user login).
Below is a fragment of the webscript code that is called to perform the operations:
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
AuthenticationUtil.clearCurrentSecurityContext();
final Map<String,String> data = getDataFromRequest(req);
TenantUtil.runAsUserTenant(new TenantUtil.TenantRunAsWork<Object>() {
@Override
public Object doWork() throws Exception {
TenantContextHolder.setTenantDomain(data.get(DOMAIN_PROP));
WorkflowTask task = workflowService.getTaskById(data.get(TASK_ID));
final Map<QName,Serializable> properties = task.getProperties();
properties.put(Params.QNAME_PASSWORD, data.get(NEW_PASSWORD));
properties.put(Params.QNAME_CONFIRM_PASS, data.get(NEW_PASSWORD_CONFIRM));
AuthenticationUtil.runAsSystem(new AuthenticationUtil.RunAsWork<Object>() {
@Override
public Object doWork() throws Exception {
workflowService.updateTask(data.get(TASK_ID), properties, null, null);
workflowService.endTask(data.get(TASK_ID), null);
return null;
}
});
return null;
}
}, data.get(USER_NAME), data.get(DOMAIN_PROP));
return new HashMap<>();
}
Can you tell me what might be causing this issue? Does the BPMN require a user to be logged in to access the Package? Could adding runAsSystem be enough to solve this? If so, how would I do that?
Upvotes: 0
Views: 30