001package org.apache.fulcrum.security.model.dynamic.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.Role; 025import org.apache.fulcrum.security.model.basic.entity.impl.BasicGroupImpl; 026import org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup; 027import org.apache.fulcrum.security.util.RoleSet; 028 029/** 030 * Represents the "dynamic" model where permissions are related to roles, roles 031 * are related to groups and groups are related to userSet, all in many to many 032 * relationships. 033 * 034 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a> 035 * @version $Id: DynamicGroup.java 223057 2004-07-05 19:28:23Z epugh $ 036 */ 037public class DynamicGroupImpl extends BasicGroupImpl implements DynamicGroup 038{ 039 private Set<? extends Role> roleSet = new RoleSet(); 040 041 /** 042 * Get the roles that are part of this group 043 * 044 * @return a set of roles 045 */ 046 public RoleSet getRoles() 047 { 048 if (roleSet instanceof RoleSet) 049 { 050 return (RoleSet) roleSet; 051 } 052 else 053 { 054 roleSet = new RoleSet(roleSet); 055 return (RoleSet) roleSet; 056 } 057 } 058 059 /** 060 * Set the roles that are part of this group 061 * 062 * @param roleSet 063 * a set of roles 064 */ 065 public void setRoles(RoleSet roleSet) 066 { 067 if (roleSet != null) 068 { 069 this.roleSet = roleSet; 070 } 071 else 072 { 073 this.roleSet = new RoleSet(); 074 } 075 } 076 077 /** 078 * Add a role to this group 079 * 080 * @param role 081 * the role to add 082 */ 083 public void addRole(Role role) 084 { 085 getRoles().add(role); 086 } 087 088 /** 089 * Remove a role from this group 090 * 091 * @param role 092 * the role to remove 093 */ 094 public void removeRole(Role role) 095 { 096 getRoles().remove(role); 097 } 098 099 /** 100 * Set the roles that are part of this group as Set 101 * 102 * @param roles 103 * a set of roles 104 */ 105 public <T extends Role> void setRolesAsSet(Set<T> roles) 106 { 107 this.roleSet = roles; 108 } 109 110 /** 111 * Get the roles that are part of this group as Set 112 * 113 * @return a set of roles 114 */ 115 @SuppressWarnings("unchecked") 116 public <T extends Role> Set<T> getRolesAsSet() 117 { 118 return (Set<T>) roleSet; 119 } 120}