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

username using client context

khalidMomin
Level 4
Level 4

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.

1 Accepted Solution
justin_at_adobe
Correct answer by
Employee
Employee

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

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

Regards,

Justin

View solution in original post

4 Replies
smacdonald2008
Level 10
Level 10

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-jack...

khalidMomin
Level 4
Level 4

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.?

justin_at_adobe
Correct answer by
Employee
Employee

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

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

Regards,

Justin