IN AEM - create a dedicated user account to set up a successful ResourceResolverFactory instance. See this code:
@Service
public class CustomerServiceImpl implements CustomerService {
/** Default log. */
protected final Logger log = LoggerFactory.getLogger(this.getClass());
private Session session;
//Inject a Sling ResourceResolverFactory
@Reference
private ResourceResolverFactory resolverFactory;
//Queries the AEM JCR for customer data and returns
//the data within an XML schema
public String getCustomerData(String filter) {
Customer cust = null;
List<Customer> custList = new ArrayList<Customer>();
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;
try {
//Invoke the adaptTo method to create a Session used to create a QueryManager
resolver = resolverFactory.getServiceResourceResolver(param);
session = resolver.adaptTo(Session.class);
NOTE: In AEM 6.1, service users must be system users, which effectively means that their node in the JCR is of type rep:SystemUser. These users cannot be used to log in normally, only by background processes. The admin user is not a system user, so you cannot use the admin user in a service user mapping like this. You have to create a new system user and assign them the appropriate permissions.If you would like to read more of the background on this change, take a look at https://issues.apache.org/jira/browse/SLING-3854.
This is explained in this AEM community article:
https://helpx.adobe.com/experience-manager/using/querying-experience-manager-sling.html