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$ 020 */ 021 022package org.nuxeo.ecm.core.security; 023 024import java.util.Arrays; 025import java.util.List; 026 027import org.nuxeo.common.xmap.annotation.XNode; 028import org.nuxeo.common.xmap.annotation.XNodeList; 029import org.nuxeo.common.xmap.annotation.XObject; 030 031/** 032 * @author Bogdan Stefanescu 033 * @author Olivier Grisel 034 * @author Thierry Delprat 035 */ 036@XObject("permission") 037public class PermissionDescriptor { 038 039 @XNode("@name") 040 private String name; 041 042 @XNodeList(value = "include", type = String[].class, componentType = String.class) 043 private String[] includePermissions; 044 045 @XNodeList(value = "remove", type = String[].class, componentType = String.class) 046 private String[] removePermissions; 047 048 @XNodeList(value = "alias", type = String[].class, componentType = String.class) 049 private String[] aliasPermissions; 050 051 public String getName() { 052 return name; 053 } 054 055 public List<String> getIncludePermissions() { 056 return Arrays.asList(includePermissions); 057 } 058 059 public List<String> getRemovePermissions() { 060 return Arrays.asList(removePermissions); 061 } 062 063 public List<String> getAliasPermissions() { 064 return Arrays.asList(aliasPermissions); 065 } 066 067 /** 068 * Used to unregistered a PermissionDescriptor out of the list of already registered contributions. 069 */ 070 @Override 071 public boolean equals(Object o) { 072 if (o instanceof PermissionDescriptor) { 073 PermissionDescriptor pd = (PermissionDescriptor) o; 074 if (!name.equals(pd.name)) { 075 return false; 076 } 077 if (!getIncludePermissions().equals(pd.getIncludePermissions())) { 078 return false; 079 } 080 if (!getRemovePermissions().equals(pd.getRemovePermissions())) { 081 return false; 082 } 083 if (!getAliasPermissions().equals(pd.getAliasPermissions())) { 084 return false; 085 } 086 // this is an equivalent permission 087 return true; 088 } 089 return false; 090 } 091 092 @Override 093 public String toString() { 094 return String.format("PermissionDescriptor[%s]", name); 095 } 096 097}