check initiator access to replicate the payload from workflow | Community
Skip to main content
Level 2
February 25, 2022

check initiator access to replicate the payload from workflow

  • February 25, 2022
  • 1 reply
  • 862 views

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!

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

DEBAL_DAS
New Member
February 25, 2022

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 -

 

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;

@8220494(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);

@9944223
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;

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

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



@9944223
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 -

 

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

 

Initiator name at workflow instance node -

 

Similar data were captured for Iris Mccoy -

 

Please refer following links- https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/workflows-get-initiator-in-a-workflow-route/m-p/165084

 

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

 

 

Debal Das, Senior AEM Consultant
Level 2
February 27, 2022

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.