Monday, July 20, 2015

AEM 6 | How to get Session and Resource Resolver

The following methods are deprecated:
  • ResourceResolverFactory.getAdministrativeResourceResolver
  • ResourceProviderFactory.getAdministrativeResourceProvider
  • SlingRepository.loginAdministrative
Now we can use the following code :
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "dummyuser");
resolver = resolverFactory.getServiceResourceResolver(param);
session = repository.loginService(null, null);


We need to set the service "Apache Sling Service User Mapper". Each entry is of the form 'bundleId [ ":" subServiceName ] "=" userName' where bundleId and subServiceName identify the service and userName defines the name of the user to provide to the service.  like : org.mysample.core:dummyuser=analyticsservice

Note The user (analyticsservice described in above example) node needs to have the following properties
  • jcr:primaryType="rep:SystemUser"
  • jcr:uuid="<some value>"
  • rep:principalName="<some value>"
  • rep:authorizableId="<some value>"
Also that the user *must not have* a password , and defined user must have sufficient permissions to perform the required tasks.
How to add system user :
  1. Logon to : http://localhost:4502/crx/explorer/index.jsp
  2. Click on User Administration .
  3. you will get screen popup (http://localhost:4502/crx/explorer/ui/usereditor.jsp?ck=1437378510768&Path=/home/users) , click on "Create System Users" as shown in snapshot below : 

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete