Hi All,
I have created a workflow step to custom lock a page. I am using below step to lock a page but It always locks with service user - I am able to get the current logged in user but unable to impersonate the current logged in user by service user. Is there any way I can lock a payload by currently logged in user?
Approached Tried
1) using workflow session --- It locks by workflow-service-user
2) user impersonation to resource resolver - Unable to impersonate user (error)
3) using dedicated sub-service to get resource resolver -- It locks the payload by dedicated service user
Please let me know is there a way to lock a page by logged in user.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////-- locks by workflow-service-user
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap arg2) throws WorkflowException {
workItem.getWorkflow().getInitiator();
String payload = (String) workItem.getWorkflowData().getPayload();
ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
//Page currentPage = pageManager.getPage("/content/page/en/");
Page page = pageManager.getPage(payload);
if (page.isLocked()) {
//log error
log.info("If Page Locked");
} else {
try {
page.lock();
} catch (WCMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log.info("Else Page Locked");
}
}---
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////----------locks by service-user
resolver = SoniUtils.getResourceResolver(resourceResolverFactory);
UserManager userManager = resolver.adaptTo(UserManager.class);
String initiator = item.getWorkflow().getInitiator();
User currentuser = (User)userManager.getAuthorizable(initiator);
LOG.info(" currentuser: "+ currentuser);
PageManager pageManager = resolver.adaptTo(PageManager.class);
Page page = pageManager.getPage(payload);
if (page.isLocked()) {
//log error
LOG.info("If Page Locked");
} else {
page.lock();
LOG.info("Else Page Locked");
}
Solved! Go to Solution.
Views
Replies
Total Likes
That's one of the rare caes when you need the deprecated getAdministrativeResourceResolver() method.
Jörg
Views
Replies
Total Likes
Hi even I am looking for the similar kind of solution. We have the requirement to acquire the lock and unlock of the page by author or initiator of workflow.
Views
Replies
Total Likes
That's one of the rare caes when you need the deprecated getAdministrativeResourceResolver() method.
Jörg
Views
Replies
Total Likes
Remember when using that call - you must whitelist the OSGi bundle.
Views
Replies
Total Likes
smacdonald2008 Jorg It worked for me now, I am able to lock the page using getAdministrativeResourceResolver()method and by whitelisting the bundle.
Thanks a lot!!!
Views
Replies
Total Likes
Views
Likes
Replies