Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
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);

View solution in original post

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