Expand my Community achievements bar.

SOLVED

How to get currently LoggedIn user in handler called from sightly in CQ5, AEM

Avatar

Level 4

I have an sightly component(.html) from where I am calling a method of my handler. In my handler I want to check userId of the loggedIn user and based on the loggedIn user I want to make that method of handler return values. How can I get the user Id of loggedIn user who is calling this handler. My html is as :

<div data-sly-unwrap data-sly-use.handler="${'com.my.wcm.sightly.handlers.MyHandler'}"> <a href="${handler.linkforloggedinUser}">${handler.linkTitle}</a><br/> </p> </div>

My Handler has simple activate method as its extending WCMUse class. Please suggest any way to get the user in my handler.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

You can get the userid from  the resource resolver object- https://docs.adobe.com/content/docs/en/aem/6-0/develop/ref/javadoc/com/adobe/cq/sightly/WCMUse.html#... 

ResourceResolver resourceResolver = getResourceResolver(); Session session = resourceResolver.adaptTo(Session.class); String userId = session.getUserID();'

View solution in original post

2 Replies

Avatar

Correct answer by
Employee Advisor

You can get the userid from  the resource resolver object- https://docs.adobe.com/content/docs/en/aem/6-0/develop/ref/javadoc/com/adobe/cq/sightly/WCMUse.html#... 

ResourceResolver resourceResolver = getResourceResolver(); Session session = resourceResolver.adaptTo(Session.class); String userId = session.getUserID();'

Avatar

Level 4

kunal23 wrote...

You can get the userid from  the resource resolver object- https://docs.adobe.com/content/docs/en/aem/6-0/develop/ref/javadoc/com/adobe/cq/sightly/WCMUse.html#... 

  1. ResourceResolver resourceResolver = getResourceResolver();
  2. Session session = resourceResolver.adaptTo(Session.class);
  3. String userId = session.getUserID();'

 

 

Hey Thanks Kunal, I had done it so many times but got confused this time. Thanks for helping me out.