1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.security.spi.impl; |
18 |
|
|
19 |
|
import java.security.Principal; |
20 |
|
import java.util.Collection; |
21 |
|
import java.util.Iterator; |
22 |
|
|
23 |
|
import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport; |
24 |
|
import org.apache.jetspeed.i18n.KeyedMessage; |
25 |
|
import org.apache.jetspeed.security.SecurityException; |
26 |
|
import org.apache.jetspeed.security.UserPrincipal; |
27 |
|
import org.apache.jetspeed.security.impl.UserPrincipalImpl; |
28 |
|
import org.apache.jetspeed.security.om.InternalGroupPrincipal; |
29 |
|
import org.apache.jetspeed.security.om.InternalRolePrincipal; |
30 |
|
import org.apache.jetspeed.security.om.InternalUserPrincipal; |
31 |
|
import org.apache.jetspeed.security.om.impl.InternalGroupPrincipalImpl; |
32 |
|
import org.apache.jetspeed.security.om.impl.InternalRolePrincipalImpl; |
33 |
|
import org.apache.jetspeed.security.om.impl.InternalUserPrincipalImpl; |
34 |
|
import org.apache.jetspeed.security.spi.SecurityAccess; |
35 |
|
import org.apache.ojb.broker.query.Criteria; |
36 |
|
import org.apache.ojb.broker.query.Query; |
37 |
|
import org.apache.ojb.broker.query.QueryFactory; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
public class SecurityAccessImpl extends InitablePersistenceBrokerDaoSupport implements SecurityAccess |
48 |
|
{ |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
public SecurityAccessImpl(String repositoryPath) |
56 |
|
{ |
57 |
0 |
super(repositoryPath); |
58 |
0 |
} |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
public boolean isKnownUser(String username) |
69 |
|
{ |
70 |
0 |
UserPrincipal userPrincipal = new UserPrincipalImpl(username); |
71 |
0 |
String fullPath = userPrincipal.getFullPath(); |
72 |
|
|
73 |
0 |
Criteria filter = new Criteria(); |
74 |
0 |
filter.addEqualTo("fullPath", fullPath); |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
0 |
filter.addEqualTo("isMappingOnly", Boolean.FALSE); |
79 |
0 |
Query query = QueryFactory.newQuery(InternalUserPrincipalImpl.class, filter); |
80 |
0 |
return getPersistenceBrokerTemplate().getCount(query) == 1; |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
public InternalUserPrincipal getInternalUserPrincipal(String username) |
92 |
|
{ |
93 |
0 |
UserPrincipal userPrincipal = new UserPrincipalImpl(username); |
94 |
0 |
String fullPath = userPrincipal.getFullPath(); |
95 |
|
|
96 |
0 |
Criteria filter = new Criteria(); |
97 |
0 |
filter.addEqualTo("fullPath", fullPath); |
98 |
0 |
Query query = QueryFactory.newQuery(InternalUserPrincipalImpl.class, filter); |
99 |
0 |
InternalUserPrincipal internalUser = (InternalUserPrincipal) getPersistenceBrokerTemplate().getObjectByQuery(query); |
100 |
0 |
return internalUser; |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
public InternalUserPrincipal getInternalUserPrincipal(String username, boolean isMappingOnly) |
113 |
|
{ |
114 |
0 |
UserPrincipal userPrincipal = new UserPrincipalImpl(username); |
115 |
0 |
String fullPath = userPrincipal.getFullPath(); |
116 |
|
|
117 |
0 |
Criteria filter = new Criteria(); |
118 |
0 |
filter.addEqualTo("fullPath", fullPath); |
119 |
0 |
filter.addEqualTo("isMappingOnly", new Boolean(isMappingOnly)); |
120 |
0 |
Query query = QueryFactory.newQuery(InternalUserPrincipalImpl.class, filter); |
121 |
0 |
InternalUserPrincipal internalUser = (InternalUserPrincipal) getPersistenceBrokerTemplate().getObjectByQuery(query); |
122 |
0 |
return internalUser; |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
public Iterator getInternalUserPrincipals(String filter) |
134 |
|
{ |
135 |
0 |
Criteria queryCriteria = new Criteria(); |
136 |
0 |
queryCriteria.addEqualTo("isMappingOnly", new Boolean(false)); |
137 |
0 |
queryCriteria.addLike("fullPath", UserPrincipal.PREFS_USER_ROOT + filter + "%"); |
138 |
0 |
Query query = QueryFactory.newQuery(InternalUserPrincipalImpl.class, queryCriteria); |
139 |
0 |
Iterator result = getPersistenceBrokerTemplate().getIteratorByQuery(query); |
140 |
0 |
return result; |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
public void setInternalUserPrincipal(InternalUserPrincipal internalUser, boolean isMappingOnly) throws SecurityException |
153 |
|
{ |
154 |
|
try |
155 |
|
{ |
156 |
0 |
if (isMappingOnly) |
157 |
|
{ |
158 |
0 |
internalUser.setMappingOnly(isMappingOnly); |
159 |
|
} |
160 |
0 |
getPersistenceBrokerTemplate().store(internalUser); |
161 |
|
} |
162 |
0 |
catch (Exception e) |
163 |
|
{ |
164 |
0 |
KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.setInternalUserPrincipal", |
165 |
|
"store", |
166 |
|
e.getMessage()); |
167 |
0 |
logger.error(msg, e); |
168 |
0 |
throw new SecurityException(msg, e); |
169 |
0 |
} |
170 |
0 |
} |
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
public void removeInternalUserPrincipal(InternalUserPrincipal internalUser) throws SecurityException |
181 |
|
{ |
182 |
|
try |
183 |
|
{ |
184 |
|
|
185 |
0 |
getPersistenceBrokerTemplate().delete(internalUser); |
186 |
0 |
if (logger.isDebugEnabled()) |
187 |
|
{ |
188 |
0 |
logger.debug("Deleted user: " + internalUser.getFullPath()); |
189 |
|
} |
190 |
|
|
191 |
|
} |
192 |
0 |
catch (Exception e) |
193 |
|
{ |
194 |
0 |
KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.removeInternalUserPrincipal", |
195 |
|
"store", |
196 |
|
e.getMessage()); |
197 |
0 |
logger.error(msg, e); |
198 |
0 |
throw new SecurityException(msg, e); |
199 |
0 |
} |
200 |
0 |
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
public InternalRolePrincipal getInternalRolePrincipal(String roleFullPathName) |
211 |
|
{ |
212 |
0 |
Criteria filter = new Criteria(); |
213 |
0 |
filter.addEqualTo("fullPath", roleFullPathName); |
214 |
0 |
Query query = QueryFactory.newQuery(InternalRolePrincipalImpl.class, filter); |
215 |
0 |
InternalRolePrincipal internalRole = (InternalRolePrincipal) getPersistenceBrokerTemplate().getObjectByQuery(query); |
216 |
0 |
return internalRole; |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
public void setInternalRolePrincipal(InternalRolePrincipal internalRole, boolean isMappingOnly) throws SecurityException |
229 |
|
{ |
230 |
|
try |
231 |
|
{ |
232 |
0 |
if (isMappingOnly) |
233 |
|
{ |
234 |
0 |
internalRole.setMappingOnly(isMappingOnly); |
235 |
|
} |
236 |
0 |
getPersistenceBrokerTemplate().store(internalRole); |
237 |
|
} |
238 |
0 |
catch (Exception e) |
239 |
|
{ |
240 |
0 |
KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.setInternalRolePrincipal", |
241 |
|
"store", |
242 |
|
e.getMessage()); |
243 |
0 |
logger.error(msg, e); |
244 |
0 |
throw new SecurityException(msg, e); |
245 |
0 |
} |
246 |
0 |
} |
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
public void removeInternalRolePrincipal(InternalRolePrincipal internalRole) throws SecurityException |
257 |
|
{ |
258 |
|
try |
259 |
|
{ |
260 |
|
|
261 |
|
|
262 |
0 |
getPersistenceBrokerTemplate().delete(internalRole); |
263 |
0 |
if (logger.isDebugEnabled()) |
264 |
|
{ |
265 |
0 |
logger.debug("Deleted role: " + internalRole.getFullPath()); |
266 |
|
} |
267 |
|
|
268 |
|
} |
269 |
0 |
catch (Exception e) |
270 |
|
{ |
271 |
0 |
KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.removeInternalRolePrincipal", |
272 |
|
"store", |
273 |
|
e.getMessage()); |
274 |
0 |
logger.error(msg, e); |
275 |
0 |
throw new SecurityException(msg, e); |
276 |
0 |
} |
277 |
|
|
278 |
0 |
} |
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
public InternalGroupPrincipal getInternalGroupPrincipal(String groupFullPathName) |
289 |
|
{ |
290 |
0 |
Criteria filter = new Criteria(); |
291 |
0 |
filter.addEqualTo("fullPath", groupFullPathName); |
292 |
0 |
Query query = QueryFactory.newQuery(InternalGroupPrincipalImpl.class, filter); |
293 |
0 |
InternalGroupPrincipal internalGroup = (InternalGroupPrincipal) getPersistenceBrokerTemplate().getObjectByQuery(query); |
294 |
0 |
return internalGroup; |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
public void setInternalGroupPrincipal(InternalGroupPrincipal internalGroup, boolean isMappingOnly) throws SecurityException |
307 |
|
{ |
308 |
|
try |
309 |
|
{ |
310 |
|
|
311 |
0 |
if (isMappingOnly) |
312 |
|
{ |
313 |
0 |
internalGroup.setMappingOnly(isMappingOnly); |
314 |
|
} |
315 |
0 |
getPersistenceBrokerTemplate().store(internalGroup); |
316 |
|
} |
317 |
0 |
catch (Exception e) |
318 |
|
{ |
319 |
0 |
KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.setInternalGroupPrincipal", |
320 |
|
"store", |
321 |
|
e.getMessage()); |
322 |
0 |
logger.error(msg, e); |
323 |
0 |
throw new SecurityException(msg, e); |
324 |
0 |
} |
325 |
0 |
} |
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
public void removeInternalGroupPrincipal(InternalGroupPrincipal internalGroup) throws SecurityException |
336 |
|
{ |
337 |
|
try |
338 |
|
{ |
339 |
|
|
340 |
0 |
getPersistenceBrokerTemplate().delete(internalGroup); |
341 |
|
|
342 |
0 |
if (logger.isDebugEnabled()) |
343 |
|
{ |
344 |
0 |
logger.debug("Deleted group: " + internalGroup.getFullPath()); |
345 |
|
} |
346 |
|
|
347 |
|
} |
348 |
0 |
catch (Exception e) |
349 |
|
{ |
350 |
0 |
KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.removeInternalGroupPrincipal", |
351 |
|
"store", |
352 |
|
e.getMessage()); |
353 |
0 |
logger.error(msg, e); |
354 |
0 |
throw new SecurityException(msg, e); |
355 |
0 |
} |
356 |
|
|
357 |
0 |
} |
358 |
|
|
359 |
|
public Iterator getInternalRolePrincipals(String filter) |
360 |
|
{ |
361 |
0 |
Criteria queryCriteria = new Criteria(); |
362 |
0 |
queryCriteria.addEqualTo("isMappingOnly", new Boolean(false)); |
363 |
0 |
queryCriteria.addLike("fullPath", UserPrincipal.PREFS_ROLE_ROOT + filter + "%"); |
364 |
0 |
Query query = QueryFactory.newQuery(InternalRolePrincipalImpl.class, queryCriteria); |
365 |
0 |
Collection c = getPersistenceBrokerTemplate().getCollectionByQuery(query); |
366 |
0 |
return c.iterator(); |
367 |
|
} |
368 |
|
|
369 |
|
public Iterator getInternalGroupPrincipals(String filter) |
370 |
|
{ |
371 |
|
|
372 |
0 |
Criteria queryCriteria = new Criteria(); |
373 |
0 |
queryCriteria.addEqualTo("isMappingOnly", new Boolean(false)); |
374 |
0 |
queryCriteria.addLike("fullPath", UserPrincipal.PREFS_GROUP_ROOT + filter + "%"); |
375 |
0 |
Query query = QueryFactory.newQuery(InternalGroupPrincipalImpl.class, queryCriteria); |
376 |
0 |
Collection c = getPersistenceBrokerTemplate().getCollectionByQuery(query); |
377 |
0 |
return c.iterator(); |
378 |
|
} |
379 |
|
|
380 |
|
} |