Ad Code

Monday, March 27, 2017

User Creation using AccountManagementService API in AEM 6.2 - Part1

When it comes to the right access to right person, creating users is the first thing which hit our mind.
Let us see how to create users in AEM6.2.
Initially users were getting created using AccountManager API and but now this is deprecated in AEM6.2
After doing POC I came to know that “AccountManagement Service API” is extended with lot of new features.
Activation of AccountManagementService in Felix Console  
Before using any OSGi Service, ideally it should be in "active" state but AccountManagement Service was in "unsatisfied" state when i checked it.
Fig- Account Management Service in Unsatisfied State

Follow the below Steps to make this Service in active State:
Fig- Configure Day CQ Mail Service
  • The email id which is configured in "Day CQ Mail Service", should turn on the "less secure apps" of google account.
  • To turn it on Click here.
turn on.PNG
Fig- Turn On Less Secure Apps of gmail account
  • Now AccountManagemntService is in "satisfied" and "active" state.
Fig- Account Management Service is in Satisified state

Explanation of AccountManagementService  API

AccountManagementService API provide the below method to create AEM User.
Fig- requestAccount() method of AccountManagementService API

Below are the parameters of requestAccount() method in detail:
  • UserId: UserId  is a name through which, the account will be created in AEM.
  • Pwd: This is the password of the user account.
  • Map<String,RequestParameter[]> properties : In this map, user's profile related all additional values can get stored. In this map “email” property must exist, because email is used for sending the mail to user to confirm or validate a newly created account
user profile.PNG
Fig- Storing properties 
  • requestUrl: API will get the host and port using this parameter which will help to create confirmation page URL. This URL will be sent to user via mail for verifying the account. Example: http://localhost:4502

