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
BedrockMission!

Learn More

View all

Sign in to view all badges

AEM 6.3 Custom Lock - Lock payload by logged in user

Avatar

Avatar
Validate 1
Level 2
nvssr90
Level 2

Likes

6 likes

Total Posts

22 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Ignite 5
View profile

Avatar
Validate 1
Level 2
nvssr90
Level 2

Likes

6 likes

Total Posts

22 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Ignite 5
View profile
nvssr90
Level 2

23-07-2018

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

        }

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,111 likes

Total Posts

3,145 posts

Correct Reply

1,072 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,111 likes

Total Posts

3,145 posts

Correct Reply

1,072 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

20-11-2018

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

Jörg

Answers (3)

Answers (3)

Avatar

Avatar
Validate 1
Level 2
adithyaa6344757
Level 2

Likes

6 likes

Total Posts

36 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 2
adithyaa6344757
Level 2

Likes

6 likes

Total Posts

36 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
adithyaa6344757
Level 2

20-11-2018

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

Thanks a lot!!!

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

20-11-2018

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

Avatar

Avatar
Validate 1
Level 2
adithyaa6344757
Level 2

Likes

6 likes

Total Posts

36 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 2
adithyaa6344757
Level 2

Likes

6 likes

Total Posts

36 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
adithyaa6344757
Level 2

20-11-2018

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.