Hi @mario248,
In general information about user who replicated page is passed via session object you are using in replicate method of replicator. You will need specific user session and use it in replicate method to achieve what you want. You can get the session using impersonation, here are some code snippets that could be useful.
import com.day.cq.replication.Replicator;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationOptions;
import javax.jcr.SimpleCredentials;
@Reference
private Replicator replicator;
//...
Session impersonatedSession = getImpersonatedSession(session, "test-user");
replicator.replicate(impersonatedSession, ReplicationActionType.ACTIVATE, path, replicationOptions)
// session - workflow-process-service user session
// userId - id of user you want to impersonate
private Session getImpersonatedSession(Session session, String userId) {
return session.impersonate(new SimpleCredentials(userId, new char[0]))
}
or
import com.day.cq.replication.Replicator;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationOptions;
import javax.jcr.SimpleCredentials;
import org.apache.sling.jcr.api.SlingRepository;
@Reference
private Replicator replicator;
@Reference
private SlingRepository repository;
//...
Session impersonatedSession = getImpersonatedSession("test-user");
replicator.replicate(impersonatedSession, ReplicationActionType.ACTIVATE, path, replicationOptions)
// userId - id of user you want to impersonate
private Session getImpersonatedSession(String userId) {
return session.repository.impersonateFromService("workflow-process-service", new SimpleCredentials("author1", new char[0]), null)
}
!Please remember that user you will impersonate needs to have permission to replicate given page, in other case this will not work. So it's always good to have proper handling for this case, e.g. fallback to service user session.