April 10, 2020
Estimated Post Reading Time ~

Create users in AEM from excel file

Sometimes it so happens that we need to create many users in the AEM and to add them to the desired group. We can do this in the AEM Useradmin console manually. But this process is tedious and inefficient.

In most of the cases, we get the users in a file with their details (first name, last name, username, group, email, password, etc.). Wouldn't it be easier if we just upload the file in our AEM instance and the users are created in the AEM server automatically?

Therefore, I decided to create an AEM project that does exactly that. In this project, a user can go to a custom console that is created and upload an excel file with the details of the users.

Let's go through the steps one by one -

Step #1

Clone and build the AEM project from here. You may need to change the uber jar version as per your need in the project's parent pom.xml.

Step #2

Create a system user with the name createUsersServiceUser from /crx/explorer and add it to the administrators group from the useradmin console.

Step #3

Navigate to ./system/console/configMgr and search for the term Apache Sling Service User Mapper Service and create the following mapping as shown below
Create a service user mapping

Step #4

Step #5

Click on the Bulk Users icon as shown below
Click in the 'Bulk Users' icon

Step #6

Now, you will get a screen where you can upload your excel file (.xlsx) with the user details. After you click on the "Upload" button, your users will be created in the AEM.
As of now, the excel file should look like this
Sample Excel file with user details

Caution:

For this project, we have overlayed the path /libs/cq/core/content/nav/tools into /apps/bulkusercreation/cq/core/content/nav/tools. Since the overlayed path is not directly in /apps but in /apps/bulkusercreation, we have to change the sling resource resolver setting in the system. 

We can do this by navigating to the ./system/console/configMgr and search for Apache Sling Resource Resolver Factory and change the Resource Search path from /apps to /apps/bulkusercreation and save.
Apache Sling Resource Resolver Factory configuration
However, if you do not wish to change the default configuration, you just have to move /apps/bulkusercreation/cq to /apps/cq in crx/de.

Conclusion

The Bulk User Creation utility enables you to just upload an excel file with the user details and your work is done.

If you wish to see the complete code of this project and contribute towards the same with your suggestions and code, then you can find it on my GitHub.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.