In AEM 6.1, there are lot of changes related to security. One of the important change is related to Admin Resource Resolver. Administrative Resource Resolver has always been used without much knowledge on the impacts on Security and Session related exceptions.
 In AEM 6.1, getAdministrativeResourceResolver() method is deprecated and should no longer be used. The alternate for getAdministrativeResourceResolver() is getServiceResourceResolver(). But the way to getServiceResourceResolver() is not that straight forward. Below steps will help you to get the resource resolver object.
Step 1: Create a system user
Go to /crx/explorer and click on “User Administration” link. On the popup, click on “Create System User” button, and enter the userid (anything you like).
Step 2: Provide appropriate permissions to the newly created “serviceuser”.
Go to User admin console and search for the system user you just created. Provide appropriate permissions for the service user. Basically, provide the permissions for the nodes where you need to use Resource Resolver to get the resource. (e.g., read and write permission on content and read permission on /etc/tags, etc).
Step 3: Add an entry in the “Apache Sling Service User Mapper Service”.
After creating the user and assigning appropriate permission, you need to add an entry in the “Apache Sling Service User Mapper Service”. This entry is to allow your bundle to access the permissions of the system user.
Go to Configuration Manager in the system console and search for “User Mapper Service”
<bundle symbolic name>:<any name of service>=<system user id>
*You need to add all the bundles that access the permissions of the system user. It can also be the bundle shipped with AEM.
If you see an error in the error log, which cannot access service for the specified package or bundle, it means you need to an entry for that bundle here.
Step 4: Get the Service Resource Resolver in code
Map<String, Object> param = new HashMap<String, Object>();
// writeService is the service name you gave in the configuration of user mapper service
param.put(ResourceResolverFactory.SUBSERVICE, “writeService”);
ResourceResolver resolver = resolverFactory.getServiceResourceResolver(param);
That’s it 🙂



Leave a comment