001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thomas Roger 016 */ 017 018package org.nuxeo.ecm.permissions; 019 020import static org.nuxeo.ecm.permissions.Constants.ACE_INFO_ACE_ID; 021import static org.nuxeo.ecm.permissions.Constants.ACE_INFO_ACL_NAME; 022import static org.nuxeo.ecm.permissions.Constants.ACE_INFO_COMMENT; 023import static org.nuxeo.ecm.permissions.Constants.ACE_INFO_DOC_ID; 024import static org.nuxeo.ecm.permissions.Constants.ACE_INFO_ID; 025import static org.nuxeo.ecm.permissions.Constants.ACE_INFO_NOTIFIED; 026import static org.nuxeo.ecm.permissions.Constants.ACE_INFO_NOTIFY; 027import static org.nuxeo.ecm.permissions.Constants.ACE_INFO_REPOSITORY_NAME; 028 029import java.util.HashMap; 030import java.util.Map; 031 032import org.nuxeo.ecm.core.api.DocumentModel; 033import org.nuxeo.ecm.core.api.security.ACE; 034 035/** 036 * @since 7.4 037 */ 038public class PermissionHelper { 039 040 private PermissionHelper() { 041 // helper class 042 } 043 044 public static String computeDirectoryId(DocumentModel doc, String aclName, String aceId) { 045 return String.format("%s:%s:%s:%s", doc.getId(), doc.getRepositoryName(), aclName, aceId); 046 } 047 048 public static Map<String, Object> createDirectoryEntry(DocumentModel doc, String aclName, ACE ace, boolean notify, 049 boolean notified, String comment) { 050 Map<String, Object> m = new HashMap<>(); 051 m.put(ACE_INFO_ID, computeDirectoryId(doc, aclName, ace.getId())); 052 m.put(ACE_INFO_REPOSITORY_NAME, doc.getRepositoryName()); 053 m.put(ACE_INFO_DOC_ID, doc.getId()); 054 m.put(ACE_INFO_ACL_NAME, aclName); 055 m.put(ACE_INFO_ACE_ID, ace.getId()); 056 m.put(ACE_INFO_NOTIFY, notify); 057 m.put(ACE_INFO_NOTIFIED, notified); 058 m.put(ACE_INFO_COMMENT, comment); 059 return m; 060 } 061}