1
votes

I want to upload a xml file into the AEM DAM. The xml file is sitemap.xml which I read using InputStream. But how do I write ResourceResolver ? ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null) is deprecated now. I am following this tutorial but facing this resource resolver problem. What will be the correct syntax ?

2
misleading title.awd

2 Answers

2
votes

You can now use resourceFactory.getServiceResourceResolver(paramMap) method of org.apache.sling.api.resource.ResourceResolverFactory.

ResourceResolver resourceResolver = null;
    try {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put(ResourceResolverFactory.SUBSERVICE, "writeService");
        resourceResolver = resourceFactory.getServiceResourceResolver(paramMap);
    } catch (LoginException e) {
        log.error("Login Exception : " + e);
    }

Also, Configure your subservice in Felix config manager in Apache Sling Service User Mapper Service as

<bundle Symbolic Name>:<sub-service name>=<system-user-name>

enter image description here

you also need to create System user using CRX Explorer and click on User Administration and give permission of the relative paths.

1
votes

The method resolverFactory.getAdministrativeResourceResolver() is deprecated for security reasons. This gave you an admin-session without any permission checking.

It is replaced by resolverFactory.getServiceResourceResolver(). This gives you a normal session with a pre-configured user. To configure it, go to the admin console (e.g. http://localhost:4502/system/console/configMgr ) and find the settings for Apache Sling Service User Mapper Service.

For your tuturial it is fair enough, just to use the admin user for your Bundle as service user.

Also look at the Adobe documentation for this issue: https://helpx.adobe.com/experience-manager/6-3/sites/administering/using/security-service-users.html