001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors. 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 * Vladimir Pasquier <vpasquier@nuxeo.com> 016 */ 017package org.nuxeo.ecm.automation.io.services.enricher; 018 019import java.io.IOException; 020 021import org.codehaus.jackson.JsonGenerator; 022import org.nuxeo.ecm.core.api.DocumentModel; 023import org.nuxeo.ecm.core.api.security.ACE; 024import org.nuxeo.ecm.core.api.security.ACL; 025import org.nuxeo.ecm.core.api.security.ACP; 026 027/** 028 * This enricher adds a document ACLs 029 * 030 * @since 5.9.5 031 * @deprecated This enricher was migrated to {@link org.nuxeo.ecm.permissions.ACLJsonEnricher}. The content enricher 032 * service doesn't work anymore. 033 */ 034@Deprecated 035public class ACLContentEnricher extends AbstractContentEnricher { 036 037 public static final String ACLS_CONTENT_ID = "acls"; 038 039 @Override 040 public void enrich(JsonGenerator jg, RestEvaluationContext ec) throws IOException { 041 DocumentModel doc = ec.getDocumentModel(); 042 ACP item = doc.getACP(); 043 jg.writeStartArray(); 044 for (ACL acl : item.getACLs()) { 045 jg.writeStartObject(); 046 jg.writeStringField("name", acl.getName()); 047 048 jg.writeArrayFieldStart("ace"); 049 050 for (ACE ace : acl.getACEs()) { 051 jg.writeStartObject(); 052 jg.writeStringField("username", ace.getUsername()); 053 jg.writeStringField("permission", ace.getPermission()); 054 jg.writeBooleanField("granted", ace.isGranted()); 055 jg.writeEndObject(); 056 } 057 058 jg.writeEndArray(); 059 jg.writeEndObject(); 060 } 061 jg.writeEndArray(); 062 jg.flush(); 063 } 064 065}