001package org.apache.fulcrum.security.util; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021import java.util.Collection; 022 023import org.apache.fulcrum.security.entity.Permission; 024 025/** 026 * This class represents a set of Permissions. It makes it easy to build a UI 027 * that would allow someone to add a group of Permissions to a Role. It enforces 028 * that only Permission objects are allowed in the set and only relevant methods 029 * are available. 030 * 031 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a> 032 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a> 033 * @author <a href="mailto:marco@intermeta.de">Marco Knüttel</a> 034 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 035 * @version $Id$ 036 */ 037public class PermissionSet extends SecuritySet<Permission> 038{ 039 /** 040 * Serial number 041 */ 042 private static final long serialVersionUID = 4532868341893924965L; 043 044 /** 045 * Constructs an empty PermissionSet 046 */ 047 public PermissionSet() 048 { 049 super(); 050 } 051 052 /** 053 * Constructs a new PermissionSet with specified contents. 054 * 055 * If the given collection contains multiple objects that are identical WRT 056 * equals() method, some objects will be overwritten. 057 * 058 * @param permissions 059 * A collection of permissions to be contained in the set. 060 */ 061 public PermissionSet(Collection<? extends Permission> permissions) 062 { 063 this(); 064 addAll(permissions); 065 } 066 067 /** 068 * Returns a Permission with the given name, if it is contained in this 069 * PermissionSet. 070 * 071 * @param permissionName 072 * Name of Permission. 073 * @return Permission if argument matched a Permission in this 074 * PermissionSet; null if no match. 075 * @deprecated use getByName() 076 */ 077 @Deprecated 078 public Permission getPermissionByName(String permissionName) 079 { 080 return getByName(permissionName); 081 } 082 083 /** 084 * Returns a Permission with the given id, if it is contained in this 085 * PermissionSet. 086 * 087 * @param permissionId 088 * Id of the Permission. 089 * @return Permission if argument matched a Permission in this 090 * PermissionSet; null if no match. 091 * @deprecated Use getById() 092 */ 093 @Deprecated 094 public Permission getPermissionById(Object permissionId) 095 { 096 return getById(permissionId); 097 } 098 099 /** 100 * Print out a PermissionSet as a String 101 * 102 * @return The Permission Set as String 103 * 104 */ 105 @Override 106 public String toString() 107 { 108 StringBuilder sb = new StringBuilder(); 109 sb.append("PermissionSet: "); 110 sb.append(super.toString()); 111 112 return sb.toString(); 113 } 114}