Package org.apache.sling.jcr.base.util
Class AccessControlUtil
- java.lang.Object
-
- org.apache.sling.jcr.base.util.AccessControlUtil
-
public class AccessControlUtil extends java.lang.ObjectA simple utility class providing utilities with respect to access control over repositories.
-
-
Constructor Summary
Constructors Constructor Description AccessControlUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleanaddEntry(javax.jcr.security.AccessControlList acl, java.security.Principal principal, javax.jcr.security.Privilege[] privileges, boolean isAllow)Same asaddEntry(AccessControlList, Principal, Privilege[], boolean, Map)using some implementation specific restrictions.static booleanaddEntry(javax.jcr.security.AccessControlList acl, java.security.Principal principal, javax.jcr.security.Privilege[] privileges, boolean isAllow, java.util.Map restrictions)Adds an access control entry to the acl consisting of the specifiedprincipal, the specifiedprivileges, theisAllowflag and an optional map containing additional restrictions.static booleanaddEntry(javax.jcr.security.AccessControlList acl, java.security.Principal principal, javax.jcr.security.Privilege[] privileges, boolean isAllow, java.util.Map<java.lang.String,javax.jcr.Value> restrictions, java.util.Map<java.lang.String,javax.jcr.Value[]> mvRestrictions)Adds an access control entry to the acl consisting of the specifiedprincipal, the specifiedprivileges, theisAllowflag and an optional map containing additional restrictions.static javax.jcr.security.AccessControlManagergetAccessControlManager(javax.jcr.Session session)Returns theAccessControlManagerfor the givensession.static java.lang.StringgetPath(javax.jcr.security.AccessControlList acl)Returns the path of the nodeAccessControlListacl has been created for.static PrincipalManagergetPrincipalManager(javax.jcr.Session session)Returns thePrincipalManagerfor the givensession.static UserManagergetUserManager(javax.jcr.Session session)Returns theUserManagerfor the givensession.static booleanisAllow(javax.jcr.security.AccessControlEntry ace)Returns true if the AccessControlEntry represents 'allowed' rights or false it it represents 'denied' rights.static booleanisEmpty(javax.jcr.security.AccessControlList acl)ReturnstrueifAccessControlListacl does not yet define any entries.static voidreplaceAccessControlEntry(javax.jcr.Session session, java.lang.String resourcePath, java.security.Principal principal, java.lang.String[] grantedPrivilegeNames, java.lang.String[] deniedPrivilegeNames, java.lang.String[] removedPrivilegeNames)Deprecated.static voidreplaceAccessControlEntry(javax.jcr.Session session, java.lang.String resourcePath, java.security.Principal principal, java.lang.String[] grantedPrivilegeNames, java.lang.String[] deniedPrivilegeNames, java.lang.String[] removedPrivilegeNames, java.lang.String order)Replaces existing access control entries in the ACL for the specifiedprincipalandresourcePath.static voidreplaceAccessControlEntry(javax.jcr.Session session, java.lang.String resourcePath, java.security.Principal principal, java.lang.String[] grantedPrivilegeNames, java.lang.String[] deniedPrivilegeNames, java.lang.String[] removedPrivilegeNames, java.lang.String order, java.util.Map<java.lang.String,javax.jcr.Value> restrictions, java.util.Map<java.lang.String,javax.jcr.Value[]> mvRestrictions, java.util.Set<java.lang.String> removedRestrictionNames)Replaces existing access control entries in the ACL for the specifiedprincipalandresourcePath.static intsize(javax.jcr.security.AccessControlList acl)Returns the number of acl entries or 0 if the acl is empty.
-
-
-
Method Detail
-
getAccessControlManager
public static javax.jcr.security.AccessControlManager getAccessControlManager(javax.jcr.Session session) throws javax.jcr.UnsupportedRepositoryOperationException, javax.jcr.RepositoryExceptionReturns theAccessControlManagerfor the givensession. If the session does not have agetAccessControlManagermethod, aUnsupportedRepositoryOperationExceptionis thrown. Otherwise theAccessControlManageris returned or if the call fails, the respective exception is thrown.- Parameters:
session- The JCR Session whoseAccessControlManageris to be returned. If the session is a pooled session, the session underlying the pooled session is actually used.- Returns:
- The
AccessControlManagerof the session - Throws:
javax.jcr.UnsupportedRepositoryOperationException- If the session has nogetAccessControlManagermethod or the exception thrown by the method.javax.jcr.RepositoryException- Forwarded from thegetAccessControlManagermethod call.
-
getUserManager
public static UserManager getUserManager(javax.jcr.Session session) throws javax.jcr.AccessDeniedException, javax.jcr.UnsupportedRepositoryOperationException, javax.jcr.RepositoryException
Returns theUserManagerfor the givensession. If the session does not have agetUserManagermethod, aUnsupportedRepositoryOperationExceptionis thrown. Otherwise theUserManageris returned or if the call fails, the respective exception is thrown.- Parameters:
session- The JCR Session whoseUserManageris to be returned. If the session is not aJackrabbitSessionuses reflection to retrive the manager from the repository.- Returns:
- The
UserManagerof the session. - Throws:
javax.jcr.AccessDeniedException- If this session is not allowed to access user data.javax.jcr.UnsupportedRepositoryOperationException- If the session has nogetUserManagermethod or the exception thrown by the method.javax.jcr.RepositoryException- Forwarded from thegetUserManagermethod call.
-
getPrincipalManager
public static PrincipalManager getPrincipalManager(javax.jcr.Session session) throws javax.jcr.AccessDeniedException, javax.jcr.UnsupportedRepositoryOperationException, javax.jcr.RepositoryException
Returns thePrincipalManagerfor the givensession. If the session does not have aPrincipalManagermethod, aUnsupportedRepositoryOperationExceptionis thrown. Otherwise thePrincipalManageris returned or if the call fails, the respective exception is thrown.- Parameters:
session- The JCR Session whosePrincipalManageris to be returned. If the session is not aJackrabbitSessionuses reflection to retrive the manager from the repository.- Returns:
- The
PrincipalManagerof the session. - Throws:
javax.jcr.AccessDeniedException- If the current user lacks sufficient privilegesjavax.jcr.UnsupportedRepositoryOperationException- If the session has noPrincipalManagermethod or the exception thrown by the method.javax.jcr.RepositoryException- Forwarded from thePrincipalManagermethod call.
-
getPath
public static java.lang.String getPath(javax.jcr.security.AccessControlList acl) throws javax.jcr.RepositoryExceptionReturns the path of the nodeAccessControlListacl has been created for.- Parameters:
acl- The acl to get the path for- Returns:
- the path for the acl
- Throws:
javax.jcr.RepositoryException- Forwarded from thegetPathmethod call.
-
isEmpty
public static boolean isEmpty(javax.jcr.security.AccessControlList acl) throws javax.jcr.RepositoryExceptionReturnstrueifAccessControlListacl does not yet define any entries.- Parameters:
acl- The acl to check- Returns:
- true if the acl is empty, false otherwise
- Throws:
javax.jcr.RepositoryException- Forwarded from theisEmptymethod call.
-
size
public static int size(javax.jcr.security.AccessControlList acl) throws javax.jcr.RepositoryExceptionReturns the number of acl entries or 0 if the acl is empty.- Parameters:
acl- The acl to get the size of- Returns:
- the size of the acl
- Throws:
javax.jcr.RepositoryException- Forwarded from thesizemethod call.
-
addEntry
public static boolean addEntry(javax.jcr.security.AccessControlList acl, java.security.Principal principal, javax.jcr.security.Privilege[] privileges, boolean isAllow) throws javax.jcr.security.AccessControlException, javax.jcr.RepositoryExceptionSame asaddEntry(AccessControlList, Principal, Privilege[], boolean, Map)using some implementation specific restrictions.- Parameters:
acl- the list to add the new entry toprincipal- the principal for the user or group to add the entry forprivileges- the set of privileges to grant or denyisAllow- try to grant the privileges or false to deny the privileges- Returns:
trueif this policy was modified,falseotherwise.- Throws:
javax.jcr.security.AccessControlException- If any of the given parameter is invalid or cannot be handled by the implementation.javax.jcr.RepositoryException- if any other error occurs.
-
addEntry
public static boolean addEntry(javax.jcr.security.AccessControlList acl, java.security.Principal principal, javax.jcr.security.Privilege[] privileges, boolean isAllow, java.util.Map restrictions) throws javax.jcr.UnsupportedRepositoryOperationException, javax.jcr.RepositoryExceptionAdds an access control entry to the acl consisting of the specifiedprincipal, the specifiedprivileges, theisAllowflag and an optional map containing additional restrictions.- Parameters:
acl- the list to add the new entry toprincipal- the principal for the user or group to add the entry forprivileges- the set of privileges to grant or denyisAllow- try to grant the privileges or false to deny the privilegesrestrictions- (optional) additional restrictions to filter the scope of the added entry. The value of the map must be aValueorValue- Returns:
trueif this policy was modified,falseotherwise.- Throws:
javax.jcr.UnsupportedRepositoryOperationException- if the repository doesn't support adding access control entriesjavax.jcr.RepositoryException- if any other error occurs.
-
addEntry
public static boolean addEntry(javax.jcr.security.AccessControlList acl, java.security.Principal principal, javax.jcr.security.Privilege[] privileges, boolean isAllow, java.util.Map<java.lang.String,javax.jcr.Value> restrictions, java.util.Map<java.lang.String,javax.jcr.Value[]> mvRestrictions) throws javax.jcr.UnsupportedRepositoryOperationException, javax.jcr.RepositoryExceptionAdds an access control entry to the acl consisting of the specifiedprincipal, the specifiedprivileges, theisAllowflag and an optional map containing additional restrictions.- Parameters:
acl- the list to add the new entry toprincipal- the principal for the user or group to add the entry forprivileges- the set of privileges to grant or denyisAllow- try to grant the privileges or false to deny the privilegesrestrictions- (optional) additional single-value restrictions to filter the scope of the added entrymvRestrictions- (optional) additional multi-value restrictions to filter the scope of the added entry- Returns:
trueif this policy was modified,falseotherwise.- Throws:
javax.jcr.UnsupportedRepositoryOperationException- if the repository doesn't support adding access control entriesjavax.jcr.RepositoryException- if any other error occurs.
-
replaceAccessControlEntry
@Deprecated public static void replaceAccessControlEntry(javax.jcr.Session session, java.lang.String resourcePath, java.security.Principal principal, java.lang.String[] grantedPrivilegeNames, java.lang.String[] deniedPrivilegeNames, java.lang.String[] removedPrivilegeNames) throws javax.jcr.RepositoryExceptionDeprecated.Replaces existing access control entries in the ACL for the specifiedprincipalandresourcePath. Any existing granted or denied privileges which do not conflict with the specified privileges are maintained. Where conflicts exist, existing privileges are dropped. The end result will be at most two ACEs for the principal: one for grants and one for denies. Aggregate privileges are disaggregated before checking for conflicts.- Parameters:
session- the JCR session of the user doing the workresourcePath- the path of the resource to replace the entry onprincipal- the principal for the user or group to add the entry forgrantedPrivilegeNames- the names of the privileges to grantdeniedPrivilegeNames- the names of the privileges to denyremovedPrivilegeNames- privileges which, if they exist, should be removed for this principal and resource- Throws:
javax.jcr.RepositoryException- if any error occurs.
-
replaceAccessControlEntry
public static void replaceAccessControlEntry(javax.jcr.Session session, java.lang.String resourcePath, java.security.Principal principal, java.lang.String[] grantedPrivilegeNames, java.lang.String[] deniedPrivilegeNames, java.lang.String[] removedPrivilegeNames, java.lang.String order) throws javax.jcr.RepositoryExceptionReplaces existing access control entries in the ACL for the specifiedprincipalandresourcePath. Any existing granted or denied privileges which do not conflict with the specified privileges are maintained. Where conflicts exist, existing privileges are dropped. The end result will be at most two ACEs for the principal: one for grants and one for denies. Aggregate privileges are disaggregated before checking for conflicts.- Parameters:
session- the JCR session of the user doing the workresourcePath- the path of the resource to replace the entry onprincipal- the principal for the user or group to add the entry forgrantedPrivilegeNames- the names of the privileges to grantdeniedPrivilegeNames- the names of the privileges to denyremovedPrivilegeNames- privileges which, if they exist, should be removed for this principal and resourceorder- where the access control entry should go in the list. Value should be one of these:Values null If the ACE for the principal doesn't exist add at the end, otherwise leave the ACE at it's current position. first Place the target ACE as the first amongst its siblings last Place the target ACE as the last amongst its siblings before xyz Place the target ACE immediately before the sibling whose name is xyz after xyz Place the target ACE immediately after the sibling whose name is xyz numeric Place the target ACE at the specified numeric index - Throws:
javax.jcr.RepositoryException- if any error occurs.
-
replaceAccessControlEntry
public static void replaceAccessControlEntry(javax.jcr.Session session, java.lang.String resourcePath, java.security.Principal principal, java.lang.String[] grantedPrivilegeNames, java.lang.String[] deniedPrivilegeNames, java.lang.String[] removedPrivilegeNames, java.lang.String order, java.util.Map<java.lang.String,javax.jcr.Value> restrictions, java.util.Map<java.lang.String,javax.jcr.Value[]> mvRestrictions, java.util.Set<java.lang.String> removedRestrictionNames) throws javax.jcr.RepositoryExceptionReplaces existing access control entries in the ACL for the specifiedprincipalandresourcePath. Any existing granted or denied privileges which do not conflict with the specified privileges are maintained. Where conflicts exist, existing privileges are dropped. The end result will be at most two ACEs for the principal: one for grants and one for denies. Aggregate privileges are disaggregated before checking for conflicts.- Parameters:
session- the JCR session of the user doing the workresourcePath- the path of the resource to replace the entry onprincipal- the principal for the user or group to add the entry forgrantedPrivilegeNames- the names of the privileges to grantdeniedPrivilegeNames- the names of the privileges to denyremovedPrivilegeNames- privileges which, if they exist, should be removed for this principal and resourceorder- where the access control entry should go in the list. Value should be one of these:Values null If the ACE for the principal doesn't exist add at the end, otherwise leave the ACE at it's current position. first Place the target ACE as the first amongst its siblings last Place the target ACE as the last amongst its siblings before xyz Place the target ACE immediately before the sibling whose name is xyz after xyz Place the target ACE immediately after the sibling whose name is xyz numeric Place the target ACE at the specified numeric index restrictions- (optional) additional single-value restrictions to filter the scope of the replaced entrymvRestrictions- (optional) additional multi-value restrictions to filter the scope of the replaced entryremovedRestrictionNames- optional set of restriction names that should be removed (if they already exist).- Throws:
javax.jcr.RepositoryException- if any error occurs.
-
isAllow
public static boolean isAllow(javax.jcr.security.AccessControlEntry ace) throws javax.jcr.RepositoryExceptionReturns true if the AccessControlEntry represents 'allowed' rights or false it it represents 'denied' rights.- Parameters:
ace- the access control entry to check- Returns:
- true if the entry represents allowed rights of ralse otherwise
- Throws:
javax.jcr.RepositoryException- Forwarded from theisAllowmethod call.
-
-