Expand my Community achievements bar.

check initiator access to replicate the payload from workflow

Avatar

Level 2

trying to check if user/initiator who run a request for activation workflow, had enough permission to activate the page. depending on the user access, I am trying to update the workflow model under OR split. used below code to get the user privileges 

 

Session session = resourceResolver.adaptTo(Session.class);
AccessControlManager acm = session.getAccessControlManager();

Privilege p[] = UIHelper.getAllPermission(acm, resource);

 

Issue is session.getUserID() return the workflow user, Need a way to get the session adaptTo initiator userID(). 

Please let me know, if any suggestions to achieve it or suggest if any alternate approach to check user has permission to replicate the page.

Thanks!

 

 

2 Replies

Avatar

Employee Advisor

Here is the sample workflow model which is responsible to read workflow initiator(process step) and selecting that initiator as participant using dynamic participant step -

 

DEBAL_DAS_0-1645966795610.png

Sample process step -

package com.aem.demo.core.workflows;

import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowData;
import com.adobe.granite.workflow.exec.WorkflowProcess;
import com.adobe.granite.workflow.metadata.MetaDataMap;

@component(property = { Constants.SERVICE_DESCRIPTION + "=This workflow step is responsible to put initiator details",
Constants.SERVICE_VENDOR + "=AEM Demo Debal", "process.label" + "=Initiator details" })
public class GetInitiatorInfoStep implements WorkflowProcess {

private final Logger logger = LoggerFactory.getLogger(GetInitiatorInfoStep.class);

@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
throws WorkflowException {

 

WorkflowData workflowData = workItem.getWorkflowData();

workflowData.getMetaDataMap().put("initiator", workItem.getWorkflow().getInitiator());

}

}

Dynamic Participant Step

package com.aem.demo.core.workflows;

import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.ParticipantStepChooser;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;

@component(service = ParticipantStepChooser.class, immediate = true, property = {"chooser.label" + "=Initiator details info" })
public class InitiatorDetailsStep implements ParticipantStepChooser {

private final Logger logger = LoggerFactory.getLogger(InitiatorDetailsStep.class);



@Override
public String getParticipant(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
throws WorkflowException {
String participant = "";

MetaDataMap map = workItem.getWorkflow().getWorkflowData().getMetaDataMap();
String reviewer = (String) map.get("initiator");

logger.info("*** Reviewer ***", reviewer);

if (!reviewer.isEmpty()) {

participant = reviewer;
} else {
participant = "reviewers";
}

return participant;
}


}

 

After staring the workflow on page , I have captured below details -

Impersonating as Debal -

DEBAL_DAS_2-1645967280292.png

 

Task is assigned to Debal Das(Initiator) and inbox notification has come -

DEBAL_DAS_3-1645967387637.png

 

Initiator name at workflow instance node -

DEBAL_DAS_1-1645967163966.png

 

Similar data were captured for Iris Mccoy -

DEBAL_DAS_4-1645967523716.pngDEBAL_DAS_5-1645967609438.pngDEBAL_DAS_6-1645967653545.png

 

Please refer following links- https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/workflows-get-initiator-in...

 

https://stackoverflow.com/questions/37341741/how-to-send-an-approval-or-rejection-email-to-workflow-...

 

 

Avatar

Level 2

Thanks for the response @DEBAL_DAS . I can able to get the workflow initiator. I want to check if initiator had enough privileges' to replicate a page in the workflow process. Issue is I can't get session adaptTo to initiator to check the privilege's. I am always getting session with workflow-user rather than a initiator session.