Return to site

Never use repository.loginAdministrative. Period!!!

Developers should never use repository.loginAdministrative  or repository.login(username,password)

Instead, use loginService(String subServiceName, String workspace) for providing Super User Access to the repository

Ex: session = repository.loginService(null, repository.getDefaultWorkspace());

Before AEM 6.1, it is allowed to use any user as service user, for invoking any service and from AEM 6.1 we should create a system user and define ServiceUserMapping

To use login service, you need to define a system user.

Note: system users don’t use password.

Steps to create System user:

  1. Login using “admin” credentials in crx explorer. http://localhost:4502/crx/explorer
  2. Select “User Administration” --> Select “Create System User” and create the user.
  3. Navigate to http://localhost:4502/useradmin --> Select the user and grant privileges to portion of the repository which the service should need access to.

Map the system user created with a bundle.

  1. Navigate to http://localhost:4502/system/console/configMgr
  2. Search for “Apache Sling Service User Mapper Service Ammendment”
  3. Click “+” and enter the bundle name and system user details in the “Service Mappings” field. For example:
    1. is the symbolic name of my bundle
    2. user is the System User created using crx explorer
The code can obtain a handled to ResourceResolver by passing the service user as a param...

Map<String, Object> param = new HashMap<String, Object>();

param.put(ResourceResolverFactory.SUBSERVICE, "FNAServiceUser");

try {

ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(param);



  1. The preferred way to map the system user is by creating a sling:osgiConfig, so you don’t need to manage it per environment.
  2. If you want to just use logged in user session then ResourceResolver API should be sufficient.
All Posts

Almost done…

We just sent you an email. Please click the link in the email to confirm your subscription!