001/* 002 * (C) Copyright 2006-2011 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 * Nuxeo - initial API and implementation 018 * 019 * $Id: MergedPermissionDescriptor.java 28439 2008-01-02 14:35:41Z sfermigier $ 020 */ 021package org.nuxeo.ecm.core.security; 022 023import java.util.ArrayList; 024import java.util.List; 025 026public class MergedPermissionDescriptor { 027 028 private String name; 029 030 private final List<String> subPermissions = new ArrayList<String>(); 031 032 private final List<String> aliasPermissions = new ArrayList<String>(); 033 034 public MergedPermissionDescriptor(PermissionDescriptor pd) { 035 mergeDescriptor(pd); 036 } 037 038 public void mergeDescriptor(PermissionDescriptor pd) { 039 name = pd.getName(); 040 subPermissions.addAll(pd.getIncludePermissions()); 041 subPermissions.removeAll(pd.getRemovePermissions()); 042 aliasPermissions.addAll(pd.getAliasPermissions()); 043 // no way to remove alias yet (YAGNI?) 044 } 045 046 public String getName() { 047 return name; 048 } 049 050 public List<String> getSubPermissions() { 051 return subPermissions; 052 } 053 054 public void removeSubPermission(String permissionName) { 055 subPermissions.remove(permissionName); 056 } 057 058 public List<String> getAliasPermissions() { 059 return aliasPermissions; 060 } 061 062 @Override 063 public String toString() { 064 return String.format("MergedPermission[%s]", name); 065 } 066 067}