Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Not able to get Resource Resolver

Avatar

Avatar
Validate 1
Level 2
prachiz
Level 2

Likes

4 likes

Total Posts

24 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 2
prachiz
Level 2

Likes

4 likes

Total Posts

24 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
prachiz
Level 2

29-03-2020

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

 

JCR Resource Resolver Service user

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,129 likes

Total Posts

6,140 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,129 likes

Total Posts

6,140 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile
kautuk_sahni
Community Manager

10-08-2020

Reply from @prachiz 

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"/>

Answers (2)

Answers (2)

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

591 likes

Total Posts

572 posts

Correct Reply

219 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

591 likes

Total Posts

572 posts

Correct Reply

219 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

30-03-2020

@prachiz,

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

prachiz

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!

prachiz
I have already configured the user under apps/<my app>/config/com.adobe.acs.commons.users.impl.EnsureServiceUser-excelServiceUser.xml
BrianKasingli
You should see an error within the error.log, can you please share the error code?
BrianKasingli

Can you find the service-user @ http://localhost:4502/crx/explorer/index.jsp ? Click on "user administration", then click on "find"; find "excel-service-user". The results returned should be a user, and also a property on that user of "system user" = true.

 

 

BrianKasingli
Then next step is to go into http://localhost:4502/useradmin, and find the user "excel-service-user". Ensure that this user have the correct privileges.
prachiz
I don't see any error in the error.log or my project log file. Not even login exception.
prachiz

I could see my service-user @ http://localhost:4502/crx/explorer/index.jsp. and Permissions are applied.

BrianKasingli
Would it be possible that getSession(); is never invoked? That might be the case.
prachiz

Method is invoked when I debug the code, debugger stops at

 resourceResolver = resourceResolverFactory.getServiceResourceResolver(authInfo);

At that point, I don't see any errors in log and debugger doesn't move further. I get the message on debug console that application is running. 

BrianKasingli

Try this:

 

Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "excel-service-user");
ResourceResolver rr = resourceResolverFactory.getServiceResourceResolver(param);

 

prachiz

@BrianKasingli Tried the code above but no luck! Seems like there are some issue with project creation. My OSGi bundle symbolic name doesn't have group id. Not sure whether it will affect the other functionalities or not.

prachiz

@BrianKasingli @Theo_Pendle Thanks for the help!
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"/>

 

BrianKasingli
Cheers, good to hear that you figured it out!

Avatar

Avatar
Validate 1
MVP
Theo_Pendle
MVP

Likes

236 likes

Total Posts

251 posts

Correct Reply

105 solutions
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 10
Ignite 1
View profile

Avatar
Validate 1
MVP
Theo_Pendle
MVP

Likes

236 likes

Total Posts

251 posts

Correct Reply

105 solutions
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 10
Ignite 1
View profile
Theo_Pendle
MVP

30-03-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?