How to save session on aem cloud using system resource resolver? | Community
Skip to main content
Level 2
July 12, 2022
Solved

How to save session on aem cloud using system resource resolver?

  • July 12, 2022
  • 1 reply
  • 2234 views

Not able to save the session with the system resource resolver. But able to save with request.getResourceResolver on cloud. System resource resolver value is not null when i debugged my code. Can someone please help me resolving this on cloud.

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 Asutosh_Jena_

Hi @rohinina 

 

If you are using a system user to get the resource resolver, please ensure to provide the correct read and write permission to the system user with the path where you are performing the write operation. If the permission are missing you will not be able to save.

 

You can set the permission using repository initializer.

org.apache.sling.jcr.repoinit.RepositoryInitializer-myproject.config

 

scripts=["
create service user service-user

set ACL on /content/myproject
allow jcr:read for service-user
allow jcr:write for service-user
end
"]

 

Thanks!

1 reply

Asutosh_Jena_
Community Advisor
Asutosh_Jena_Community AdvisorAccepted solution
Community Advisor
July 12, 2022

Hi @rohinina 

 

If you are using a system user to get the resource resolver, please ensure to provide the correct read and write permission to the system user with the path where you are performing the write operation. If the permission are missing you will not be able to save.

 

You can set the permission using repository initializer.

org.apache.sling.jcr.repoinit.RepositoryInitializer-myproject.config

 

scripts=["
create service user service-user

set ACL on /content/myproject
allow jcr:read for service-user
allow jcr:write for service-user
end
"]

 

Thanks!

RohiniNaAuthor
Level 2
July 12, 2022

Hi @asutosh_jena_ , 

 

I gave permissions as follows:

scripts=[
"
create service user service-user with path system
set ACL on /conf,/apps, /, /content/dam/project
allow jcr:read for service-user
end

# Add members to groups
add service-user to group administrators
"
]

 So, my service-user has admin rights. still nodes are not getting saved with session.save(), where session is created with service user.
When I debug through my code, I get resolver object and code is traversed till the end. I don't see any error in logs too. 

RohiniNaAuthor
Level 2
July 12, 2022

Hi @rohinina 

 

First of all you should not give administrator access to the system user as it defeats the purpose of system user.

Also I see you have given the read access to all the paths, instead of it, you should give read and write access to the path where you are writing the data.

 

Can you confirm which location you are trying to write the data? As you mentioned, you are able to save the session when using the request.ResourceResolver which is anonymous I feel it's must be somewhere you have the public access. Please confirm.

 

Thanks!


Thanks @asutosh_jena_ . Just to confirm if the issue is with permissions, I added user to the admin group. I will update the rights.

 

I'm trying to write the data under /content/project.
Basically, I'm creating nodes programatically and I want to save them.