Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the CQ5 userInfo in java or jsp by using jackrabbit

Tags:

aem

jackrabbit

How to get the CQ5 userInfo by using org.apache.jackrabbit.api.security.user like name and group information in java or jsp .?

like image 375
VAr Avatar asked Mar 21 '14 03:03

VAr


1 Answers

In JSP / Java you can adapt your resource to UserManager class and get the current user or list down all the users and groups as per your requirement.

    Session session = resourceResolver.adaptTo(Session.class);
    UserManager userManager = resourceResolver.adaptTo(UserManager.class);
    /* to get the current user */
    Authorizable auth = userManager.getAuthorizable(session.getUserID());
    /* to get the property of the authorizable. Use relative path */
    Value[] names = auth.getProperty("./profile/familyName");
    /* to get the groups it is member of */
    Iterator<Group> groups = auth.memberOf(); 

To list all the users or groups, you can use findAuthorizables() method available in the UserManger.

You can also obtain the User info in JS using CQ.User.getCurrentUser() which would return an instance of the current User, with which you can access the user's properties.

like image 111
rakhi4110 Avatar answered Oct 28 '22 06:10

rakhi4110