Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

AEM 6.1 ResourceResolver

Avatar

Level 3

This does not work:

private ResourceResolver getImpersonatedResolver(String userId) { Map<String, Object> param = new HashMap<>();    try {if(StringUtils.isNotBlank(userId)){ param.put(ResourceResolverFactory.USER_IMPERSONATION, userId);            return resourceResolverFactory.getResourceResolver(param);        } } catch (Exception e) {log.error(e.getLocalizedMessage(), e);    }return null;}

The following exception message appears:

Impersonation not allowed.
org.apache.sling.api.resource.LoginException: Impersonation not allowed.
    at org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory.getLoginException(JcrResourceProviderFactory.java:402)
    at org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory.handleImpersonation(JcrResourceProviderFactory.java:381)
    at org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory.getResourceProviderInternal(JcrResourceProviderFactory.java:344)
    at org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory.getResourceProvider(JcrResourceProviderFactory.java:209)
    at org.apache.sling.resourceresolver.impl.tree.ResourceProviderFactoryHandler.login(ResourceProviderFactoryHandler.java:172)
    at org.apache.sling.resourceresolver.impl.tree.RootResourceProviderEntry.loginToRequiredFactories(RootResourceProviderEntry.java:95)
    at org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl.getResourceResolverInternal(CommonResourceResolverFactoryImpl.java:257)
    at org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl.getResourceResolver(CommonResourceResolverFactoryImpl.java:158)
    at org.apache.sling.resourceresolver.impl.ResourceResolverFactoryImpl.getResourceResolver(ResourceResolverFactoryImpl.java:99)

Under AEM 6.0 it worked.

1 Accepted Solution

Avatar

Correct answer by
Level 10

It looks like logged in User doesnt have permission to impersonate the given userId. 

Have you configured the same for the logged in User in useradmin ?

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

It looks like logged in User doesnt have permission to impersonate the given userId. 

Have you configured the same for the logged in User in useradmin ?

Avatar

Level 9

 I do see the same problem at the last line, it is throwing the same exception

we have created writeService system user and added to administrators group (AEM 6.2)

Map<String, Object> param = new HashMap<String, Object>();        
                param.put(ResourceResolverFactory.SUBSERVICE, "writeService");
            adminResolver = resourceResolverFactory.getServiceResourceResolver(param);
            adminSession = adminResolver.adaptTo(Session.class);

userSession = adminSession.impersonate(new SimpleCredentials(member.getID(),"".toCharArray()));

29.11.2016 16:45:26.894 *ERROR* [JobHandler: /etc/workflow/instances/server0/2016-11-28_4/test2] com.abc.SingleMailGenerator Could not send email

javax.jcr.LoginException: Impersonation not allowed.