001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Nuxeo - initial API and implementation 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.ecm.core.security; 016 017import java.io.Serializable; 018import java.util.Arrays; 019import java.util.List; 020 021import org.nuxeo.common.xmap.annotation.XNode; 022import org.nuxeo.common.xmap.annotation.XNodeList; 023import org.nuxeo.common.xmap.annotation.XObject; 024 025/** 026 * @author Bogdan Stefanescu 027 * @author Olivier Grisel 028 * @author Thierry Delprat 029 */ 030@XObject("permission") 031public class PermissionDescriptor implements Serializable { 032 033 private static final long serialVersionUID = 1L; 034 035 @XNode("@name") 036 private String name; 037 038 @XNodeList(value = "include", type = String[].class, componentType = String.class) 039 private String[] includePermissions; 040 041 @XNodeList(value = "remove", type = String[].class, componentType = String.class) 042 private String[] removePermissions; 043 044 @XNodeList(value = "alias", type = String[].class, componentType = String.class) 045 private String[] aliasPermissions; 046 047 public String getName() { 048 return name; 049 } 050 051 public List<String> getIncludePermissions() { 052 return Arrays.asList(includePermissions); 053 } 054 055 public List<String> getRemovePermissions() { 056 return Arrays.asList(removePermissions); 057 } 058 059 public List<String> getAliasPermissions() { 060 return Arrays.asList(aliasPermissions); 061 } 062 063 /** 064 * Used to unregistered a PermissionDescriptor out of the list of already registered contributions. 065 */ 066 @Override 067 public boolean equals(Object o) { 068 if (o instanceof PermissionDescriptor) { 069 PermissionDescriptor pd = (PermissionDescriptor) o; 070 if (!name.equals(pd.name)) { 071 return false; 072 } 073 if (!getIncludePermissions().equals(pd.getIncludePermissions())) { 074 return false; 075 } 076 if (!getRemovePermissions().equals(pd.getRemovePermissions())) { 077 return false; 078 } 079 if (!getAliasPermissions().equals(pd.getAliasPermissions())) { 080 return false; 081 } 082 // this is an equivalent permission 083 return true; 084 } 085 return false; 086 } 087 088 @Override 089 public String toString() { 090 return String.format("PermissionDescriptor[%s]", name); 091 } 092 093}