001/* 002 * (C) Copyright 2006-2010 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.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 * Julien Anguenot 016 * Florent Guillaume 017 */ 018 019package org.nuxeo.ecm.platform.publisher.rules; 020 021import java.util.Arrays; 022import java.util.HashSet; 023 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.core.api.DocumentRef; 026import org.nuxeo.ecm.core.api.UnrestrictedSessionRunner; 027import org.nuxeo.ecm.core.api.security.ACP; 028import org.nuxeo.ecm.core.api.security.SecurityConstants; 029 030/** 031 * Default NXP validator. 032 * <p> 033 * Validators here will be principals having manage everything rights in the sections where the document has been 034 * published. 035 */ 036public class DefaultValidatorsRule implements ValidatorsRule { 037 038 private static final long serialVersionUID = 1L; 039 040 public String[] computesValidatorsFor(DocumentModel doc) { 041 UnrestrictedACPGetter acpg = new UnrestrictedACPGetter(doc); 042 acpg.runUnrestricted(); 043 String[] writePermissions = doc.getCoreSession().getPermissionsToCheck(SecurityConstants.WRITE); 044 String[] reviewers = acpg.acp.listUsernamesForAnyPermission(new HashSet<String>(Arrays.asList(writePermissions))); 045 return reviewers; 046 } 047 048 protected static class UnrestrictedACPGetter extends UnrestrictedSessionRunner { 049 050 public final DocumentRef docRef; 051 052 public ACP acp; 053 054 public UnrestrictedACPGetter(DocumentModel doc) { 055 super(doc.getCoreSession()); 056 this.docRef = doc.getRef(); 057 } 058 059 @Override 060 public void run() { 061 acp = session.getACP(docRef); 062 } 063 } 064 065}