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
BedrockMission!

Learn More

View all

Sign in to view all badges

Custom Workflow Component - Iterate over Users

Avatar

Avatar
Affirm 3
Level 2
crich2784
Level 2

Likes

4 likes

Total Posts

32 posts

Correct Reply

2 solutions
Top badges earned
Affirm 3
Boost 3
Give Back
Validate 1
Boost 1
View profile

Avatar
Affirm 3
Level 2
crich2784
Level 2

Likes

4 likes

Total Posts

32 posts

Correct Reply

2 solutions
Top badges earned
Affirm 3
Boost 3
Give Back
Validate 1
Boost 1
View profile
crich2784
Level 2

22-05-2021

I have a custom workflow component that needs to look up a User in the AEM User repository.

 

Code is pretty simple:

resourceResolver = getResourceResolver(workflowSession);
UserManager userManager = resourceResolver.adaptTo(UserManager.class);
Iterator<Authorizable> userIterator = userManager.findAuthorizables("jcr:primaryType", "rep:User");
Iterator<Authorizable> groupIterator = userManager.findAuthorizables("jcr:primaryType", "rep:Group");
while (userIterator.hasNext()) {
   log.info("Getting user");
   Authorizable user = userIterator.next();
   if (!user.isGroup()) {
      log.info("User found: {}", user.getID());
   }
}

 

The output only finds "anonymous" user.  Is it a permissions issue?  How do I allow it to iterate through ALL users in AEM?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

551 likes

Total Posts

663 posts

Correct Reply

191 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

551 likes

Total Posts

663 posts

Correct Reply

191 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile
asutosh_jena
Level 10

23-05-2021

Hi @crich2784 

 

How are you getting the resource resolver? 

 

I just tried the below snippet on my instance and it gives me the complete list of users. I am retriving the resource resolver from workflow session.

I hope you are using "com.adobe.granite.workflow" API.

 

import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowProcess;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jcr.RepositoryException;
import java.util.Iterator;

@Component(service = WorkflowProcess.class, property = {"process.label=Get All User Process"})
public class GetAllUserWorkflowProcess implements WorkflowProcess {

private static final Logger log = LoggerFactory.getLogger(GetAllUserWorkflowProcess.class);

@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) {
log.info("***** :: execute :: Start :: *****");
try (ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class)) {
final UserManager userManager = resourceResolver.adaptTo(UserManager.class);
if (null != userManager) {
Iterator<Authorizable> userAuthorizables = userManager.findAuthorizables(JcrConstants.JCR_PRIMARYTYPE, UserConstants.NT_REP_USER);
userAuthorizables.forEachRemaining(user -> {
log.info("Getting User...");
try {
String id = user.getID();
log.info("User ID -> {}", id);
} catch (RepositoryException e) {
log.error("Error While getting User", e);
}
});
}
} catch (RepositoryException repoException) {
log.error("Error", repoException);
}
log.info("***** :: execute :: End :: *****");
}
}

 

Here is the output I get in log with the user details. Could not put all here due to character restrictions.

 

23.05.2021 13:04:23.691 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess ***** :: execute :: Start :: *****
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> varmstrong
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> imccoy
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> ksaner
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> zachary.mitchell@spambob.com
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> olive.pixley@spambob.com
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> cavery
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> willie.melton@dodgit.com
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> replication-receiver
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> campaign-remote
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> anonymous
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> admin
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting User...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess User ID -> test
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.693 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> screens-devices-master
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> screens-administrators
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> screens-we-retail-administrators
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> screens-we-retail-devices
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> analytics-administrators
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> af-template-script-writers
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> administrators
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> projects-we_retail-editor
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> projects-we_retail
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> projects-we_retail-owner
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> projects-administrators
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.694 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> projects-users
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> forms-submission-reviewers
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> forms-users
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-desert-hiking-rtpso-communitymanagers
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-sitecontentmanager
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-surfing-zcqya-members
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-wintersports-fqlju-communitymanagers
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-siteenablementmanagers
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-groupadministrators
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-communitymanagers
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-administrators
23.05.2021 13:04:23.695 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.696 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-moderators
23.05.2021 13:04:23.696 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.696 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-skiing-mfpcv-administrators
23.05.2021 13:04:23.696 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.696 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-surfing-zcqya-moderators
23.05.2021 13:04:23.696 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.696 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-wintersports-fqlju-members
23.05.2021 13:04:23.696 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Getting Group...
23.05.2021 13:04:23.696 *INFO* [JobHandler: /var/workflow/instances/server0/2021-05-23/user-list-model_3:/content] com.adobecommunity.core.workflows.GetAllUserWorkflowProcess Group ID -> community-community-rqlgn-skiing-mfpcv-members

com.adobecommunity.core.workflows.GetAllUserWorkflowProcess ***** :: execute :: End :: *****
 

Answers (1)

Answers (1)

Avatar

Avatar
Affirm 3
Level 2
crich2784
Level 2

Likes

4 likes

Total Posts

32 posts

Correct Reply

2 solutions
Top badges earned
Affirm 3
Boost 3
Give Back
Validate 1
Boost 1
View profile

Avatar
Affirm 3
Level 2
crich2784
Level 2

Likes

4 likes

Total Posts

32 posts

Correct Reply

2 solutions
Top badges earned
Affirm 3
Boost 3
Give Back
Validate 1
Boost 1
View profile
crich2784
Level 2

23-05-2021

I figured this out . . . the code was working as expected.  I went into configmgr and whitelisted all components and it worked.  The code, right or wrong, is working.  

Now I need to figure out a service account and not use the whitelisting.