Tuesday 12 April 2016

How to get Service Resource Resolver ?

Goal:

How to get Service Resource resolver ?

Explanation:

One of the Important change in AEM 6.1 securities is related to Admin Resourceresolver. In AEM 6.1 getAdministrativeResourceResolver has been deprecated other way to get this resourceresolver is using serviceResourceResolver.

Steps:

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).


Goto Useradmin console and provide required permissions for the user.

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.


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);


Now this resourceresolver is used as per the permissions given for the user.

No comments:

Post a Comment