* Convenience method for adding a single privilege to a principal (user or
* role), typically jcr:all
*/
- public static void addPrivilege(Session session, String path,
+ public synchronized static void addPrivilege(Session session, String path,
String principal, String privilege) throws RepositoryException {
List<Privilege> privileges = new ArrayList<Privilege>();
privileges.add(session.getAccessControlManager().privilegeFromName(
/**
* Add privileges on a path to a {@link Principal}. The path must already
- * exist. Session is saved.
+ * exist. Session is saved. Synchronized to prevent concurrent modifications
+ * of the same node.
*/
- public static void addPrivileges(Session session, String path,
+ public synchronized static void addPrivileges(Session session, String path,
Principal principal, List<Privilege> privs)
throws RepositoryException {
+ // make sure the session is in line with the persisted state
+ session.refresh(false);
AccessControlManager acm = session.getAccessControlManager();
AccessControlList acl = getAccessControlList(acm, path);
acl.addAccessControlEntry(principal,
log.debug("Added privileges " + privBuf + " to " + principal
+ " on " + path);
}
+ session.refresh(true);
session.save();
}
/** Gets access control list for this path, throws exception if not found */
- public static AccessControlList getAccessControlList(
+ public synchronized static AccessControlList getAccessControlList(
AccessControlManager acm, String path) throws RepositoryException {
// search for an access control list
AccessControlList acl = null;
}
/** Clear authorizations for a user at this path */
- public static void clearAccessControList(Session session, String path,
- String username) throws RepositoryException {
+ public synchronized static void clearAccessControList(Session session,
+ String path, String username) throws RepositoryException {
AccessControlManager acm = session.getAccessControlManager();
AccessControlList acl = getAccessControlList(acm, path);
for (AccessControlEntry ace : acl.getAccessControlEntries()) {