How to get the CQ5 userInfo by using org.apache.jackrabbit.api.security.user
like name and group information in java or jsp .?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With