How to impersonate the user from code in AEM 6.2?
I understand it is not the same way as AEM 6.0. Please help.
Solved! Go to Solution.
Views
Replies
Total Likes
This worked for us:
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Reference
private SlingRepository repository;
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
Session session = workflowSession.getSession();
ResourceResolver resourceResolver = resourceResolver = getResourceResolver(resourceResolverFactory, session);
final String initiator = workItem.getWorkflow().getInitiator();
Session userSession = repository.impersonateFromService("workflow-process-service", new SimpleCredentials(initiator, "".toCharArray()), null);
//other logic
}
Views
Replies
Total Likes
Hi,
The below should work in AEM 6.2
(repository.impersonateFromService(Constants.WORKFLOW_USER,
new SimpleCredentials(item.getWorkflow().getInitiator();, "".toCharArray()), null), resolverFactory)
Views
Replies
Total Likes
HI cquser1,
Can you explain how it works?
Views
Replies
Total Likes
It uses this API: Session (Content Repository for Java Technology API Version 2.0)
Views
Replies
Total Likes
This worked for us:
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Reference
private SlingRepository repository;
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
Session session = workflowSession.getSession();
ResourceResolver resourceResolver = resourceResolver = getResourceResolver(resourceResolverFactory, session);
final String initiator = workItem.getWorkflow().getInitiator();
Session userSession = repository.impersonateFromService("workflow-process-service", new SimpleCredentials(initiator, "".toCharArray()), null);
//other logic
}
Views
Replies
Total Likes