I want to write some data to AEM, and the below code works fine for me in AEM 6.0 but not in AEM 6.1 , always throws a Login Exception as follows:
"Login Exception when obtaining a CRX User for the Service:'writeService'.org.apache.sling.api.resource.LoginException: Cannot derive user name for bundle group.tti.commons-service [395] and sub service writeService"
OSGI Config:
Code in my class:
import javax.jcr.Session;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
....
@Reference
private ResourceResolverFactory factory;
private ResourceResolver resourceResolverWriter;
private static Session adminSession;
...
...
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "writeService");
try {
resourceResolverWriter = factory.getServiceResourceResolver(param);
adminSession = resourceResolverWriter.adaptTo(Session.class);
...
} catch (LoginException e) {
...
}
Am i missing anything on AEM 6.1?
In AEM 6.1, service users must be system users, which effectively means that their node in the JCR is of type rep:SystemUser. These users cannot be used to log in normally, only by background processes. The admin user is not a system user, so you cannot use the admin user in a service user mapping like this. You have to create a new system user and assign them the appropriate permissions.
If you would like to read more of the background on this change, take a look at https://issues.apache.org/jira/browse/SLING-3854.