@Override public List<Ace> getAces() { return objectAcl.getAces(); } };
@Override public List<Ace> getAces() { return objectAcl.getAces(); } };
/** * Checks if at least one ACE list is not empty. */ protected boolean isAclMergeRequired(Acl addAces, Acl removeAces) { return (addAces != null && addAces.getAces() != null && !addAces.getAces().isEmpty()) || (removeAces != null && removeAces.getAces() != null && !removeAces.getAces().isEmpty()); }
@Override public Acl setAcl(String repositoryId, String objectId, Acl aces) { Acl currentAcl = getAcl(repositoryId, objectId, false, null); List<Ace> removeAces = new ArrayList<Ace>(); if (currentAcl.getAces() != null) { for (Ace ace : currentAcl.getAces()) { if (ace.isDirect()) { removeAces.add(ace); } } } return applyAcl(repositoryId, objectId, aces, new AccessControlListImpl(removeAces), AclPropagation.OBJECTONLY, null); } }
@Override public Acl setAcl(String repositoryId, String objectId, Acl aces) { Acl currentAcl = getAcl(repositoryId, objectId, false, null); List<Ace> removeAces = new ArrayList<Ace>(); if (currentAcl.getAces() != null) { for (Ace ace : currentAcl.getAces()) { if (ace.isDirect()) { removeAces.add(ace); } } } return applyAcl(repositoryId, objectId, aces, new AccessControlListImpl(removeAces), AclPropagation.OBJECTONLY, null); } }
@Override public Acl setAcl(String repositoryId, String objectId, Acl aces) { Acl currentAcl = getAcl(repositoryId, objectId, false, null); List<Ace> removeAces = new ArrayList<Ace>(); if (currentAcl.getAces() != null) { for (Ace ace : currentAcl.getAces()) { if (ace.isDirect()) { removeAces.add(ace); } } } return applyAcl(repositoryId, objectId, aces, new AccessControlListImpl(removeAces), AclPropagation.OBJECTONLY, null); } }
@Override public Set<String> getPermissionsForPrincipal(String principalId) { if (principalId == null) { throw new IllegalArgumentException("Principal must be set!"); } Acl currentAcl = getAcl(); if (currentAcl == null) { throw new IllegalStateException("ACLs are not available!"); } if (isNullOrEmpty(acl.getAces())) { return Collections.emptySet(); } HashSet<String> result = new HashSet<String>(); for (Ace ace : acl.getAces()) { if (principalId.equals(ace.getPrincipalId()) && ace.getPermissions() != null) { result.addAll(ace.getPermissions()); } } return result; }
@Override public Set<String> getPermissionsForPrincipal(String principalId) { if (principalId == null) { throw new IllegalArgumentException("Principal must be set!"); } Acl currentAcl = getAcl(); if (currentAcl == null) { throw new IllegalStateException("ACLs are not available!"); } if (isNullOrEmpty(acl.getAces())) { return Collections.emptySet(); } HashSet<String> result = new HashSet<String>(); for (Ace ace : acl.getAces()) { if (principalId.equals(ace.getPrincipalId()) && ace.getPermissions() != null) { result.addAll(ace.getPermissions()); } } return result; }
/** * Converts a list of ACEs into Map for better handling. */ private static Map<String, Set<String>> convertAclToMap(Acl acl) { Map<String, Set<String>> result = new HashMap<String, Set<String>>(); if (acl == null || acl.getAces() == null) { return result; } for (Ace ace : acl.getAces()) { // don't consider indirect ACEs - we can't change them if (!ace.isDirect()) { // ignore continue; } // although a principal must not be null, check it if (ace.getPrincipal() == null || ace.getPrincipal().getId() == null) { // ignore continue; } Set<String> permissions = result.get(ace.getPrincipal().getId()); if (permissions == null) { permissions = new HashSet<String>(); result.put(ace.getPrincipal().getId(), permissions); } if (ace.getPermissions() != null) { permissions.addAll(ace.getPermissions()); } } return result; }
/** * Converts a list of ACEs into Map for better handling. */ private static Map<String, Set<String>> convertAclToMap(Acl acl) { Map<String, Set<String>> result = new HashMap<String, Set<String>>(); if (acl == null || acl.getAces() == null) { return result; } for (Ace ace : acl.getAces()) { // don't consider indirect ACEs - we can't change them if (!ace.isDirect()) { // ignore continue; } // although a principal must not be null, check it if (ace.getPrincipal() == null || ace.getPrincipal().getId() == null) { // ignore continue; } Set<String> permissions = result.get(ace.getPrincipal().getId()); if (permissions == null) { permissions = new HashSet<String>(); result.put(ace.getPrincipal().getId(), permissions); } if (ace.getPermissions() != null) { permissions.addAll(ace.getPermissions()); } } return result; }
private void addAcesParameters(Acl acl, String principalControl, String permissionControl) { if (acl == null || acl.getAces() == null) { return; } int idx = 0; for (Ace ace : acl.getAces()) { if (ace.getPrincipalId() != null && isNotEmpty(ace.getPermissions())) { String idxStr = "[" + idx + "]"; addParameter(principalControl + idxStr, ace.getPrincipalId()); int permIdx = 0; for (String perm : ace.getPermissions()) { if (perm != null) { String permIdxStr = "[" + permIdx + "]"; addParameter(permissionControl + idxStr + permIdxStr, perm); permIdx++; } } idx++; } } }
private void addAcesParameters(Acl acl, String principalControl, String permissionControl) { if (acl == null || acl.getAces() == null) { return; } int idx = 0; for (Ace ace : acl.getAces()) { if (ace.getPrincipalId() != null && isNotEmpty(ace.getPermissions())) { String idxStr = "[" + idx + "]"; addParameter(principalControl + idxStr, ace.getPrincipalId()); int permIdx = 0; for (String perm : ace.getPermissions()) { if (perm != null) { String permIdxStr = "[" + permIdx + "]"; addParameter(permissionControl + idxStr + permIdxStr, perm); permIdx++; } } idx++; } } }
private Document cmisAccessList(String id) { DocumentWriter writer = newDocument(ObjectId.toString(ObjectId.Type.ACL, id)); writer.setPrimaryType(ModeShapeLexicon.ACCESS_LIST_NODE_TYPE_STRING); writer.setParent(id); CmisObject obj = session.getObject(id); obj = session.getObject(obj, ctx); Acl acl = obj.getAcl(); List<Ace> entries = acl.getAces(); for (Ace entry : entries) { String entryId = AclObjectId.encode(id, entry.getPrincipalId()); writer.addChild(ObjectId.toString(ObjectId.Type.PERMISSIONS, entryId), ModeShapeLexicon.PERMISSION.toString()); } return writer.document(); }
private Document cmisPermission( String id ) { String cmisObjectId = AclObjectId.cmisObjectId(id); String entryId = AclObjectId.entryId(id); DocumentWriter writer = newDocument(ObjectId.toString(ObjectId.Type.PERMISSIONS, id)); writer.setPrimaryType(ModeShapeLexicon.PERMISSION.toString()); writer.setParent(id); Acl acl = session.getObject(cmisObjectId, ctx).getAcl(); List<Ace> entries = acl.getAces(); for (Ace entry : entries) { if (entry.getPrincipalId().equals(entryId)) { String name = entry.getPrincipal().getId(); name = Converter.jcrPrincipal(name); writer.addProperty(ModeShapeLexicon.PERMISSION_PRINCIPAL_NAME.getLocalName(), name); List<String> perms = entry.getPermissions(); writer.addProperty(ModeShapeLexicon.PERMISSION_PRIVILEGES_NAME.getLocalName(), Converter.jcrPermissions(perms)); } } return writer.document(); }