1 package org.apache.turbine.om.security;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.sql.Connection;
20 import java.util.Iterator;
21
22 import org.apache.turbine.services.security.TurbineSecurity;
23 import org.apache.turbine.util.security.RoleSet;
24 import org.apache.turbine.util.security.TurbineSecurityException;
25
26 /***
27 * This class represents a Group of Users in the system that are associated
28 * with specific entity or resource. The users belonging to the Group may have
29 * various Roles. The Permissions to perform actions upon the resource depend
30 * on the Roles in the Group that they are assigned.
31 *
32 * <a name="global">
33 * <p> Certain Roles that the Users may have in the system may are not related
34 * to any specific resource nor entity.
35 * They are assigned within a special group named 'global' that can be
36 * referenced in the code as {@link #GLOBAL_GROUP_NAME}.
37 * <br>
38 *
39 * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
40 * @version $Id: TurbineGroup.java 278822 2005-09-05 19:53:05Z henning $
41 */
42 public class TurbineGroup extends SecurityObject implements Group
43 {
44 /*** Serial Version UID */
45 private static final long serialVersionUID = -6034684697021752649L;
46
47 /***
48 * Constructs a new Group.
49 */
50 public TurbineGroup()
51 {
52 super();
53 }
54
55 /***
56 * Constructs a new Group with the specified name.
57 *
58 * @param name The name of the new object.
59 */
60 public TurbineGroup(String name)
61 {
62 super(name);
63 }
64
65
66
67 /***
68 * Makes changes made to the Group attributes permanent.
69 *
70 * @throws TurbineSecurityException if there is a problem while saving data.
71 */
72 public void save() throws TurbineSecurityException
73 {
74 TurbineSecurity.saveGroup(this);
75 }
76
77 /***
78 * not implemented
79 *
80 * @param conn
81 * @throws Exception
82 */
83 public void save(Connection conn) throws Exception
84 {
85 throw new Exception("not implemented");
86 }
87
88 /***
89 * not implemented
90 *
91 * @param dbname
92 * @throws Exception
93 */
94 public void save(String dbname) throws Exception
95 {
96 throw new Exception("not implemented");
97 }
98
99 /***
100 * Removes a group from the system.
101 *
102 * @throws TurbineSecurityException if the Group could not be removed.
103 */
104 public void remove() throws TurbineSecurityException
105 {
106 TurbineSecurity.removeGroup(this);
107 }
108
109 /***
110 * Renames the role.
111 *
112 * @param name The new Group name.
113 * @throws TurbineSecurityException if the Group could not be renamed.
114 */
115 public void rename(String name) throws TurbineSecurityException
116 {
117 TurbineSecurity.renameGroup(this, name);
118 }
119
120 /***
121 * Grants a Role in this Group to an User.
122 *
123 * @param user An User.
124 * @param role A Role.
125 * @throws TurbineSecurityException if there is a problem while assigning
126 * the Role.
127 */
128 public void grant(User user, Role role) throws TurbineSecurityException
129 {
130 TurbineSecurity.grant(user, this, role);
131 }
132
133 /***
134 * Grants Roles in this Group to an User.
135 *
136 * @param user An User.
137 * @param roleSet A RoleSet.
138 * @throws TurbineSecurityException if there is a problem while assigning
139 * the Roles.
140 */
141 public void grant(User user, RoleSet roleSet)
142 throws TurbineSecurityException
143 {
144 for (Iterator roles = roleSet.iterator(); roles.hasNext();)
145 {
146 TurbineSecurity.grant(user, this, (Role) roles.next());
147 }
148 }
149
150 /***
151 * Revokes a Role in this Group from an User.
152 *
153 * @param user An User.
154 * @param role A Role.
155 * @throws TurbineSecurityException if there is a problem while unassigning
156 * the Role.
157 */
158 public void revoke(User user, Role role) throws TurbineSecurityException
159 {
160 TurbineSecurity.revoke(user, this, role);
161 }
162
163 /***
164 * Revokes Roles in this group from an User.
165 *
166 * @param user An User.
167 * @param roleSet a RoleSet.
168 * @throws TurbineSecurityException if there is a problem while unassigning
169 * the Roles.
170 */
171 public void revoke(User user, RoleSet roleSet)
172 throws TurbineSecurityException
173 {
174 for (Iterator roles = roleSet.iterator(); roles.hasNext();)
175 {
176 TurbineSecurity.revoke(user, this, (Role) roles.next());
177 }
178 }
179 }