Expand my Community achievements bar.

SOLVED

username using client context

Avatar

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

Avatar

Correct answer by
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

Avatar

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

Avatar

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

Avatar

Correct answer by
Employee

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

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

Regards,

Justin