Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Get the users from AEM group

chetan001
Level 2
Level 2

Hi All,

 

Appreciate your comments here.

 

Use case:   get the users from aem group then send the mails..  

 

This code is written in aem custom workflow.

 

Working fine :  when click on asset and initiate custom workflow . I am getting group and able to get users.

 

Not working case :  when adding asset to folder and using luncher/event handler initiate the custom workflow. In this case below group is coming null

 

JackrabbitSession jrSession=(JackrabbitSession) session;

                     UserManager userManager=jrSession.getUserManager();

                     Group group = (Group) userManager.getAuthorizable("GroupId");

                     log.info("group >>> "+group);

                   final Iterator<Authorizable> memberslist = group.getMembers();

                  

                           while (memberslist.hasNext()) {

                           final Authorizable user = memberslist.next();

                                  if (user != null && !user.isGroup() && user.getProperty("./profile/email") != null) {

                                         //EMAIL ADDRESS FOR MEMBERS

                                         Value[] usrEmail = user.getProperty("./profile/email");

                                         for(Value emailGroup : usrEmail) {

                                                log.info("emailGroup line 152>>> "+emailGroup);

                                         }

                                  }

                           }

 

 

1 Accepted Solution
kchaurasiya
Correct answer by
Level 6
Level 6

@chetan001 : Are you using any system user for the workflow? If you are already using then you can provide the permission on that user for the folders which is required for the workflow. Please check this.

 

Thank You.

 

Keshav Chaurasiya

 

View solution in original post

0 Replies
kchaurasiya
Correct answer by
Level 6
Level 6

@chetan001 : Are you using any system user for the workflow? If you are already using then you can provide the permission on that user for the folders which is required for the workflow. Please check this.

 

Thank You.

 

Keshav Chaurasiya

 

View solution in original post

Vijayalakshmi_S
Community Advisor
Community Advisor

Hi @chetan001,

From the code snippet you have shared, suggest to make below changes

  • Way we get UserManager Object:
  • Authorizable first before typecasting it to Group.

UserManager :

  • If you are using com.adobe.granite.workflow.WorkflowSession (extends Adaptable),

 

 

ResourceResolver rescResolver = wfSession.adaptTo(ResourceResolver.class);
UserManager userManager = rescResolver.adaptTo(UserManager.class);

 

 

  • If you are using com.day.cq.workflow.WorkflowSession (Doesn't extends Adaptable)
    • We need to create ResourceResolver(using System user with desired permissions/Service Resolver) from ResourceResolverFactory Service Reference

 

 

@Reference
private ResourceResolverFactory resFactory;

Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "demoService");
ResourceResolver rescResolver = null;
try {
   rescResolver = resFactory.getServiceResourceResolver(param);
} catch (LoginException e) {
   LOG.error("Login Exception={}", e.getMessage());
}

 

 

Authorizable First: (Check if authorizable is a group or no)

 

 

String userOrGroupId = "admin";
        try {
            Authorizable authorizable = userManagerResc.getAuthorizable(userOrGroupId);
            if (authorizable.isGroup()) {
                LOG.info("Id is a group");
                Group userGroup = (Group) authorizable;
                Iterator<Authorizable> declaredMembers = userGroup.getDeclaredMembers();
                while (declaredMembers.hasNext()) {
                    declaredMembers.next();
                }
            }
            else{
                LOG.info("It is a user !!");
            }
        } catch (RepositoryException e) {
            e.printStackTrace();
        }