username using client context | Community
Skip to main content
New Participant
October 16, 2015
Solved

username using client context

  • October 16, 2015
  • 4 replies
  • 1354 views

How to get the logged in username using client context. I tried following code, but got admin as output, where as i want output as user logged in the geometrixx website.

 Session session = resourceResolver.adaptTo(Session.class);
 String userName=session.getUserID();

i guess this can be done using client context. Can anyone help me out getting username from client context.

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by JustinEd3

In Javascript, you can do something like this to get the username:

CQ_Analytics.ClientContext.get("profile/authorizableId")

Regards,

Justin

4 replies

smacdonald2008
New Participant
October 16, 2015
smacdonald2008
New Participant
October 16, 2015

A ClientContext represents a dynamically assembled collection of user data - not really the logged in user. 

TO get user information/logged in users - you should  be using Jackrabbit User Manager API.

Here is a community article that talks about how to use this API from within an OSGi:

Developing AEM OSGi bundles that use Jackrabbit UserManager APIs

Here is a StackOverflow thread with more info:

http://stackoverflow.com/questions/22549502/how-to-get-the-cq5-userinfo-in-java-or-jsp-by-using-jackrabbit

New Participant
October 16, 2015

Hi smacdonald2008,

Thanks for responding. my ultimate aim is to get logged in user name and i have used the above said API only.

i have 2 users one is logged in to CQ5 and another logged in to geometrixx site.

i want geometrixx site user.

can u share any code snippet by which i can get logged in username.?

JustinEd3Accepted solution
Employee
October 16, 2015

In Javascript, you can do something like this to get the username:

CQ_Analytics.ClientContext.get("profile/authorizableId")

Regards,

Justin