如何使用Jackrabbit在Java或JSP中获取CQ5 userInfo [英] How to get the CQ5 userInfo in java or jsp by using jackrabbit
问题描述
如何使用 org.apache.jackrabbit.api.security.user
来获取CQ5 userInfo,例如java或jsp中的名称和组信息??
在JSP / Java中,您可以将资源调整为 UserManager 类,并根据需要获取当前用户或列出所有用户和组
会话session = resourceResolver.adaptTo(Session.class);
UserManager userManager = resourceResolver.adaptTo(UserManager.class);
/ *获取当前用户* /
Authorizable auth = userManager.getAuthorizable(session.getUserID());
/ *获取可授权属性。使用相对路径* /
Value []名称= auth.getProperty( ./ profile / familyName);
/ *以获得它所属的组* /
Iterator< Group>组= auth.memberOf();
要列出所有用户或组,可以使用UserManger中可用的findAuthorizables()方法。 / p>
您也可以使用 CQ.User.getCurrentUser()
在JS中获取用户信息,该实例将返回当前的用户 ,您可以使用该属性访问用户的属性。
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.
这篇关于如何使用Jackrabbit在Java或JSP中获取CQ5 userInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!