在AEM 6.2中,CQ用户未使用Java添加到组中

时间:2016-09-08 16:38:09

标签: cq5 aem

我正在尝试在AEM中添加一个cq用户。我使用下面的代码。代码运行成功但用户未添加到组中。你能看到我在做错了吗?

 ResourceResolver resourceResolver = request.getResourceResolver();
              UserManager userManager = resourceResolver.adaptTo(UserManager.class);
            try {
                Authorizable authGroup= userManager.getAuthorizable("administrators");
                LOGGER.info("authorizable"+authGroup.toString());

                Group group = (Group) authGroup;
                Authorizable authUser = userManager.getAuthorizable("myuser");
                LOGGER.info("Before Groufp"+authUser.toString());
                boolean b=group.addMember(authUser);
                LOGGER.info("After Group"+authUser.toString());
                if(b){
                    LOGGER.info("success");
                }
                else{
                    LOGGER.info("failure");
                }


            } catch (RepositoryException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

1 个答案:

答案 0 :(得分:0)

您可以设置userManager.autoSave(true),也可以添加finally块,然后您可以执行以下操作:

Session session = userManager.adaptTo(Session.class)
if(session != null){
   session.save()
}

在此处阅读UserManager:https://docs.adobe.com/content/docs/en/aem/6-0/develop/ref/javadoc/org/apache/jackrabbit/api/security/user/UserManager.html