1 package org.apache.fulcrum.security.model.turbine;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.avalon.framework.configuration.Configurable;
23 import org.apache.avalon.framework.configuration.Configuration;
24 import org.apache.fulcrum.security.entity.Group;
25 import org.apache.fulcrum.security.entity.Permission;
26 import org.apache.fulcrum.security.entity.Role;
27 import org.apache.fulcrum.security.entity.User;
28 import org.apache.fulcrum.security.model.turbine.entity.TurbineGroup;
29 import org.apache.fulcrum.security.model.turbine.entity.TurbineRole;
30 import org.apache.fulcrum.security.model.turbine.entity.TurbineUser;
31 import org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRole;
32 import org.apache.fulcrum.security.spi.AbstractManager;
33 import org.apache.fulcrum.security.util.DataBackendException;
34 import org.apache.fulcrum.security.util.EntityExistsException;
35 import org.apache.fulcrum.security.util.UnknownEntityException;
36
37
38
39
40
41
42
43
44
45 public abstract class AbstractTurbineModelManager extends AbstractManager implements TurbineModelManager, Configurable
46 {
47
48
49
50
51
52 private static final long serialVersionUID = 1L;
53
54 private String globalGroupName;
55
56
57
58
59
60
61 @Override
62 public void configure(Configuration conf)
63 {
64 globalGroupName = conf.getAttribute(
65 TurbineModelManager.GLOBAL_GROUP_ATTR_NAME,
66 TurbineModelManager.GLOBAL_GROUP_NAME);
67
68 }
69
70
71
72
73
74
75
76 @Override
77 public Group getGlobalGroup() throws DataBackendException
78 {
79 Group g = null;
80 try
81 {
82 g = getGroupManager().getGroupByName(globalGroupName);
83 }
84 catch (UnknownEntityException uee)
85 {
86 g = getGroupManager().getGroupInstance(globalGroupName);
87 try
88 {
89 getGroupManager().addGroup(g);
90 }
91 catch (EntityExistsException eee)
92 {
93 throw new DataBackendException(eee.getMessage(), eee);
94 }
95
96 }
97 return g;
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112 @Override
113 public synchronized void revokeAll(Role role) throws DataBackendException, UnknownEntityException
114 {
115 revokeAll( role, false );
116 }
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 @Override
134 public synchronized void revokeAll(Role role, boolean cascadeDelete) throws DataBackendException, UnknownEntityException
135 {
136 boolean roleExists = false;
137 roleExists = getRoleManager().checkExists(role);
138 if (roleExists)
139 {
140
141 Object permissions[] = ((TurbineRole) role).getPermissions().toArray();
142 for (Object permission : permissions)
143 {
144 revoke(role, (Permission) permission);
145 }
146 if (cascadeDelete) {
147 Object userGroupRoles[] = ((TurbineRole) role).getUserGroupRoleSet().toArray();
148 for (Object userGroupRole : userGroupRoles)
149 {
150 TurbineUserGroupRole/../../org/apache/fulcrum/security/model/turbine/entity/TurbineUserGroupRole.html#TurbineUserGroupRole">TurbineUserGroupRole ugr = (TurbineUserGroupRole) userGroupRole;
151 revoke(ugr.getUser(), ugr.getGroup(), role);
152 }
153 }
154 }
155 else
156 {
157 throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
158 }
159
160 }
161
162
163
164
165
166
167
168
169
170
171
172
173
174 @Override
175 public synchronized void revokeAll(User user) throws DataBackendException, UnknownEntityException
176 {
177 boolean userExists = false;
178 userExists = getUserManager().checkExists(user);
179 if (userExists)
180 {
181
182 Object userGroupRoles[] = ((TurbineUser) user).getUserGroupRoleSet().toArray();
183 for (Object userGroupRole : userGroupRoles)
184 {
185 TurbineUserGroupRole/../../org/apache/fulcrum/security/model/turbine/entity/TurbineUserGroupRole.html#TurbineUserGroupRole">TurbineUserGroupRole ugr = (TurbineUserGroupRole) userGroupRole;
186 revoke(user, ugr.getGroup(), ugr.getRole());
187 }
188 }
189 else
190 {
191 throw new UnknownEntityException("Unknown user '" + user.getName() + "'");
192 }
193 }
194
195
196
197
198
199
200
201
202
203
204
205
206
207 @Override
208 public synchronized void revokeAll(Group group) throws DataBackendException, UnknownEntityException
209 {
210 boolean groupExists = false;
211 groupExists = getGroupManager().checkExists(group);
212 if (groupExists)
213 {
214
215 Object userGroupRoles[] = ((TurbineGroup) group).getUserGroupRoleSet().toArray();
216 for (Object userGroupRole : userGroupRoles)
217 {
218 TurbineUserGroupRole/../../org/apache/fulcrum/security/model/turbine/entity/TurbineUserGroupRole.html#TurbineUserGroupRole">TurbineUserGroupRole ugr = (TurbineUserGroupRole) userGroupRole;
219 revoke(ugr.getUser(), group, ugr.getRole());
220 }
221 }
222 else
223 {
224 throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
225 }
226 }
227
228 @Override
229 public String getGlobalGroupName() {
230 return globalGroupName;
231 }
232 }