Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Find out a user or user group of a Page resource.

Avatar

Level 2

Hi,

I am trying to find a user or user group who has access to the Page resource using APIs (Jackrabbit APIs) . I could not find any API which gives the Users or User Group of page resource. For ex: i have  a page resource /content/geometrix/mens.html , first i want to find out what user group has access to this resource. Use case for this scenarios is: Authors or users should have only read only access to that page.

Sri.

1 Accepted Solution

Avatar

Correct answer by
Level 6

As smacdonald2008​  mentioned you need a business logic to handle this in your servlet.

UserManager (Adobe AEM 6.0.0 API 6.0.0 API)  provides it.

look into this

Iterator<Authorizable>findAuthorizables(Query query)
          Return Authorizables that match a specific Query.
Iterator<Authorizable>findAuthorizables(String relPath, String value)
          Returns all Authorizables that have a property with the given relative path (or name) that matches the specified value.
Iterator<Authorizable>findAuthorizables(String relPath, String value, int searchType)
          Returns all Authorizables that have a property with the given relative path (or name) that matches the specified value.
AuthorizablegetAuthorizable(Principal principal)
          Get the Authorizable by its Principal.
AuthorizablegetAuthorizable(String id)
          Get the Authorizable by its id.

View solution in original post

7 Replies

Avatar

Level 6

public boolean hasWriteAccess(Resource resource , Session userSession) throws RepositoryException {

Node pageNode = resource.adaptTo(Node.class);

String path = pageNode.getPath();

  try {

    userSession.checkPermission(path, "add_node,set_property");

    if(pageNode.hasNode(JcrConstants.JCR_CONTENT)) {

      String contentNodePath = path + "/" + "jcr:content";

      userSession.checkPermission(contentNodePath, "add_node,set_property");

    }

  } catch(java.security.AccessControlException e) {

    return false;

  }

  return true;

}

reference :

Apache Sling :: Getting Resources and Properties in Sling

How do I check user privileges?

Avatar

Level 2

I think my problem is not clear. Let me explain that again.

Author has created a page (Mens.html) and also a user (user1) . Author assigned read only Access to user 1 for Mens.html resource. I have made few changes in the Side kick bar and introduced a new option (Send Email). When clicked, it calls Servlet, passing only the resourcepath which is mens.html. Using this resource path,  i  need to find out which users or user groups are associated to it then dynamically revoke access to this page after sending email. User is other than the Author. 

Avatar

Level 10

"  need to find out which users or user groups are associated to it" - meaning you want to find our which users has permissions. You still use the User Manager API.

Avatar

Correct answer by
Level 6

As smacdonald2008​  mentioned you need a business logic to handle this in your servlet.

UserManager (Adobe AEM 6.0.0 API 6.0.0 API)  provides it.

look into this

Iterator<Authorizable>findAuthorizables(Query query)
          Return Authorizables that match a specific Query.
Iterator<Authorizable>findAuthorizables(String relPath, String value)
          Returns all Authorizables that have a property with the given relative path (or name) that matches the specified value.
Iterator<Authorizable>findAuthorizables(String relPath, String value, int searchType)
          Returns all Authorizables that have a property with the given relative path (or name) that matches the specified value.
AuthorizablegetAuthorizable(Principal principal)
          Get the Authorizable by its Principal.
AuthorizablegetAuthorizable(String id)
          Get the Authorizable by its id.

Avatar

Level 2

Ok. Does the UserManager api returns the Users which are associated to that resource page?

Ok Thank you. Let me try that.