Find out a user or user group of a Page resource. | Community
Skip to main content
Level 2
November 1, 2017
Solved

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

  • November 1, 2017
  • 7 replies
  • 3370 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by manoj_devapath

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.

7 replies

manoj_devapath
Level 5
November 1, 2017

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?

smacdonald2008
Level 10
November 1, 2017

Excellent Response!!!

Level 2
November 1, 2017

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. 

smacdonald2008
Level 10
November 1, 2017

"  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.

manoj_devapath
manoj_devapathAccepted solution
Level 5
November 1, 2017

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.
Level 2
November 1, 2017

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

Ok Thank you. Let me try that.

Level 2
November 1, 2017

This Helps. Thanks a lot.