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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

I want to create service user using YAML Config & Access to get Resource Resolver.

Avatar

Level 1

Hello everyone, does anyone know how to create service user using yaml config (AC Tool) & How to get Resource Resolver for access jcr node.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Ashok67621, you will need to follow below 3 steps.

  1. Create yaml (using AC Tool) file definition to create system user and assign it to group (I have used administrator group as an example - but you can use any other group)
    - user_config:
    
         - custom-system-user:
           - isMemberOf: administrators
             path: /home/users/system/custom
             isSystemUser: true
  2. Add an entry in the Apache Sling Service User Mapper Service (it can be done manually from OSGi console, or via xml/config file) - below example shows config file usage.
    Name of the file: org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-custom.config
    service.ranking=I"0"
    user.mapping=["<bundle-symbolic-name>:<name-of-service>\=custom-system-user"]
  3. Get resource resolver instance that will use above user
    @Reference
    private ResourceResolverFactory resolverFactory;
    
    Map<String, Object> param = new HashMap<String, Object>();
    param.put(ResourceResolverFactory.SUBSERVICE, "name-of-service");
    
    ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(param);
1 Reply

Avatar

Correct answer by
Community Advisor

Hi @Ashok67621, you will need to follow below 3 steps.

  1. Create yaml (using AC Tool) file definition to create system user and assign it to group (I have used administrator group as an example - but you can use any other group)
    - user_config:
    
         - custom-system-user:
           - isMemberOf: administrators
             path: /home/users/system/custom
             isSystemUser: true
  2. Add an entry in the Apache Sling Service User Mapper Service (it can be done manually from OSGi console, or via xml/config file) - below example shows config file usage.
    Name of the file: org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-custom.config
    service.ranking=I"0"
    user.mapping=["<bundle-symbolic-name>:<name-of-service>\=custom-system-user"]
  3. Get resource resolver instance that will use above user
    @Reference
    private ResourceResolverFactory resolverFactory;
    
    Map<String, Object> param = new HashMap<String, Object>();
    param.put(ResourceResolverFactory.SUBSERVICE, "name-of-service");
    
    ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(param);