Skip to main content
olegd52630483
Level 2
Nov 5, 2015 9:09 PM UTC
Solved

AEM 6.1 ResourceResolver

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
Level 10
Nov 6, 2015 12:04 AM UTC

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 ?

3 replies

Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
Level 10
Nov 6, 2015 12:04 AM UTC

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 ?

Translate
Community Advisor
Nov 30, 2016 1:00 PM UTC

 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.

Translate
smacdonald2008
Level 10
Nov 30, 2016 4:34 PM UTC

See this video and article - it shows you this working: 

http://scottsdigitalcommunity.blogspot.ca/2014/12/querying-adobe-experience-manager-6.html

Translate