AEM 6.1 comes with lot of features, one of those is allowing developer or content authors to create system user from CRX explorer.
The focus of this tutorial is to have a clear understanding about:
- What is a System User in AEM.
- Why System Users are introduced in AEM 6.1.
- How to create a System User in AEM 6.1.
- How to define Service User mapper in Felix Console.
System User In AEM:-
Till AEM 6 we have the liberty to use any user as service user, for invoking and executing any service. But from AEM 6.1 there was a slight change on how to define the ServiceUserMapping and how the service user or system user has to be created.
If we try to assign any arbitrary user as service user in AEM 6.1 we would face below error :
org.apache.sling.api.resource.LoginException: Cannot derive user name for bundle ch.inside.cqblog-bundle  and sub service readService
Note:- From AEM 6.1 service users can only be mapped to system users (jcr:primaryType = rep:SystemUser).
Why System User are Introduced:-
Use of admin session and admin resource resolver through ResourceresolverFactory is now deprecated, that’s why from AEM 6.1 Adobe forces developers to create system users and map them to Service User Mapper in Felix Console.
- Prevent excessive use of administrative JCR Sessions and ResourceResolvers.
- Allow services access to ResourceResolvers and JCR Sessions without requiring to hard-code or configure passwords.
- Allow services to use service users and/or system user which are specially configured for service level access.
Create System User in AEM:-
A system user can either be created by definition in your application content package or manual creation in the CRX Explorer through “User Administration”. As this is a system user, no need to set a password.
- Go to CRX Explorer.
- Click on User Administration.
- Click on Create system User from Top Bar.
- UserId- testSystemUser (User Id of system user you want to assign)
- Intermediate Path – /home/users/system
Note:- Path where you want to store system user. If no path is provided it will store user at some arbitrary node. This field is optional, but it is always advisable to provide path so that it will be easy to track user.
- Click on Green check box.
- Your system user is successfully created.
- You can also view system user details from CRX DE at this path /home/user/system.
Define Service User Mapper in AEM :-
- Go to Felix Console configurations.
- Search for “service user mapper” configuration.
- Click on Plus sign against Apache sling Service User Mapper Service Amendment to create new factory configuration.
- Enter Service Mapping Details
- Enter entry in form of BundleId:subserviceName=userName.
- For example in below screenshot:
- bundleId = com.adobe.cq.cq-dms-tagmanager
- subServiceName =tagmanagement
- systemUser Name =tagmanagerservice