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

你离开我真会死。 提交于 2019-12-18 08:31:13

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/22549502/how-to-get-the-cq5-userinfo-in-java-or-jsp-by-using-jackrabbit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!