Note: I have given the example of localhost, but this will not work in other environment i.e QA/UAT. For these environments, domains will be dynamically fetched from “DAY CQ Link Externalizer” configuration from Felix console

    • configPath: It is a path of the node(e.g., “/content/properties”) type of nt:unstructured , where below three properties need to be added:
    a) memberOf
    b) intermediatePath
      c) confirmationPage
    Fig- config path node with its properties
    Detailed explanation of above Properties:
    • memberOf : This property identifies that the user should be part of which group. If you don’t provide any value to memberOf property,the user become part of “everyone” group. Note: This is an optional field.
    • intermediatePath: By default , AEM users gets created under /home/users.Intermediate path is used to provide customized path for creation of users. Eg: sgaem. So here, all the users will be created under /home/users/sgaem. Note: This is an optional field.
    • confirmationPage: ConfirmationPage link will be sent to email id which is added by user in registeration details. Note: This field is mandatory.

    Functionality of requestAccount() method
    AccountCreation (1).jpg
    Fig- Flow of user creation using AccountManagementService API

    Follow the below Steps:
    • User fills the Account Creation form and submits it.
    signUp form.PNG

    • This Request received by the servlet  and the servlet calls the requestAccount() method of AccountManagementService API.

    • This method creates the user in AEM in disabled state and send a verification email to the user.
    Fig- Highlighted property shows that the user is in disable state

    mail message.PNG
    Fig- User gets the Account Verification Email 

    • The confirmation link page will be having a component named "emailConfirmation". The emailConfirmation.html contains.

    • User will click on verification link to enable the account in AEM.
    Fig- User become Enable After Verifying the link
    • Confirmation mail will be sent to user after verification.
    user-creation mail.PNG
    Fig- User gets email for Account Creation
    • Mission Accomplished: and created user can access the AEM instance with his own credentials
    But wait, below issue can screw all the happiness.

    Issue in using AccountManagementService API
    Issue :  Initially I used configPath as “/etc/properties” but accountManagementService.requestAccount() will throw nullPointerException.
    Solution: While checking the code,I came to know that AccountManagementService  API internally using below method to get the Session object.
    private Session getServiceSession()
      throws RepositoryException
       return this.repository.loginService("account-management-service",null);
    "account-management-service “ is a subService defined in User Mapper Configuration.
    Fig- Service User Mapper Service Configuration
    account manager.PNG
    Fig- Check the Permission of Service user
    "account manager" is a user correspond to "account-management-service" in "Apache Sling Service User Mapper Service Amendment" configuration, but account manager has only permissions for " /content".
    Note: The configPath should be under "/content" or you can give any hierarchy but “account-manager” user must have the permission of that particular configPath.

    Kindly share your feedback and contact us at for any query.

    Thanks and Happy Learning 😊

    Thursday, March 23, 2017

    Create Multiple Bundles in an AEM Maven Project


    In AEM, Maven provides multi-module architecture.

    What does it mean??
    It means that we can have different modules like bundle and content(core,ui.apps) in a single project.

    In this blog, we will discuss that how can we create multiple bundles in the same project.
    Initially, when we create an AEM Project, we always see two modules:
    1. Bundle
    2. Content
    Fig- Initial modules provided by maven-archetype

    These modules are defined under parent Pom.xml.
    Fig- Modules configuration in parent Pom.xml

    Problem Statement: I want to create multiple bundles in the same AEM Project. The use cases of doing this can be:

    • Need a bundle to run in publish instance only or need to deploy a bundle on the basis of specific locations.
    • Want to create multiple bundles in a single project on the basis of big functionalities like Login Module, Payment Module etc.

    Solution: It is very easy, you just need to follow the below Steps:
    • Create the new bundle by just copying the existing bundle of a project.
    add a new bundle.PNG
    Fig - New Bundle created by copying the existing bundle

    • Rename the bundle1 ( i.e., test) .Now In Pom.xml of Test bundle change the ArtifactID (Because artifact should be unique for each module of the project).
    Fig- Rename the copied bundle and change the artifact id in Pom.xml of new bundle

    • Change the “Bundle-SymbolicName”  in the Test Module Pom.xml.
    Fig- Change the Bundle-SymbolicName in Pom.xml of Test Module

    • Add a new module in parent Pom.xml.
    Fig- Adding Test Module in Parent Pom.xml

    • Content Pom.xml  contains the dependency of all the bundles, so we need to add the dependency of the new bundle(test-module) in this Pom.xml
    add dependency.PNG
    Fig- Add the dependency of Test Bundle in Content(ui.apps) Pom.xml

    • For deploying the bundles at any specific location we need to specify the location in the "target" (like install) and bundle ‘s groupId and artifactid in the embedded section.
    Fig- Configuring the embedded section in Content(ui.apps) Pom.xml

    • Now you just need to build the code and you can find the bundle’s jar at expected location as you configured in content Pom.xml in embedded section.
    Fig- Showing bundles at specific location
    By following the above steps you can create n number of bundles in a single AEM project.

    Find the git repository from here .

    If you have any query or suggestion then kindly comment or mail us at

    Thanks and Happy Learning 😊

    Monday, March 20, 2017

    Run Modes with Use Cases In AEM 6.2 - Part2


    In the Run Modes -Part1, We have discussed about the purpose of Run Modes.

    In this blog we will explore the purpose of Run Modes in detail:
    • OSGi Component Creation for a specific environment.
    • Bundle Creation for a specific environment.

    OSGi Component Creation for a specific environment
    Run Modes helps to create OSGi component for the specific environment.
    Problem Statement: To make OSGi Component to be available only for publish instance.
    Solution: To solve this problem, follow these two steps:
    • Annotate the component with “ConfigurationPolicy.REQUIRE
    • Make this configuration available under config.publish.

    Sample code of OSGi Component

    👉 Here “policy= ConfigurationPolicy.REQUIRE”  means that this component should be available as configuration created under config nodes. But Initially, this configuration will not exist  in felix console components
    So, to make it visible in Felix console of publish instance, You need to create configuration of this component (using Pid of OSGi Component) under config.publish node.

    Fig- Node name same as Pid of OSGi Component

    After addition of this configuration, you can see, the component will be available in Felix console in publish instance.
    Note: In other run modes, this component will not get executed because it is specified only for publish instance. If you want to use it in other run modes, you need to make it in other config as well. (eg:,

    Bundle Creation for a specific environment

    Run Modes is not only used for configurations, they can also be used to differentiate bundles based on the environments.
    Isn’t it sounds interesting??
    Problem Statement: Let Suppose, You have multiple bundles in a single project. like
    Bundle A” for  “Author” Environment.
    Bundle Bfor  “Publish” Environment
    Solution: So we need to make environment specific configuration for install folder.  (nt:folder)
                    => Bundle A.jar
    Install.publish (nt:folder)
                    => Bundle B.jar
    Fig- sgaem-test.jar for author and sgaem-bundle.jar for publish instance

    Note: If you are in publish instance, You will not able to see bundle "sgaem-test" in felix console and vice-Versa for author instance.

    Note: Here the question arises that how to create multiple bundles in an AEM Maven project? So stay tuned for next upcoming blog to get the answer of above question 👍.

    Kindly share your feedback and contact us at for any query.

    Thanks and Happy Learning 😊