001/* 002 * Copyright (c) 2006-2011 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 Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 */ 012package org.nuxeo.ecm.automation.core.operations.document; 013 014import org.nuxeo.ecm.automation.core.Constants; 015import org.nuxeo.ecm.automation.core.annotations.Context; 016import org.nuxeo.ecm.automation.core.annotations.Operation; 017import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 018import org.nuxeo.ecm.automation.core.annotations.Param; 019import org.nuxeo.ecm.automation.core.collectors.DocumentModelCollector; 020import org.nuxeo.ecm.core.api.CoreSession; 021import org.nuxeo.ecm.core.api.DocumentModel; 022import org.nuxeo.ecm.core.api.DocumentRef; 023import org.nuxeo.ecm.core.api.security.ACP; 024 025/** 026 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 027 */ 028@Operation(id = RemoveDocumentACL.ID, category = Constants.CAT_DOCUMENT, label = "Remove ACL", description = "Remove a named Acces Control List from the input document(s). Returns the document(s).") 029public class RemoveDocumentACL { 030 031 public static final String ID = "Document.RemoveACL"; 032 033 @Context 034 protected CoreSession session; 035 036 @Param(name = "acl") 037 protected String aclName; 038 039 @OperationMethod(collector = DocumentModelCollector.class) 040 public DocumentModel run(DocumentModel doc) { 041 deleteACL(doc.getRef()); 042 return session.getDocument(doc.getRef()); 043 } 044 045 @OperationMethod(collector = DocumentModelCollector.class) 046 public DocumentModel run(DocumentRef doc) { 047 deleteACL(doc); 048 return session.getDocument(doc); 049 } 050 051 protected void deleteACL(DocumentRef ref) { 052 ACP acp = session.getACP(ref); 053 acp.removeACL(aclName); 054 acp.removeACL("inherited"); // make sure to not save the inherited acl 055 // which is dynamically computed 056 session.setACP(ref, acp, true); 057 } 058 059}