I have implemented Sling Content Distribution (of type Sync Distribution) to sync nodes from one publisher to another publisher. I am using a custom trigger based on ResourceChangeListener, only looking for added events under the path /home/users/IDCS. Use case being i am only trying to sync new created users as i have enabled encapsulation token support and want to ensure newly created users are synced across publishers.
I am able to sync the top level user nodes ( like /home/users/IDCS/ymk6sYtFij-x_-UkAyF_) across the publishers, How can i sync the group this user is part of in Publisher A to Publisher B, what nodes do i have to send to another publisher so the permissions are also synced?Below is the code to trigger an event to the sync Agent that i have configured called "simple-agent".
package com.abc.test.core.services.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.resource.observation.ResourceChange;
import org.apache.sling.api.resource.observation.ResourceChangeListener;
import org.apache.sling.distribution.DistributionRequestType;
import org.apache.sling.distribution.Distributor;
import org.apache.sling.distribution.SimpleDistributionRequest;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(
service = ResourceChangeListener.class,
property = {
ResourceChangeListener.PATHS + "=/home/users",
ResourceChangeListener.CHANGES + "=ADDED"
}
)
public class UsersAddedDistributor implements ResourceChangeListener {
private static final Logger LOG = LoggerFactory.getLogger(UsersAddedDistributor.class);
@Reference
private ResourceResolverFactory rrf;
@Reference
private Distributor distributor;
@Override
public void onChange(List<ResourceChange> changes) {
for (ResourceChange ch : changes) {
String path = ch.getPath();
LOG.info("Detected ADD event at path: {}", path);
Map<String, Object> auth = new HashMap<>();
auth.put(ResourceResolverFactory.SUBSERVICE, "simple_svc");
try (ResourceResolver resolver = rrf.getServiceResourceResolver(auth)) {
Resource res = resolver.getResource(path);
if (res == null) {
LOG.warn("Resource not found at {}", path);
continue;
}
ValueMap vm = res.getValueMap();
String primaryType = vm.get("jcr:primaryType", String.class);
if ("rep:User".equals(primaryType)) {
LOG.info("rep:User detected at {} — triggering distribution", path);
distributor.distribute(
"simple-agent",
resolver,
new SimpleDistributionRequest(DistributionRequestType.ADD, path)
);
} else {
LOG.debug("Skipping non-user node at {}", path);
}
} catch (LoginException e) {
LOG.error("Error obtaining service resolver for {}", path, e);
} catch (Exception e) {
LOG.error("Error distributing path {}", path, e);
}
}
}
}
Regards,