当我想使用openCMIS方法Acl removeAcl(List removeAces,AclPropagation aclPropagation)从单个用户删除权限时遇到麻烦。
我有一个文档或文件夹,其中有几个拥有权限的用户,我只想删除对单个用户的权限。
这是我用来删除用户的代码:
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
我有这个具有与文件夹关联的权限的用户,并且想要删除,但只有这个用户。
permissions.add(“ {http://www.alfresco.org/model/content/1.0} folder.Coordinator”);
StringPrincipal =“ peter.sts”;
当我运行该方法时,将删除所有与该文件夹关联的权限的用户。
我在做什么错了?
答案 0 :(得分:1)
如果仅需要删除条目,则无需创建ACE实例。示例:
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()));
}
}
针对具有三个用户tuser1 / 2/3的文件夹运行此文件夹,每个用户都具有协作者访问权限:
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