alfrescoaclcmis

CMIS ACL remove permission only a user (on Alfresco)


I'm having trouble when I want to remove a permission from a single user, using openCMIS method Acl removeAcl(List removeAces, AclPropagation aclPropagation).

I have a document or folder several users with permission and I just want to remove the permission to single user.

This is the code I am using, to remove the user:

    OperationContext operationContext = new OperationContextImpl();
    operationContext.setIncludeAcls(true);
    Folder testFolder = (Folder) session.getObject("72deb421-3b8e-4268-9987-9c59a19f4a13");
    testFolder = (Folder) session.getObject(testDoc, operationContext);
    List<String> permissions = new ArrayList<String>();
    permissions.add("{http://www.alfresco.org/model/content/1.0}folder.Coordinator");
    String principal = "peter.sts";
    Ace aceIn = session.getObjectFactory().createAce(principal, permissions);
    List<Ace> aceListIn = new ArrayList<Ace>();
    aceListIn.add(aceIn);
    testDoc.removeAcl(aceListIn, AclPropagation.REPOSITORYDETERMINED);
    testDoc = (Folder) session.getObject(testDoc, operationContext);here

I have this user with this permission associated with a folder and want to remove, but only this user.

permissions.add("{http://www.alfresco.org/model/content/1.0}folder.Coordinator");

String principal = "peter.sts";

When I run the method, all users with permission associated with the folder are removed.

What am I doing wrong?


Solution

  • You don't need to create an instance of an ACE if you only need to remove an entry. Example:

    public void doExample() {
        OperationContext oc = new OperationContextImpl();
        oc.setIncludeAcls(true);
        Folder folder = (Folder) getSession().getObject("workspace://SpacesStore/5c8251c3-d309-4c88-a397-c408f4b34ed3", oc);
    
        // grab the ACL
        Acl acl = folder.getAcl();
    
        // dump the entries to sysout
        dumpAcl(acl);
    
        // iterate over the ACL Entries, removing the one that matches the id we want to remove
        List<Ace> aces = acl.getAces();
        for (Ace ace : aces) {
            if (ace.getPrincipalId().equals("tuser2")) {
                aces.remove(ace);
            }
        }
    
        // update the object ACL with the new list of ACL Entries
        folder.setAcl(aces);
    
        // refresh the object
        folder.refresh();
    
        // dump the acl to show the update
        acl = folder.getAcl();
        dumpAcl(acl);
    }
    
    public void dumpAcl(Acl acl) {
        List<Ace> aces = acl.getAces();
        for (Ace ace : aces) {
            System.out.println(String.format("%s has %s access", ace.getPrincipalId(), ace.getPermissions()));
        }
    }
    

    Running this against a folder that has three users, tuser1/2/3, each with collaborator access returns:

    GROUP_EVERYONE has [{http://www.alfresco.org/model/content/1.0}cmobject.Consumer] access
    tuser1 has [{http://www.alfresco.org/model/content/1.0}cmobject.Collaborator] access
    tuser2 has [{http://www.alfresco.org/model/content/1.0}cmobject.Collaborator] access
    tuser3 has [{http://www.alfresco.org/model/content/1.0}cmobject.Collaborator] access
    GROUP_EVERYONE has [{http://www.alfresco.org/model/content/1.0}cmobject.Consumer] access
    tuser1 has [{http://www.alfresco.org/model/content/1.0}cmobject.Collaborator] access
    tuser3 has [{http://www.alfresco.org/model/content/1.0}cmobject.Collaborator] access