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:
- Login using “admin” credentials in crx explorer. http://localhost:4502/crx/explorer
- Select “User Administration” --> Select “Create System User” and create the user.
- 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.
- Navigate to http://localhost:4502/system/console/configMgr
- Search for “Apache Sling Service User Mapper Service Ammendment”
- Click “+” and enter the bundle name and system user details in the “Service Mappings” field. For example: com.sk.test=user
- Com.sk.test is the symbolic name of my bundle
- user is the System User created using crx explorer
Map<String, Object> param = new HashMap<String, Object>();
ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(param);
- The preferred way to map the system user is by creating a sling:osgiConfig, so you don’t need to manage it per environment.
- If you want to just use logged in user session then ResourceResolver API should be sufficient.