Not able to get Resource Resolver | Community
Skip to main content
Level 3
March 30, 2020
Solved

Not able to get Resource Resolver

  • March 30, 2020
  • 3 replies
  • 11323 views

Hi,

I am trying to read excel file and write it's content into JCR under content folder. For that, I am using ACS AEM Commons Ensure user. I could see that my service user is created and it has root read and content write access. However, I'm not able to create resource resolver object and get the session. I tried to debug the code, when my debugger reaches below step, nothing happens and debugger doesn't move further. 

resourceResolver = resourceResolverFactory.getResourceResolver(authInfo); 

I don't even see any errors in the logs. Below is the method in which I am trying to get the resource resolver object. Thanks in advance.

private Session getSession() throws LoginException {

ResourceResolver resourceResolver;
Session session = null;


final Map<String, Object> authInfo = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) "excel-service-user");
resourceResolver = resourceResolverFactory.getServiceResourceResolver(authInfo);

session = resourceResolver.adaptTo(Session.class);

logger.info("####### session ######### : " + session.getUserID());

return session;
}

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by kautuk_sahni

Reply from @aembee 

The issue is resolved. I was trying to register service user for com.<myapp>.core as below code, but my OSGi bundle symbolic name was core only, however, I'm not sure why bundle name didn't have artifact id. Ideally, BSN should have GroupID+ ArtifactID or ArtifactID. 

 user.mapping="com.<myapp>.core:excel-service-user=excel-service-user"/>

3 replies

Theo_Pendle
Level 8
March 30, 2020

Hi, 

 

This is not anything I've seen before unless you've made some configuration error. I do have one question though. If the data you are trying to manipulate is under the /content node, why are you using a service user (especially with root access)? Would it not be simpler and safer to use the session?

aembeeAuthor
Level 3
March 30, 2020

I'm trying to write the data into jcr node. I am reading an excel file from dam, parsing the data into model and then write the data under /content/<my_folder>. To write the data into jcr, I need service user.

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
March 30, 2020

@aembee,

Your source code looks correct. It seems like you might be having a system user and Apache Sling User Mapping Situation. Have you set up the Apache sling Service User Mapper Service Amendment Factory configuration? com.mysite.core:excel-service-user=my-system-user or the System User + ACL permissions? 

You're in luck. There is a step by step guide on how you can set up these two configurations: http://www.aemcq5tutorials.com/tutorials/create-system-user-in-aem

aembeeAuthor
Level 3
March 30, 2020

Hi,

I have already configured the user under apps/<my app>/config/com.adobe.acs.commons.users.impl.EnsureServiceUser-excelServiceUser.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"
aces="[type=allow;privileges=jcr:read\,rep:write;path=/content;rep:glob=/jcr:content/*]"
ensure-immediately="{Boolean}true"
principalName="excel-service-user"
type="add"/>

org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-excelServiceUser.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="{Long}0"
user.mapping="com.<myapp>.core:excel-service-user=excel-service-user"/>

Thanks!

kautuk_sahni
Community Manager
kautuk_sahniCommunity ManagerAccepted solution
Community Manager
August 10, 2020

Reply from @aembee 

The issue is resolved. I was trying to register service user for com.<myapp>.core as below code, but my OSGi bundle symbolic name was core only, however, I'm not sure why bundle name didn't have artifact id. Ideally, BSN should have GroupID+ ArtifactID or ArtifactID. 

 user.mapping="com.<myapp>.core:excel-service-user=excel-service-user"/>
Kautuk Sahni