Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM 6.3 Custom Lock - Lock payload by logged in user

nvssr90
Level 3
Level 3

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");

        }

1 Accepted Solution
Jörg_Hoh
Correct answer by
Employee
Employee

That's one of the rare caes when you need the deprecated getAdministrativeResourceResolver() method.

Jörg

View solution in original post

4 Replies
adithyaa6344757
Level 3
Level 3

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.

Jörg_Hoh
Correct answer by
Employee
Employee

That's one of the rare caes when you need the deprecated getAdministrativeResourceResolver() method.

Jörg

View solution in original post

smacdonald2008
Level 10
Level 10

Remember when using that call - you must whitelist the OSGi bundle.

adithyaa6344757
Level 3
Level 3

smacdonald2008Jorg​ It worked for me now, I am able to lock the page using getAdministrativeResourceResolver()method and by whitelisting the bundle.

Thanks a lot!!!