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_NOTIFY; 026import static org.nuxeo.ecm.permissions.Constants.ACE_INFO_REPOSITORY_NAME; 027 028import java.util.HashMap; 029import java.util.Map; 030 031import org.nuxeo.ecm.core.api.DocumentModel; 032import org.nuxeo.ecm.core.api.security.ACE; 033 034/** 035 * @since 7.4 036 */ 037public class PermissionHelper { 038 039 private PermissionHelper() { 040 // helper class 041 } 042 043 public static String computeDirectoryId(DocumentModel doc, String aclName, String aceId) { 044 return String.format("%s:%s:%s:%s", doc.getId(), doc.getRepositoryName(), aclName, aceId); 045 } 046 047 public static Map<String, Object> createDirectoryEntry(DocumentModel doc, String aclName, ACE ace, boolean notify, 048 String comment) { 049 Map<String, Object> m = new HashMap<>(); 050 m.put(ACE_INFO_ID, computeDirectoryId(doc, aclName, ace.getId())); 051 m.put(ACE_INFO_REPOSITORY_NAME, doc.getRepositoryName()); 052 m.put(ACE_INFO_DOC_ID, doc.getId()); 053 m.put(ACE_INFO_ACL_NAME, aclName); 054 m.put(ACE_INFO_ACE_ID, ace.getId()); 055 m.put(ACE_INFO_NOTIFY, notify); 056 m.put(ACE_INFO_COMMENT, comment); 057 return m; 058 } 059}