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