@Override public ACPImpl clone() { ACPImpl copy = new ACPImpl(); for (ACL acl : acls) { copy.acls.add((ACL) acl.clone()); } return copy; }
@Override public boolean removeACE(String aclName, ACE ace) { if (aclName == null) { throw new NullPointerException("'aclName' cannot be null"); } ACL acl = getOrCreateACL(aclName); boolean aclChanged = acl.remove(ace); if (aclChanged) { addACL(acl); } return aclChanged; }
public void addACL(ACL acl) { assert acl != null; ACL oldACL = getACL(acl.getName()); if (!acl.equals(oldACL)) { case ACL.LOCAL_ACL: ACL inherited = getACL(ACL.INHERITED_ACL); if (inherited != null) { int i = acls.indexOf(inherited); ACL local = getACL(ACL.LOCAL_ACL); if (local != null) { int i = acls.indexOf(local); if (useLegacyBehavior()) { i++; inherited = getACL(ACL.INHERITED_ACL); if (inherited != null) { int i = acls.indexOf(inherited);
/** * ajout une ace sur un document * * @param session * @param ref * @param ace * @throws NuxeoException */ public static void setACE(CoreSession session, DocumentRef ref, ACE ace) throws NuxeoException { ACPImpl acp = new ACPImpl(); ACLImpl acl = new ACLImpl(ACL.LOCAL_ACL); acp.addACL(acl); acl.add(ace); session.setACP(ref, acp, false); }
@Override public void addACL(int pos, ACL acl) { ACL oldACL = getACL(acl.getName()); if (oldACL != null) { acls.remove(oldACL); } acls.add(pos, acl); cache.clear(); }
/** * ajout une ace sur un document * @param session * @param ref * @param ace * @throws ClientException */ public static void setACE(CoreSession session, DocumentRef ref,ACE ace) throws ClientException { ACPImpl acp = new ACPImpl(); ACLImpl acl = new ACLImpl(ACL.LOCAL_ACL); acp.addACL(acl); acl.add(ace); session.setACP(ref, acp, false); }
@Override public boolean removeACEsByUsername(String username) { boolean changed = false; for (ACL acl : acls) { boolean aclChanged = acl.removeByUsername(username); if (aclChanged) { addACL(acl); changed = true; } } return changed; }
@Override public void run() { ACP acp = new ACPImpl(); session.setACP(docRef, acp, true); }
@Override public boolean unblockInheritance(String aclName) { if (aclName == null) { throw new NullPointerException("'aclName' cannot be null"); } ACL acl = getOrCreateACL(aclName); boolean aclChanged = acl.unblockInheritance(); if (aclChanged) { addACL(acl); } return aclChanged; }
@SuppressWarnings("unchecked") private void copyACP(DocumentRef docRef) throws NuxeoException { List<String> aclsToCopyList = Collections.emptyList(); // get the ACP from the source document ACP srcACP = session.getACP(srcDoc.getRef()); // slurp the ACLs to copy if (!doCopyAll && StringUtils.isNotBlank(ACLnames)) { aclsToCopyList = Arrays.asList(ACLnames.split(",")); } // copy the ACLs ACP dstACP = new ACPImpl(); for (ACL srcAcl : srcACP.getACLs()) { if ( doCopyAll || (!doCopyAll && aclsToCopyList.contains(srcAcl.getName())) ) { dstACP.addACL(srcAcl); } } // save new ACP session.setACP(docRef, dstACP, doOverwrite); }
protected static void setLocalAcl(CoreSession session, DocumentModel doc, String value) { ACPImpl acp = new ACPImpl(); ACLImpl acl = new ACLImpl(ACL.LOCAL_ACL); acp.addACL(acl); String[] entries = StringUtils.split(value, ',', true); if (entries.length == 0) { return; } for (String entry : entries) { String[] ace = StringUtils.split(entry, ':', true); acl.add(new ACE(ace[0], ace[1], Boolean.parseBoolean(ace[2]))); } session.setACP(doc.getRef(), acp, false); }
@Override public boolean replaceACE(String aclName, ACE oldACE, ACE newACE) { if (aclName == null) { throw new NullPointerException("'aclName' cannot be null"); } ACL acl = getOrCreateACL(aclName); boolean aclChanged = acl.replace(oldACE, newACE); if (aclChanged) { addACL(acl); } return aclChanged; }
@Override public void setRules(String aclName, UserEntry[] userEntries, boolean overwrite) { ACL acl = getACL(aclName); if (acl == null) { // create the loca ACL acl = new ACLImpl(aclName); addACL(acl); } else if (overwrite) { // :XXX: Should not overwrite entries not given as parameters here. acl.clear(); } for (UserEntry entry : userEntries) { String username = entry.getUserName(); for (String permission : entry.getGrantedPermissions()) { acl.add(new ACE(username, permission, true)); } for (String permission : entry.getDeniedPermissions()) { acl.add(new ACE(username, permission, false)); } } cache.clear(); }
protected void unblockPermissionInheritance(DocumentModel doc) { ACP acp = doc.getACP() != null ? doc.getACP() : new ACPImpl(); boolean permissionChanged = acp.unblockInheritance(aclName); if (permissionChanged) { doc.setACP(acp, true); } } }
@POST @Path("add") public Response postPermission() { HttpServletRequest req = ctx.getRequest(); String action = req.getParameter("action"); String permission = req.getParameter("permission"); String username = req.getParameter("user"); UserManager userManager = Framework.getService(UserManager.class); NuxeoPrincipal user = userManager.getPrincipal(username); if (user == null) { NuxeoGroup group = userManager.getGroup(username); if (group == null) { return Response.status(500).build(); } } ACPImpl acp = new ACPImpl(); ACLImpl acl = new ACLImpl(ACL.LOCAL_ACL); acp.addACL(acl); boolean granted = "grant".equals(action); ACE ace = new ACE(username, permission, granted); acl.add(ace); CoreSession session = ctx.getCoreSession(); Resource target = getTarget(); session.setACP(target.getAdapter(DocumentModel.class).getRef(), acp, false); session.save(); return redirect(target.getPath()); }
@Override public boolean removeACEsByUsername(String aclName, String username) { if (aclName == null) { throw new NullPointerException("'aclName' cannot be null"); } ACL acl = getOrCreateACL(aclName); boolean aclChanged = acl.removeByUsername(username); if (aclChanged) { addACL(acl); } return aclChanged; }