Announcement Announcement Module
Collapse
No announcement yet.
readAclById Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • readAclById

    all,

    what's the best way to add and remove a role (using GrantedAuthoritySid) to a ACL? i'm trying to implemented the concept of public/private for some objects? do i need to get the whole ACL for the object and figure out the index position of the ACE i want to remove by looping over the collection?

    thanks,
    deno

  • #2
    Is there a better way that what i have below? It seems odd that i need to delete and re-add the ACL if i want to remove several ACEs at once.

    Code:
        public void setGuidelinePublicAccess(Long guidelineId, boolean state) {
            ObjectIdentityImpl ident = new ObjectIdentityImpl(getGuideline(guidelineId));
            MutableAcl acl = (MutableAcl) aclService.readAclById(ident);
    
            if (state) {
                acl.insertAce(0, PermissionExtended.READ, new GrantedAuthoritySid("ROLE_ADMIN"), true);
                acl.insertAce(1, PermissionExtended.READ, new GrantedAuthoritySid("ROLE_AUTHOR"), true);
                acl.insertAce(2, PermissionExtended.READ, new GrantedAuthoritySid("ROLE_USER"), true);
                aclService.updateAcl(acl);
            } else {
                ArrayList<Sid> list = new ArrayList<Sid>();
                list.add(new GrantedAuthoritySid("ROLE_ADMIN"));
                list.add(new GrantedAuthoritySid("ROLE_AUTHOR"));
                list.add(new GrantedAuthoritySid("ROLE_USER"));
    
                int x = 0;
                aclService.deleteAcl(ident, true);
                MutableAcl updatedACL = aclService.createAcl(ident);
                for(AccessControlEntry entry : acl.getEntries()) {
                    if (!list.contains(entry.getSid()) || !entry.getPermission().equals(PermissionExtended.READ)) {
                        updatedACL.insertAce(x++, entry.getPermission(), entry.getSid(), true);
                    }
                }
                aclService.updateAcl(updatedACL);
            }
    
        }

    Comment

    Working...
    X