Class AccessControlUtils
- java.lang.Object
-
- org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils
-
public class AccessControlUtils extends java.lang.ObjectThis class provides common access control related utilities.
-
-
Constructor Summary
Constructors Constructor Description AccessControlUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanaddAccessControlEntry(Session session, java.lang.String absPath, java.security.Principal principal, java.lang.String[] privilegeNames, boolean isAllow)A utility method to add a new access control entry.
Please note, that callingSession.save()is required in order to persist the changes.static booleanaddAccessControlEntry(Session session, java.lang.String absPath, java.security.Principal principal, Privilege[] privileges, boolean isAllow)A utility method to add a new access control entry.static booleanallow(Node node, java.lang.String principalName, java.lang.String... privileges)Allow certain privileges on a given node for a given principal.static booleanclear(Node node)Removes the access control list at a given node.static booleanclear(Node node, java.lang.String principalName)Removes all ACL entries for a principal on a given node.static booleanclear(Session session, java.lang.String absPath)Removes the access control list at the specified absolute path.static booleanclear(Session session, java.lang.String absPath, java.lang.String principalName)Removes all ACL entries for a principal at a given absolute path.static booleandeny(Node node, java.lang.String principalName, java.lang.String... privileges)Deny certain privileges on a node for a given principal.static booleandenyAllToEveryone(Session session, java.lang.String absPath)Utility to deny jcr:all privilege to the everyone group principal.static JackrabbitAccessControlListgetAccessControlList(AccessControlManager accessControlManager, java.lang.String absPath)Utility that combinesAccessControlManager.getApplicablePolicies(String)andAccessControlManager.getPolicies(String)to retrieve a modifiableJackrabbitAccessControlListfor the given path.
Note that the policy must bereappliedand the changes must be saved in order to make the AC modifications take effect.static JackrabbitAccessControlListgetAccessControlList(Session session, java.lang.String absPath)Utility that combinesAccessControlManager.getApplicablePolicies(String)andAccessControlManager.getPolicies(String)to retrieve a modifiableJackrabbitAccessControlListfor the given path.
Note that the policy must bereappliedand the changes must be saved in order to make the AC modifications take effect.static java.security.PrincipalgetEveryonePrincipal(Session session)Shortcut for callingPrincipalManager.getEveryone().static java.security.PrincipalgetPrincipal(Session session, java.lang.String principalName)Retrieves the principal with the specifiedprincipalName.static booleangrantAllToEveryone(Session session, java.lang.String absPath)Utility to grant jcr:all privilege to the everyone group principal.static java.lang.String[]namesFromPrivileges(Privilege... privileges)Retrieves the names of the specified privileges.static Privilege[]privilegesFromNames(AccessControlManager accessControlManager, java.lang.String... privilegeNames)Retrieves thePrivileges from the specified privilege names.static Privilege[]privilegesFromNames(Session session, java.lang.String... privilegeNames)Retrieves thePrivileges from the specified privilege names.
-
-
-
Method Detail
-
privilegesFromNames
public static Privilege[] privilegesFromNames(Session session, java.lang.String... privilegeNames) throws RepositoryException
Retrieves thePrivileges from the specified privilege names.- Parameters:
session- The editing session.privilegeNames- The privilege names.- Returns:
- An array of privileges.
- Throws:
RepositoryException- If an error occurs or ifprivilegeNamescontains an unknown/invalid privilege name.
-
privilegesFromNames
public static Privilege[] privilegesFromNames(AccessControlManager accessControlManager, java.lang.String... privilegeNames) throws RepositoryException
Retrieves thePrivileges from the specified privilege names.- Parameters:
accessControlManager- The access control manager.privilegeNames- The privilege names.- Returns:
- An array of privileges.
- Throws:
RepositoryException- If an error occurs or ifprivilegeNamescontains an unknown/invalid privilege name.
-
namesFromPrivileges
public static java.lang.String[] namesFromPrivileges(Privilege... privileges)
Retrieves the names of the specified privileges.- Parameters:
privileges- One or more privileges.- Returns:
- The names of the specified privileges.
-
getAccessControlList
public static JackrabbitAccessControlList getAccessControlList(Session session, java.lang.String absPath) throws RepositoryException
Utility that combinesAccessControlManager.getApplicablePolicies(String)andAccessControlManager.getPolicies(String)to retrieve a modifiableJackrabbitAccessControlListfor the given path.
Note that the policy must bereappliedand the changes must be saved in order to make the AC modifications take effect.- Parameters:
session- The editing session.absPath- The absolute path of the target node.- Returns:
- A modifiable access control list or null if there is none.
- Throws:
RepositoryException- If an error occurs.
-
getAccessControlList
public static JackrabbitAccessControlList getAccessControlList(AccessControlManager accessControlManager, java.lang.String absPath) throws RepositoryException
Utility that combinesAccessControlManager.getApplicablePolicies(String)andAccessControlManager.getPolicies(String)to retrieve a modifiableJackrabbitAccessControlListfor the given path.
Note that the policy must bereappliedand the changes must be saved in order to make the AC modifications take effect.- Parameters:
accessControlManager- TheAccessControlManager.absPath- The absolute path of the target node.- Returns:
- A modifiable access control list or null if there is none.
- Throws:
RepositoryException- If an error occurs.
-
addAccessControlEntry
public static boolean addAccessControlEntry(Session session, java.lang.String absPath, java.security.Principal principal, java.lang.String[] privilegeNames, boolean isAllow) throws RepositoryException
A utility method to add a new access control entry.
Please note, that callingSession.save()is required in order to persist the changes.- Parameters:
session- The editing session.absPath- The absolute path of the target node.principal- The principal to grant/deny privileges to.privilegeNames- The names of the privileges to grant or deny.isAllow-trueto grant;falseotherwise.- Returns:
trueif the node's ACL was modified and the session has pending changes.- Throws:
RepositoryException- If an error occurs.
-
addAccessControlEntry
public static boolean addAccessControlEntry(Session session, java.lang.String absPath, java.security.Principal principal, Privilege[] privileges, boolean isAllow) throws RepositoryException
A utility method to add a new access control entry. Please note, that a call toSession.save()is required in order to persist the changes.- Parameters:
session- The editing sessionabsPath- The absolute path of the target node.principal- The principal to grant/deny privileges to.privileges- The privileges to grant or denyisAllow-trueto grant;falseotherwise;- Returns:
trueif the node's ACL was modified and the session has pending changes.- Throws:
RepositoryException- If an error occurs.
-
grantAllToEveryone
public static boolean grantAllToEveryone(Session session, java.lang.String absPath) throws RepositoryException
Utility to grant jcr:all privilege to the everyone group principal. Please note, thatSession.save()is required in order to persist the changes.- Parameters:
session- The editing session.absPath- The absolute path of the target node- Returns:
trueif the node's access control list was modified;falseotherwise;- Throws:
RepositoryException- If an error occurs.
-
denyAllToEveryone
public static boolean denyAllToEveryone(Session session, java.lang.String absPath) throws RepositoryException
Utility to deny jcr:all privilege to the everyone group principal. Please note, thatSession.save()is required in order to persist the changes.- Parameters:
session- The editing session.absPath- The absolute path of the target node- Returns:
trueif the node's access control list was modified;falseotherwise;- Throws:
RepositoryException- If an error occurs.
-
allow
public static boolean allow(Node node, java.lang.String principalName, java.lang.String... privileges) throws RepositoryException
Allow certain privileges on a given node for a given principal.To activate the ACL change, session.save() must be called.
- Parameters:
node- node to set the resource-based ACL entry on; underlying session is used to write the ACLprincipalName- Name of the principal for which the ACL entry should applyprivileges- list of privileges to set by name (seePrivilege)- Returns:
trueif the node's ACL was modified and the session has pending changes.- Throws:
RepositoryException- If an unexpected repository error occurs
-
deny
public static boolean deny(Node node, java.lang.String principalName, java.lang.String... privileges) throws RepositoryException
Deny certain privileges on a node for a given principal.To activate the ACL change, session.save() must be called.
- Parameters:
node- node to set the resource-based ACL entry on; underlying session is used to write the ACLprincipalName- Name of the principal for which the ACL entry should applyprivileges- list of privileges to set by name (seePrivilege)- Returns:
trueif the node's ACL was modified and the session has pending changes.- Throws:
RepositoryException- If an unexpected repository error occurs
-
clear
public static boolean clear(Session session, java.lang.String absPath, java.lang.String principalName) throws RepositoryException
Removes all ACL entries for a principal at a given absolute path. If the specifiedprincipalNameisnullthe policy will be removed altogether.Modifications only take effect upon
Session.save().- Parameters:
session- The editing session.absPath- Absolute path of an existing node from which to remove ACL entries (or the policy)principalName- Name of the principal whose entries should be removed; usenullto clear the policy.- Returns:
trueif the policy has been modified;falseotherwise.- Throws:
RepositoryException- If an unexpected repository error occurs
-
clear
public static boolean clear(Node node, java.lang.String principalName) throws RepositoryException
Removes all ACL entries for a principal on a given node.Modification to the policy only take effect upon
Session.save()must be called.- Parameters:
node- node from which to remove ACL entries; underlying session is used to write the changesprincipalName- Name of the principal whose entries should be removed; usenullto clear the policy altogether.- Returns:
trueif the node's ACL was modified,falseotherwise.- Throws:
RepositoryException- If an unexpected repository error occurs
-
clear
public static boolean clear(Node node) throws RepositoryException
Removes the access control list at a given node.To persist the modifications,
Session.save()must be called.- Parameters:
node- node from which to remove the ACL; underlying session is used to write the changes- Returns:
trueif the node's ACL was removed,falseotherwise.- Throws:
RepositoryException- If an unexpected repository error occurs
-
clear
public static boolean clear(Session session, java.lang.String absPath) throws RepositoryException
Removes the access control list at the specified absolute path.To persist the modification, session.save() must be called.
- Parameters:
session- The editing session.absPath- An absolute path of a valid node accessible to the editing session from which to remove the ACL.- Returns:
trueif the node's ACL got removed,falseotherwise.- Throws:
RepositoryException- If an unexpected repository error occurs
-
getPrincipal
public static java.security.Principal getPrincipal(Session session, java.lang.String principalName) throws RepositoryException
Retrieves the principal with the specifiedprincipalName. Shortcut for callingPrincipalManager.getPrincipal(String).- Parameters:
session- The editing session which must be aJackrabbitSession.principalName- The name of the principal.- Returns:
- The principal with the specified name or
nullif no such principal exists. - Throws:
RepositoryException- If an error occurs or if the session is not aJackrabbitSession.
-
getEveryonePrincipal
public static java.security.Principal getEveryonePrincipal(Session session) throws RepositoryException
Shortcut for callingPrincipalManager.getEveryone().- Parameters:
session- The editing session which must be aJackrabbitSession.- Returns:
- The group principal presenting everyone.
- Throws:
RepositoryException- If an error occurs or if the session is not aJackrabbitSession.
-
-