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.Permission;
25 import org.apache.fulcrum.security.model.turbine.entity.TurbineRole;
26 import org.apache.fulcrum.security.util.PermissionSet;
27
28 /**
29 * Represents the "turbine" model where permissions are in a many to many
30 * relationship to roles, roles are related to groups are related to users, all
31 * in many to many relationships.
32 *
33 * @author <a href="mailto:epugh@upstate.com">Eric Pugh </a>
34 * @version $Id: TurbineRole.java 437451 2006-08-27 20:20:44Z tv $
35 */
36 public class TurbineRoleImpl extends AbstractTurbineSecurityEntityImpl implements TurbineRole
37 {
38 private Set<? extends Permission> permissionSet = new PermissionSet();
39
40 /**
41 * Get the permission that are part of this role
42 *
43 * @return a set of permissions
44 */
45 public PermissionSet getPermissions()
46 {
47 if (permissionSet instanceof PermissionSet)
48 {
49 return (PermissionSet) permissionSet;
50 }
51 else
52 {
53 permissionSet = new PermissionSet(permissionSet);
54 return (PermissionSet) permissionSet;
55 }
56 }
57
58 /**
59 * Get the permission that are part of this role as Set
60 *
61 * @return a set of permissions
62 */
63 @SuppressWarnings("unchecked")
64 public <T extends Permission> Set<T> getPermissionsAsSet()
65 {
66 return (Set<T>) permissionSet;
67 }
68
69 /**
70 * Set the permission that are part of this role
71 *
72 * @param permissionSet
73 * a set of permissions
74 */
75 public void setPermissions(PermissionSet permissionSet)
76 {
77 if (permissionSet != null)
78 {
79 this.permissionSet = permissionSet;
80 }
81 else
82 {
83 this.permissionSet = new PermissionSet();
84 }
85 }
86
87 /**
88 * Set the permission that are part of this role as Set
89 *
90 * @param permissions
91 * a set of permissions
92 * @param <T> Permission
93 */
94 public <T extends Permission> void setPermissionsAsSet(Set<T> permissions)
95 {
96 this.permissionSet = permissions;
97 }
98
99 /**
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 }