001/* 002 * (C) Copyright 2013 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 * Martin Pernollet 016 */ 017 018package org.nuxeo.ecm.platform.groups.audit.service.acl.filter; 019 020import java.util.Collection; 021 022import org.apache.commons.logging.Log; 023import org.apache.commons.logging.LogFactory; 024import org.nuxeo.ecm.core.api.security.SecurityConstants; 025import org.nuxeo.ecm.platform.usermanager.UserManager; 026import org.nuxeo.runtime.api.Framework; 027 028/** 029 * Ignore users and keep groups. Warning: this filter assumes a {@link UserManager} is available. 030 * 031 * @author Martin Pernollet <mpernollet@nuxeo.com> 032 */ 033public class AcceptsGroupOnly extends AbstractContentFilter implements IContentFilter { 034 protected static Log log = LogFactory.getLog(AcceptsGroupOnly.class); 035 036 protected UserManager um = Framework.getLocalService(UserManager.class); 037 038 protected Collection<String> groups = null; 039 040 /** 041 * Return true if the input string is the name of a group known by the {@link UserManager} service. Return also true 042 * if input is equal to {@link SecurityConstants.EVERYONE}, since this is a special user name intended to define 043 * inheritance blocker rules. 044 */ 045 @Override 046 public boolean acceptsUserOrGroup(String userOrGroup) { 047 if (isEveryone(userOrGroup)) 048 return true; 049 return isGroup(userOrGroup); 050 } 051 052 public boolean isGroup(String user) { 053 if (groups == null) 054 groups = um.getGroupIds(); 055 return groups.contains(user); 056 } 057}