1 package org.apache.fulcrum.security.model.turbine.entity.impl;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.Set;
23
24 import org.apache.fulcrum.security.entity.Role;
25 import org.apache.fulcrum.security.entity.impl.SecurityEntityImpl;
26 import org.apache.fulcrum.security.model.turbine.entity.TurbinePermission;
27 import org.apache.fulcrum.security.util.RoleSet;
28
29 /**
30 * Represents the "turbine" model where permissions are in a many to many
31 * relationship to roles, roles are related to groups are related to users, all
32 * in many to many relationships.
33 *
34 * @author <a href="mailto:epugh@upstate.com">Eric Pugh </a>
35 * @version $Id: TurbinePermission.java 223081 2004-10-07 15:11:58Z epugh $
36 */
37 public class TurbinePermissionImpl extends SecurityEntityImpl implements TurbinePermission
38 {
39 private Set<? extends Role> roleSet = new RoleSet();
40
41 /**
42 * Get the roles that this permission belongs to
43 *
44 * @return a set of roles
45 */
46 public RoleSet getRoles()
47 {
48 if (roleSet instanceof RoleSet)
49 {
50 return (RoleSet) roleSet;
51 }
52 else
53 {
54 roleSet = new RoleSet(roleSet);
55 return (RoleSet) roleSet;
56 }
57 }
58
59 /**
60 * Set the roles that this permission belongs to
61 *
62 * @param roleSet
63 * a set of roles
64 */
65 public void setRoles(RoleSet roleSet)
66 {
67 if (roleSet != null)
68 {
69 this.roleSet = roleSet;
70 }
71 else
72 {
73 this.roleSet = new RoleSet();
74 }
75 }
76
77 /**
78 * Add a role to this permission
79 *
80 * @param role
81 * the role to add
82 */
83 public void addRole(Role role)
84 {
85 getRoles().add(role);
86 }
87
88 /**
89 * Remove a role from this permission
90 *
91 * @param role
92 * the role to remove
93 */
94 public void removeRole(Role role)
95 {
96 getRoles().remove(role);
97 }
98
99 /**
100 * Set the roles that this permission belongs to 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 this permission belongs to 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 }