use of org.apache.wiki.auth.acl.AclEntryImpl in project jspwiki by apache.
the class PageManager method changeAcl.
/**
* For a single wiki page, replaces all Acl entries matching a supplied array of Principals
* with a new Principal.
*
* @param page the wiki page whose Acl is to be modified
* @param oldPrincipals an array of Principals to replace; all AclEntry objects whose
* {@link AclEntry#getPrincipal()} method returns one of these Principals will be replaced
* @param newPrincipal the Principal that should receive the old Principals' permissions
* @return <code>true</code> if the Acl was actually changed; <code>false</code> otherwise
*/
protected boolean changeAcl(WikiPage page, Principal[] oldPrincipals, Principal newPrincipal) {
Acl acl = page.getAcl();
boolean pageChanged = false;
if (acl != null) {
Enumeration<AclEntry> entries = acl.entries();
Collection<AclEntry> entriesToAdd = new ArrayList<AclEntry>();
Collection<AclEntry> entriesToRemove = new ArrayList<AclEntry>();
while (entries.hasMoreElements()) {
AclEntry entry = entries.nextElement();
if (ArrayUtils.contains(oldPrincipals, entry.getPrincipal())) {
// Create new entry
AclEntry newEntry = new AclEntryImpl();
newEntry.setPrincipal(newPrincipal);
Enumeration<Permission> permissions = entry.permissions();
while (permissions.hasMoreElements()) {
Permission permission = permissions.nextElement();
newEntry.addPermission(permission);
}
pageChanged = true;
entriesToRemove.add(entry);
entriesToAdd.add(newEntry);
}
}
for (Iterator<AclEntry> ix = entriesToRemove.iterator(); ix.hasNext(); ) {
AclEntry entry = ix.next();
acl.removeEntry(entry);
}
for (Iterator<AclEntry> ix = entriesToAdd.iterator(); ix.hasNext(); ) {
AclEntry entry = ix.next();
acl.addEntry(entry);
}
}
return pageChanged;
}
Aggregations