Expand my Community achievements bar.

Check if workflow initiator can write to a path?

Avatar

Level 2

I need to create a workflow that allows the author to create pages in a specific path.  I want to check if the user has write access to the path they have requested.  The below code does not seem to work for all users.  Is there another way to check user permissions?

 

Map<String, Object> userImpersonationMap = new HashMap<>();
userImpersonationMap.put(ResourceResolverFactory.USER_IMPERSONATION, initiator);
ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(userImpersonationMap);
Session userSession = resourceResolver.adaptTo(Session.class);
boolean canAccessPath = userSession.hasPermission(destinationPagePath, Session.ACTION_ADD_NODE);

 

AEM 6.5.14

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

2 Replies

Avatar

Level 8

Hi @Brian_Vaughn 

The problem seems to be because you are using the 

resourceResolverFactory.getAdministrativeResourceResolver

which has been deprecated - https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolverFactory.html#g...

 

You can use getServiceResolver or if you need to use the user's session then you could try something as being done in below code -

https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/ad...

 

Thanks

Narendra

Avatar

Level 2

Hi @Brian_Vaughn 
I agree with solution provided by @narendragandhi , Try to get resource resolver from service user and if you are using resource resolver to get session then get session from workflow session instead of resource resolver.