001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Vladimir Pasquier <vpasquier@nuxeo.com> 018 */ 019package org.nuxeo.ecm.automation.io.services.enricher; 020 021import java.io.IOException; 022 023import org.codehaus.jackson.JsonGenerator; 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.core.api.security.ACE; 026import org.nuxeo.ecm.core.api.security.ACL; 027import org.nuxeo.ecm.core.api.security.ACP; 028 029/** 030 * This enricher adds a document ACLs 031 * 032 * @since 5.9.5 033 * @deprecated This enricher was migrated to {@link org.nuxeo.ecm.permissions.ACLJsonEnricher}. The content enricher 034 * service doesn't work anymore. 035 */ 036@Deprecated 037public class ACLContentEnricher extends AbstractContentEnricher { 038 039 public static final String ACLS_CONTENT_ID = "acls"; 040 041 @Override 042 public void enrich(JsonGenerator jg, RestEvaluationContext ec) throws IOException { 043 DocumentModel doc = ec.getDocumentModel(); 044 ACP item = doc.getACP(); 045 jg.writeStartArray(); 046 for (ACL acl : item.getACLs()) { 047 jg.writeStartObject(); 048 jg.writeStringField("name", acl.getName()); 049 050 jg.writeArrayFieldStart("ace"); 051 052 for (ACE ace : acl.getACEs()) { 053 jg.writeStartObject(); 054 jg.writeStringField("username", ace.getUsername()); 055 jg.writeStringField("permission", ace.getPermission()); 056 jg.writeBooleanField("granted", ace.isGranted()); 057 jg.writeEndObject(); 058 } 059 060 jg.writeEndArray(); 061 jg.writeEndObject(); 062 } 063 jg.writeEndArray(); 064 jg.flush(); 065 } 066 067}