001package org.apache.fulcrum.security.model.turbine.entity.impl; 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 */ 021 022import java.util.Set; 023 024import org.apache.fulcrum.security.entity.Permission; 025import org.apache.fulcrum.security.model.turbine.entity.TurbineRole; 026import org.apache.fulcrum.security.util.PermissionSet; 027 028/** 029 * Represents the "turbine" model where permissions are in a many to many 030 * relationship to roles, roles are related to groups are related to users, all 031 * in many to many relationships. 032 * 033 * @author <a href="mailto:epugh@upstate.com">Eric Pugh </a> 034 * @version $Id: TurbineRole.java 437451 2006-08-27 20:20:44Z tv $ 035 */ 036public class TurbineRoleImpl extends AbstractTurbineSecurityEntityImpl implements TurbineRole 037{ 038 private Set<? extends Permission> permissionSet = new PermissionSet(); 039 040 /** 041 * Get the permission that are part of this role 042 * 043 * @return a set of permissions 044 */ 045 public PermissionSet getPermissions() 046 { 047 if (permissionSet instanceof PermissionSet) 048 { 049 return (PermissionSet) permissionSet; 050 } 051 else 052 { 053 permissionSet = new PermissionSet(permissionSet); 054 return (PermissionSet) permissionSet; 055 } 056 } 057 058 /** 059 * Get the permission that are part of this role as Set 060 * 061 * @return a set of permissions 062 */ 063 @SuppressWarnings("unchecked") 064 public <T extends Permission> Set<T> getPermissionsAsSet() 065 { 066 return (Set<T>) permissionSet; 067 } 068 069 /** 070 * Set the permission that are part of this role 071 * 072 * @param permissionSet 073 * a set of permissions 074 */ 075 public void setPermissions(PermissionSet permissionSet) 076 { 077 if (permissionSet != null) 078 { 079 this.permissionSet = permissionSet; 080 } 081 else 082 { 083 this.permissionSet = new PermissionSet(); 084 } 085 } 086 087 /** 088 * Set the permission that are part of this role as Set 089 * 090 * @param permissions 091 * a set of permissions 092 * @param <T> Permission 093 */ 094 public <T extends Permission> void setPermissionsAsSet(Set<T> permissions) 095 { 096 this.permissionSet = permissions; 097 } 098 099 /** 100 * This method should only be used by a RoleManager. Not directly. 101 * 102 * @param permission the permission to add 103 */ 104 public void addPermission(Permission permission) 105 { 106 getPermissions().add(permission); 107 } 108 109 /** 110 * This method should only be used by a RoleManager. Not directly. 111 * 112 * @param permission the permission to remove 113 */ 114 public void removePermission(Permission permission) 115 { 116 getPermissions().remove(permission); 117 } 118}