protected void blockPermissionInheritance(DocumentModel doc) { ACP acp = doc.getACP() != null ? doc.getACP() : new ACPImpl(); String username = session.getPrincipal().getName(); boolean permissionChanged = acp.blockInheritance(aclName, username); if (permissionChanged) { doc.setACP(acp, true); } } }
protected void addPermission(DocumentModel doc) { ACP acp = doc.getACP() != null ? doc.getACP() : new ACPImpl(); Map<String, Serializable> contextData = new HashMap<>(); contextData.put(NOTIFY_KEY, notify); contextData.put(COMMENT_KEY, comment); String creator = session.getPrincipal().getName(); boolean permissionChanged = false; if (blockInheritance) { permissionChanged = acp.blockInheritance(aclName, creator); } for (String username : users) { ACE ace = ACE.builder(username, permission) .creator(creator) .begin(begin) .end(end) .contextData(contextData) .build(); permissionChanged = acp.addACE(aclName, ace) || permissionChanged; } if (permissionChanged) { doc.setACP(acp, true); } }
/** * @param acp The ACP to modify * @param aclName the name of the ACL to target * @param userName the name of the principal (user or group) * @param permission the permission of the ACE * @param blockInheritance should we block inheritance * @param currentPrincipalName the creator * @param begin the begin date of the ACE * @param end the end date of the ACE * @return true if something has changed on the document security * @since 7.4 */ public static boolean addPermission(ACP acp, String aclName, String userName, String permission, boolean blockInheritance, String currentPrincipalName, Calendar begin, Calendar end, Map<String, Serializable> contextData) { boolean acpChanged = false; if (blockInheritance) { acpChanged = acp.blockInheritance(aclName, currentPrincipalName); } acpChanged = acpChanged || acp.addACE(aclName, ACE.builder(userName, permission) .creator(currentPrincipalName) .begin(begin) .end(end) .contextData(contextData) .build()); return acpChanged; }