You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Joerg Hoh (Jira)" <ji...@apache.org> on 2021/07/16 12:20:00 UTC

[jira] [Commented] (OAK-9494) Check if a privilege name is included in a set/array of Privileges obtained from AccessControlManager.getPrivileges

    [ https://issues.apache.org/jira/browse/OAK-9494?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17382029#comment-17382029 ] 

Joerg Hoh commented on OAK-9494:
--------------------------------

[~angela]: yes, my usecase is just checking what privileges are already present.

Regarding your suggested approach:

{code}
Privilege readPrivilege = acMgr.privilegeFromName(Privilege.JCR_READ)
{code}

I did a quick test and found that this approach was slower than the comparing just the names (although I haven't done a full benchmark, but just a few random requests). Just guessing from the fact that this call can throw an {{AccessControlException}} I assume that it does a lot of validation which come with a certain overhead. And because I test for a number of privileges (4-8) this could get expensive in terms of time, especially when comparing it with string comparisons.

So the {{accessControlManger.getPrivileges(absPath)}} is absolutely fine for me, it's just that I need a performant and elegant solution to test this result for the presence of individual privileges. 


> Check if a privilege name is included in a set/array of Privileges obtained from AccessControlManager.getPrivileges
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: OAK-9494
>                 URL: https://issues.apache.org/jira/browse/OAK-9494
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>          Components: api, commons
>            Reporter: Joerg Hoh
>            Priority: Major
>
> I have a case where I need to check for a session if individual privileges are available for a specific node. For performance reasons I want to avoid to execute multiple calls to {{accessControlManager.hasPrivilege(...)}}, but get all Privileges of that node once and the set various flags based on the presene of certain privileges or not.
> I want to use something like this:
> {code}
> Set<String> applicablePrivilegeNames = ...(accessControlManager.getPrivileges(path))...
> boolean canAddChildNodes = applicablePrivilegeNames.contains(Privilege.JCR_ADD_CHILD_NODES);
> boolean canWrite = applicablePrivilegeNames.contains(Privilege.WRITE);
> {code}
> It should work with aggregates as well.
> Right now it's a bit problematic because {{privilege.getName()}} resolves to something like {{jcr:read}}, while the value of {{Privilege.JCR_READ}} is {{\{http://www.jcp.org/jcr/1.0}read}}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)