Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

how get the user profile path(/home/users/username/profile) from the session?

Avatar

Level 2

I have got the session from the repository login (using username and password), now how to access the profile of the user from the session(/home/users/username/profile). In the end, I need user properties. The request could not be adopted to user properties since its still pointing to the anonymous user.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Dear Sharat,

Thank you for your quick response,

You should be able to adapt org.apache.jackrabbit.api.JackrabbitSession to Authorisable[1] and retrieve property you want.

E.g. instead of adapting to request, adapt to the session which holds user information you want to present.

[1] Authorizable (Apache Jackrabbit 2.6.10 API)

Regards,

Peter

View solution in original post

5 Replies

Avatar

Community Advisor

Dear Sharat,

Just to clarify,

When request comes in the user is not authenticated and is anonymous user. E.g. did not do any authorisation.

You want to serve user properties of another user(possibly system user) who is authenticated into repository to anonymous user?

Regards,

Peter

Avatar

Level 2

When the request comes in, the user is trying to signup. I want to access the same user properties( Node )  from the session which i got from the repository login (which call the External login module and creates the same user in aem) .

Avatar

Correct answer by
Community Advisor

Dear Sharat,

Thank you for your quick response,

You should be able to adapt org.apache.jackrabbit.api.JackrabbitSession to Authorisable[1] and retrieve property you want.

E.g. instead of adapting to request, adapt to the session which holds user information you want to present.

[1] Authorizable (Apache Jackrabbit 2.6.10 API)

Regards,

Peter

Avatar

Level 4

I dont know why you need the path but you can get the value,

I am getting logged in user property like this..(i am using AEM 6.2 )

Session session = slingRequest.getResourceResolver().adaptTo(Session.class);

UserManager userManager = AccessControlUtil.getUserManager(session);

if (session != null) {

final User currentUser = (User) userManager.getAuthorizable(session.getUserID());

userEmail = currentUser.getProperty(USER_EMAIL) != null ? currentUser.getProperty(USER_EMAIL)[0].getString() : null;

userName = currentUser.getProperty(USER_NAME) != null ? currentUser.getProperty(USER_NAME)[0].getString() : null;

here

USER_NAME = "./profile/familyName";

USER_EMAIL = "./profile/email";

rest properties you can look in crx /home/users/geometrixx/aparker@geometrixx.info/profile

Capture.PNG

same way you can get others also

Avatar

Level 2

Thanks !!

This is what i came up with

JackrabbitSession jaSession = (JackrabbitSession) session;

UserManager auth = jaSession.getUserManager();

Authorizable authorizable = auth.getAuthorizable(session.getUserID());

Then u can easily access the user path from there.