Expand my Community achievements bar.

SOLVED

retrieve resourceresolver as logged in user

Avatar

Level 4

Hi

how do we retrieve resourceresolver on behalf of logged in user? in this case, am getting anonymous as value when getUserID() method is called. Also, what's the difference when we retrieve resource resolver via getResourceResolver(userInfo) and getThreadResourceResolver(). From the logs seems like they both reference to same resolver object instance and no difference in log values.

Map<String,Object> userInfo = new HashMap<String, Object>();

userInfo.put(ResourceResolverFactory.SUBSERVICE, "myuser");

ResourceResolver resourceResolver = resourceFactory.getResourceResolver(userInfo);

ResourceResolver resourceResolverCurrentThread = resourceFactory.getThreadResourceResolver();

            

logger.info("resource resolver {}",resourceResolver.toString());

logger.info("resource resolver {}",resourceResolver.getUserID());

logger.info("resource resolver {}",resourceResolver.isLive());

logger.info("thread resource resolver {}",resourceResolverCurrentThread.toString());

logger.info("thread resource resolver {}",resourceResolver.getUserID());

logger.info("thread resource resolver {}",resourceResolver.isLive());

1 Accepted Solution

Avatar

Correct answer by
Employee
4 Replies

Avatar

Employee

If you pass through things like resourceResolver /  resource from user's request you get the right object/permissions based on the user.

When getting the resource-resolver via the factory it is disconnected from the user

Avatar

Level 4

Hi

how do we retrieve from resourceresolver of user request?

Avatar

Correct answer by
Employee