Thursday, February 23, 2017

Creating AEM service user and defining ACL package

From AEM6 , the usage of admin session is deprecated. In this post, i'll try to explain how to create the service user and get the session.  Also briefly explains how to create the ACL service package.

1) Create a system user
The service user is normal AEM user having enough permissions in required nodes. 

Go to http://localhost:4502/useradmin and create a user and provide proper permissions.

Sample user:  rsa-service-user


2) Create the service mapping Osgi configurations.

File: org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-rsa.xml

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
service.ranking="0"
user.mapping="[org.test.rsa-osgi:repositoryService=rsa-service-user]" />

This mapping is required for getting jcr session in specified Osgi bundles. Here "org.test.rsa-osgi" is orgi bundle name.

3) Getting service user session in Osgi service

// Getting Resource Resolver
ResourceResolver resourceResolver = null;
try {
final Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "repositoryService");
resourceResolver = resolverFactory.getServiceResourceResolver(param);
} catch (LoginException e) {
//
}

// Getting JCR session
Session session = null;
try {
session = repository.loginService("repositoryService", repository.getDefaultWorkspace());
} catch (RepositoryException e) {
//
}
return session;
}

4) Creating ACL package

You may create the ACL service package so it will be useful on deploying in higher environment.
In this package, we need to include rep policy path  and service user path.


The user path can be copied from edit user console.

Edit the package and select the option Overwrite in AC Handling for overwriting the access policies.





No comments:

Post a Comment