Hi @jhansi_123 ,
Please refer below sample code to create a system user (custom-system-user) with (read, write and replicate) permissions from code.
Step1) create the service user in your code.
you will have to create folders under /content/jcr_root to maintain the structure /home/users/system/custom-system-user like and update the .content.xml as below
src/main/content/jcr_root/home/users/system/custom-system-user/.content.xml
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
jcr:primaryType="rep:SystemUser"
rep:authorizableId="custom-system-user"
rep:principalName="custom-system-user"/>
Step2) provide permissions by creating an _rep_policy.xml file as under src/main/content/jcr_root/content/_rep_policy.xml
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:crx="http://www.day.com/crx/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
jcr:primaryType="rep:ACL">
<allow
jcr:primaryType="rep:GrantACE"
rep:principalName="custom-system-user"
rep:privileges="{Name}[jcr:read,crx:replicate,rep:write]"/>
</jcr:root>
Step3) then add these paths in src/main/content/META-INF/vault/filter.xml
<filter root="/home/users/system/custom-system-user"/>
<filter root="/content/rep:policy"/>
Note - you may remove the filters after the first build so this wont be created with each build but just the first time for the instance.
manual step reference - https://www.aemcq5tutorials.com/tutorials/create-system-user-in-aem/
Cheers!