KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > security > permissions > impl > acegi > ACLEntryAfterInvocationTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.security.permissions.impl.acegi;
18
19 import java.lang.reflect.InvocationTargetException JavaDoc;
20 import java.lang.reflect.Method JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import net.sf.acegisecurity.ConfigAttribute;
28 import net.sf.acegisecurity.ConfigAttributeDefinition;
29
30 import org.alfresco.model.ContentModel;
31 import org.alfresco.repo.search.results.ChildAssocRefResultSet;
32 import org.alfresco.repo.security.permissions.impl.AbstractPermissionTest;
33 import org.alfresco.repo.security.permissions.impl.SimplePermissionEntry;
34 import org.alfresco.service.cmr.repository.ChildAssociationRef;
35 import org.alfresco.service.cmr.repository.NodeRef;
36 import org.alfresco.service.cmr.repository.StoreRef;
37 import org.alfresco.service.cmr.search.ResultSet;
38 import org.alfresco.service.cmr.security.AccessStatus;
39 import org.alfresco.service.cmr.security.PermissionService;
40 import org.alfresco.service.namespace.QName;
41 import org.aopalliance.intercept.MethodInterceptor;
42 import org.aopalliance.intercept.MethodInvocation;
43 import org.springframework.aop.framework.ProxyFactory;
44 import org.springframework.aop.framework.adapter.AdvisorAdapterRegistry;
45 import org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry;
46 import org.springframework.aop.target.SingletonTargetSource;
47
48 public class ACLEntryAfterInvocationTest extends AbstractPermissionTest
49 {
50
51     public ACLEntryAfterInvocationTest()
52     {
53         super();
54     }
55
56     public void testBasicAllowNullNode() throws Exception JavaDoc
57     {
58         runAs("andy");
59
60         Object JavaDoc o = new ClassWithMethods();
61         Method JavaDoc method = o.getClass().getMethod("echoNodeRef", new Class JavaDoc[] { NodeRef.class });
62
63         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
64
65         ProxyFactory proxyFactory = new ProxyFactory();
66         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
67         proxyFactory.setTargetSource(new SingletonTargetSource(o));
68         Object JavaDoc proxy = proxyFactory.getProxy();
69
70         Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { null });
71         assertNull(answer);
72     }
73     
74     public void testBasicAllowNullStore() throws Exception JavaDoc
75     {
76         runAs("andy");
77
78         Object JavaDoc o = new ClassWithMethods();
79         Method JavaDoc method = o.getClass().getMethod("echoStoreRef", new Class JavaDoc[] { StoreRef.class });
80
81         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
82
83         ProxyFactory proxyFactory = new ProxyFactory();
84         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
85         proxyFactory.setTargetSource(new SingletonTargetSource(o));
86         Object JavaDoc proxy = proxyFactory.getProxy();
87
88         Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { null });
89         assertNull(answer);
90     }
91
92     public void testBasicAllowUnrecognisedObject() throws Exception JavaDoc
93     {
94         runAs("andy");
95
96         Object JavaDoc o = new ClassWithMethods();
97         Method JavaDoc method = o.getClass().getMethod("echoObject", new Class JavaDoc[] { Object JavaDoc.class });
98
99         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
100
101         ProxyFactory proxyFactory = new ProxyFactory();
102         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
103         proxyFactory.setTargetSource(new SingletonTargetSource(o));
104         Object JavaDoc proxy = proxyFactory.getProxy();
105
106         Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { "noodle" });
107         assertNotNull(answer);
108     }
109
110     public void testBasicDenyStore() throws Exception JavaDoc
111     {
112         runAs("andy");
113
114         Object JavaDoc o = new ClassWithMethods();
115         Method JavaDoc method = o.getClass().getMethod("echoStoreRef", new Class JavaDoc[] { StoreRef.class });
116
117         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
118
119         ProxyFactory proxyFactory = new ProxyFactory();
120         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
121         proxyFactory.setTargetSource(new SingletonTargetSource(o));
122         Object JavaDoc proxy = proxyFactory.getProxy();
123
124         try
125         {
126             Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { rootNodeRef.getStoreRef() });
127             assertNotNull(answer);
128         }
129         catch (InvocationTargetException JavaDoc e)
130         {
131
132         }
133
134     }
135     
136     public void testBasicDenyNode() throws Exception JavaDoc
137     {
138         runAs("andy");
139
140         Object JavaDoc o = new ClassWithMethods();
141         Method JavaDoc method = o.getClass().getMethod("echoNodeRef", new Class JavaDoc[] { NodeRef.class });
142
143         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
144
145         ProxyFactory proxyFactory = new ProxyFactory();
146         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
147         proxyFactory.setTargetSource(new SingletonTargetSource(o));
148         Object JavaDoc proxy = proxyFactory.getProxy();
149
150         try
151         {
152             Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { rootNodeRef });
153             assertNotNull(answer);
154         }
155         catch (InvocationTargetException JavaDoc e)
156         {
157
158         }
159
160     }
161
162     public void testBasicAllowNode() throws Exception JavaDoc
163     {
164         runAs("andy");
165
166         Object JavaDoc o = new ClassWithMethods();
167         Method JavaDoc method = o.getClass().getMethod("echoNodeRef", new Class JavaDoc[] { NodeRef.class });
168
169         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
170
171         ProxyFactory proxyFactory = new ProxyFactory();
172         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
173         proxyFactory.setTargetSource(new SingletonTargetSource(o));
174         Object JavaDoc proxy = proxyFactory.getProxy();
175
176         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
177
178         Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { rootNodeRef });
179         assertEquals(answer, rootNodeRef);
180
181     }
182     
183     public void testBasicAllowStore() throws Exception JavaDoc
184     {
185         runAs("andy");
186
187         Object JavaDoc o = new ClassWithMethods();
188         Method JavaDoc method = o.getClass().getMethod("echoStoreRef", new Class JavaDoc[] { StoreRef.class });
189
190         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
191
192         ProxyFactory proxyFactory = new ProxyFactory();
193         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
194         proxyFactory.setTargetSource(new SingletonTargetSource(o));
195         Object JavaDoc proxy = proxyFactory.getProxy();
196
197         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
198
199         Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { rootNodeRef.getStoreRef() });
200         assertEquals(answer, rootNodeRef.getStoreRef());
201
202     }
203
204     public void testBasicAllowNodeParent() throws Exception JavaDoc
205     {
206         runAs("andy");
207
208         Object JavaDoc o = new ClassWithMethods();
209         Method JavaDoc method = o.getClass().getMethod("echoNodeRef", new Class JavaDoc[] { NodeRef.class });
210
211         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
212
213         ProxyFactory proxyFactory = new ProxyFactory();
214         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_PARENT.sys:base.Read")));
215         proxyFactory.setTargetSource(new SingletonTargetSource(o));
216         Object JavaDoc proxy = proxyFactory.getProxy();
217
218         Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { rootNodeRef });
219         assertEquals(answer, rootNodeRef);
220
221         try
222         {
223             answer = method.invoke(proxy, new Object JavaDoc[] { systemNodeRef });
224             assertNotNull(answer);
225         }
226         catch (InvocationTargetException JavaDoc e)
227         {
228
229         }
230
231         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
232
233         answer = method.invoke(proxy, new Object JavaDoc[] { systemNodeRef });
234         assertEquals(answer, systemNodeRef);
235     }
236
237     public void testBasicAllowNullChildAssociationRef1() throws Exception JavaDoc
238     {
239         runAs("andy");
240
241         Object JavaDoc o = new ClassWithMethods();
242         Method JavaDoc method = o.getClass().getMethod("echoChildAssocRef", new Class JavaDoc[] { ChildAssociationRef.class });
243
244         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
245
246         ProxyFactory proxyFactory = new ProxyFactory();
247         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
248         proxyFactory.setTargetSource(new SingletonTargetSource(o));
249         Object JavaDoc proxy = proxyFactory.getProxy();
250
251         Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { null });
252         assertNull(answer);
253     }
254
255     public void testBasicAllowNullChildAssociationRef2() throws Exception JavaDoc
256     {
257         runAs("andy");
258
259         Object JavaDoc o = new ClassWithMethods();
260         Method JavaDoc method = o.getClass().getMethod("echoChildAssocRef", new Class JavaDoc[] { ChildAssociationRef.class });
261
262         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
263
264         ProxyFactory proxyFactory = new ProxyFactory();
265         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_PARENT.sys:base.Read")));
266         proxyFactory.setTargetSource(new SingletonTargetSource(o));
267         Object JavaDoc proxy = proxyFactory.getProxy();
268
269         Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { null });
270         assertNull(answer);
271     }
272
273     public void testBasicDenyChildAssocRef1() throws Exception JavaDoc
274     {
275         runAs("andy");
276
277         Object JavaDoc o = new ClassWithMethods();
278         Method JavaDoc method = o.getClass().getMethod("echoChildAssocRef", new Class JavaDoc[] { ChildAssociationRef.class });
279
280         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
281
282         ProxyFactory proxyFactory = new ProxyFactory();
283         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
284         proxyFactory.setTargetSource(new SingletonTargetSource(o));
285         Object JavaDoc proxy = proxyFactory.getProxy();
286
287         try
288         {
289             Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(rootNodeRef) });
290             assertNotNull(answer);
291         }
292         catch (InvocationTargetException JavaDoc e)
293         {
294
295         }
296
297         try
298         {
299             Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(systemNodeRef) });
300             assertNotNull(answer);
301         }
302         catch (InvocationTargetException JavaDoc e)
303         {
304
305         }
306
307     }
308
309     public void testBasicDenyChildAssocRef2() throws Exception JavaDoc
310     {
311         runAs("andy");
312
313         Object JavaDoc o = new ClassWithMethods();
314         Method JavaDoc method = o.getClass().getMethod("echoChildAssocRef", new Class JavaDoc[] { ChildAssociationRef.class });
315
316         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
317
318         ProxyFactory proxyFactory = new ProxyFactory();
319         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_PARENT.sys:base.Read")));
320         proxyFactory.setTargetSource(new SingletonTargetSource(o));
321         Object JavaDoc proxy = proxyFactory.getProxy();
322
323         Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(rootNodeRef) });
324         assertNotNull(answer);
325
326         try
327         {
328             answer = method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(systemNodeRef) });
329             assertNotNull(answer);
330         }
331         catch (InvocationTargetException JavaDoc e)
332         {
333
334         }
335
336     }
337
338     public void testBasicAllowChildAssociationRef1() throws Exception JavaDoc
339     {
340         runAs("andy");
341
342         Object JavaDoc o = new ClassWithMethods();
343         Method JavaDoc method = o.getClass().getMethod("echoChildAssocRef", new Class JavaDoc[] { ChildAssociationRef.class });
344
345         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
346
347         ProxyFactory proxyFactory = new ProxyFactory();
348         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
349         proxyFactory.setTargetSource(new SingletonTargetSource(o));
350         Object JavaDoc proxy = proxyFactory.getProxy();
351
352         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
353
354         Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(rootNodeRef) });
355         assertEquals(answer, nodeService.getPrimaryParent(rootNodeRef));
356
357         answer = method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(systemNodeRef) });
358         assertEquals(answer, nodeService.getPrimaryParent(systemNodeRef));
359
360     }
361
362     public void testBasicAllowChildAssociationRef2() throws Exception JavaDoc
363     {
364         runAs("andy");
365
366         Object JavaDoc o = new ClassWithMethods();
367         Method JavaDoc method = o.getClass().getMethod("echoChildAssocRef", new Class JavaDoc[] { ChildAssociationRef.class });
368
369         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
370
371         ProxyFactory proxyFactory = new ProxyFactory();
372         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_PARENT.sys:base.Read")));
373         proxyFactory.setTargetSource(new SingletonTargetSource(o));
374         Object JavaDoc proxy = proxyFactory.getProxy();
375
376         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
377
378         Object JavaDoc answer = method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(rootNodeRef) });
379         assertEquals(answer, nodeService.getPrimaryParent(rootNodeRef));
380
381         answer = method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(systemNodeRef) });
382         assertEquals(answer, nodeService.getPrimaryParent(systemNodeRef));
383     }
384
385     public void testBasicAllowNullResultSet() throws Exception JavaDoc
386     {
387         runAs("andy");
388
389         Object JavaDoc o = new ClassWithMethods();
390         Method JavaDoc methodResultSet = o.getClass().getMethod("echoResultSet", new Class JavaDoc[] { ResultSet.class });
391         Method JavaDoc methodCollection = o.getClass().getMethod("echoCollection", new Class JavaDoc[] { Collection JavaDoc.class });
392         Method JavaDoc methodArray = o.getClass().getMethod("echoArray", new Class JavaDoc[] { Object JavaDoc[].class });
393
394         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
395
396         ProxyFactory proxyFactory = new ProxyFactory();
397         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
398         proxyFactory.setTargetSource(new SingletonTargetSource(o));
399         Object JavaDoc proxy = proxyFactory.getProxy();
400
401         List JavaDoc<NodeRef> nodeRefList = new ArrayList JavaDoc<NodeRef>();
402         NodeRef[] nodeRefArray = new NodeRef[0];
403
404         Set JavaDoc<NodeRef> nodeRefSet = new HashSet JavaDoc<NodeRef>();
405         
406         List JavaDoc<ChildAssociationRef> carList = new ArrayList JavaDoc<ChildAssociationRef>();
407
408         ChildAssociationRef[] carArray = new ChildAssociationRef[0];
409
410         Set JavaDoc<ChildAssociationRef> carSet = new HashSet JavaDoc<ChildAssociationRef>();
411        
412         ChildAssocRefResultSet rsIn = new ChildAssocRefResultSet(nodeService, nodeRefList, null, false);
413
414         assertEquals(0, rsIn.length());
415         ResultSet answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object JavaDoc[] { rsIn });
416         assertEquals(0, answerResultSet.length());
417         Collection JavaDoc answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefList });
418         assertEquals(0, answerCollection.size());
419         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefSet });
420         assertEquals(0, answerCollection.size());
421         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carList });
422         assertEquals(0, answerCollection.size());
423         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carSet });
424         assertEquals(0, answerCollection.size());
425         Object JavaDoc[] answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { nodeRefArray });
426         assertEquals(0, answerArray.length);
427         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { carArray });
428         assertEquals(0, answerArray.length);
429         
430         assertEquals(0, rsIn.length());
431         answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object JavaDoc[] { null });
432         assertNull(answerResultSet);
433         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { null });
434         assertNull(answerCollection);
435         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { null });
436         assertNull(answerArray);
437     }
438
439     public void testResultSetFilterAll() throws Exception JavaDoc
440     {
441         runAs("admin");
442         
443         NodeRef n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN,
444                 QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
445
446         runAs("andy");
447
448         Object JavaDoc o = new ClassWithMethods();
449         Method JavaDoc methodResultSet = o.getClass().getMethod("echoResultSet", new Class JavaDoc[] { ResultSet.class });
450         Method JavaDoc methodCollection = o.getClass().getMethod("echoCollection", new Class JavaDoc[] { Collection JavaDoc.class });
451         Method JavaDoc methodArray = o.getClass().getMethod("echoArray", new Class JavaDoc[] { Object JavaDoc[].class });
452
453         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
454
455         ProxyFactory proxyFactory = new ProxyFactory();
456         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
457         proxyFactory.setTargetSource(new SingletonTargetSource(o));
458         Object JavaDoc proxy = proxyFactory.getProxy();
459
460         List JavaDoc<NodeRef> nodeRefList = new ArrayList JavaDoc<NodeRef>();
461         nodeRefList.add(rootNodeRef);
462         nodeRefList.add(systemNodeRef);
463         nodeRefList.add(n1);
464         nodeRefList.add(n1);
465
466         NodeRef[] nodeRefArray = nodeRefList.toArray(new NodeRef[] {});
467
468         Set JavaDoc<NodeRef> nodeRefSet = new HashSet JavaDoc<NodeRef>();
469         nodeRefSet.addAll(nodeRefList);
470
471         List JavaDoc<ChildAssociationRef> carList = new ArrayList JavaDoc<ChildAssociationRef>();
472         carList.add(nodeService.getPrimaryParent(rootNodeRef));
473         carList.add(nodeService.getPrimaryParent(systemNodeRef));
474         carList.add(nodeService.getPrimaryParent(n1));
475         carList.add(nodeService.getPrimaryParent(n1));
476
477         ChildAssociationRef[] carArray = carList.toArray(new ChildAssociationRef[] {});
478
479         Set JavaDoc<ChildAssociationRef> carSet = new HashSet JavaDoc<ChildAssociationRef>();
480         carSet.addAll(carList);
481
482         ChildAssocRefResultSet rsIn = new ChildAssocRefResultSet(nodeService, nodeRefList, null, false);
483
484         assertEquals(4, rsIn.length());
485         ResultSet answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object JavaDoc[] { rsIn });
486         assertEquals(0, answerResultSet.length());
487         Collection JavaDoc answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefList });
488         assertEquals(0, answerCollection.size());
489         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefSet });
490         assertEquals(0, answerCollection.size());
491         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carList });
492         assertEquals(0, answerCollection.size());
493         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carSet });
494         assertEquals(0, answerCollection.size());
495         Object JavaDoc[] answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { nodeRefArray });
496         assertEquals(0, answerArray.length);
497         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { carArray });
498         assertEquals(0, answerArray.length);
499     }
500
501     public void testResultSetFilterForNullParentOnly() throws Exception JavaDoc
502     {
503         runAs("admin");
504         NodeRef n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN,
505                 QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
506
507         runAs("andy");
508
509         Object JavaDoc o = new ClassWithMethods();
510         Method JavaDoc methodResultSet = o.getClass().getMethod("echoResultSet", new Class JavaDoc[] { ResultSet.class });
511         Method JavaDoc methodCollection = o.getClass().getMethod("echoCollection", new Class JavaDoc[] { Collection JavaDoc.class });
512         Method JavaDoc methodArray = o.getClass().getMethod("echoArray", new Class JavaDoc[] { Object JavaDoc[].class });
513
514         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
515
516         ProxyFactory proxyFactory = new ProxyFactory();
517         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_PARENT.sys:base.Read")));
518         proxyFactory.setTargetSource(new SingletonTargetSource(o));
519         Object JavaDoc proxy = proxyFactory.getProxy();
520
521         List JavaDoc<NodeRef> nodeRefList = new ArrayList JavaDoc<NodeRef>();
522         nodeRefList.add(rootNodeRef);
523         nodeRefList.add(systemNodeRef);
524         nodeRefList.add(n1);
525         nodeRefList.add(n1);
526
527         NodeRef[] nodeRefArray = nodeRefList.toArray(new NodeRef[] {});
528
529         Set JavaDoc<NodeRef> nodeRefSet = new HashSet JavaDoc<NodeRef>();
530         nodeRefSet.addAll(nodeRefList);
531
532         List JavaDoc<ChildAssociationRef> carList = new ArrayList JavaDoc<ChildAssociationRef>();
533         carList.add(nodeService.getPrimaryParent(rootNodeRef));
534         carList.add(nodeService.getPrimaryParent(systemNodeRef));
535         carList.add(nodeService.getPrimaryParent(n1));
536         carList.add(nodeService.getPrimaryParent(n1));
537
538         ChildAssociationRef[] carArray = carList.toArray(new ChildAssociationRef[] {});
539
540         Set JavaDoc<ChildAssociationRef> carSet = new HashSet JavaDoc<ChildAssociationRef>();
541         carSet.addAll(carList);
542
543         ChildAssocRefResultSet rsIn = new ChildAssocRefResultSet(nodeService, nodeRefList, null, false);
544
545
546         assertEquals(4, rsIn.length());
547         ResultSet answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object JavaDoc[] { rsIn });
548         assertEquals(1, answerResultSet.length());
549         Collection JavaDoc answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefList });
550         assertEquals(1, answerCollection.size());
551         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefSet });
552         assertEquals(1, answerCollection.size());
553         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carList });
554         assertEquals(1, answerCollection.size());
555         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carSet });
556         assertEquals(1, answerCollection.size());
557         Object JavaDoc[] answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { nodeRefArray });
558         assertEquals(1, answerArray.length);
559         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { carArray });
560         assertEquals(1, answerArray.length);
561     }
562
563     public void testResultSetFilterNone1() throws Exception JavaDoc
564     {
565         runAs("admin");
566         NodeRef n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN,
567                 QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
568
569         runAs("andy");
570
571         Object JavaDoc o = new ClassWithMethods();
572         Method JavaDoc methodResultSet = o.getClass().getMethod("echoResultSet", new Class JavaDoc[] { ResultSet.class });
573         Method JavaDoc methodCollection = o.getClass().getMethod("echoCollection", new Class JavaDoc[] { Collection JavaDoc.class });
574         Method JavaDoc methodArray = o.getClass().getMethod("echoArray", new Class JavaDoc[] { Object JavaDoc[].class });
575
576         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
577
578         ProxyFactory proxyFactory = new ProxyFactory();
579         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
580         proxyFactory.setTargetSource(new SingletonTargetSource(o));
581         Object JavaDoc proxy = proxyFactory.getProxy();
582
583         List JavaDoc<NodeRef> nodeRefList = new ArrayList JavaDoc<NodeRef>();
584         nodeRefList.add(rootNodeRef);
585         nodeRefList.add(systemNodeRef);
586         nodeRefList.add(n1);
587         nodeRefList.add(n1);
588         
589         List JavaDoc<Object JavaDoc> mixedRefList = new ArrayList JavaDoc<Object JavaDoc>();
590         mixedRefList.add(rootNodeRef);
591         mixedRefList.add(systemNodeRef);
592         mixedRefList.add(n1);
593         mixedRefList.add(n1);
594         mixedRefList.add(rootNodeRef.getStoreRef());
595
596         NodeRef[] nodeRefArray = nodeRefList.toArray(new NodeRef[] {});
597
598
599         Set JavaDoc<NodeRef> nodeRefSet = new HashSet JavaDoc<NodeRef>();
600         nodeRefSet.addAll(nodeRefList);
601         
602         Set JavaDoc<Object JavaDoc> mixedRefSet = new HashSet JavaDoc<Object JavaDoc>();
603         mixedRefSet.addAll(mixedRefList);
604
605         List JavaDoc<ChildAssociationRef> carList = new ArrayList JavaDoc<ChildAssociationRef>();
606         carList.add(nodeService.getPrimaryParent(rootNodeRef));
607         carList.add(nodeService.getPrimaryParent(systemNodeRef));
608         carList.add(nodeService.getPrimaryParent(n1));
609         carList.add(nodeService.getPrimaryParent(n1));
610
611         ChildAssociationRef[] carArray = carList.toArray(new ChildAssociationRef[] {});
612
613         Set JavaDoc<ChildAssociationRef> carSet = new HashSet JavaDoc<ChildAssociationRef>();
614         carSet.addAll(carList);
615
616         ChildAssocRefResultSet rsIn = new ChildAssocRefResultSet(nodeService, nodeRefList, null, false);
617
618         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
619
620         assertEquals(4, rsIn.length());
621         ResultSet answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object JavaDoc[] { rsIn });
622         assertEquals(4, answerResultSet.length());
623         Collection JavaDoc answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefList });
624         assertEquals(4, answerCollection.size());
625         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefList });
626         assertEquals(5, answerCollection.size());
627         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefSet });
628         assertEquals(3, answerCollection.size());
629         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefSet });
630         assertEquals(4, answerCollection.size());
631         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carList });
632         assertEquals(4, answerCollection.size());
633         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carSet });
634         assertEquals(3, answerCollection.size());
635         Object JavaDoc[] answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { nodeRefArray });
636         assertEquals(4, answerArray.length);
637         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { carArray });
638         assertEquals(4, answerArray.length);
639
640         permissionService.setPermission(new SimplePermissionEntry(n1, getPermission(PermissionService.READ), "andy", AccessStatus.DENIED));
641
642         assertEquals(4, rsIn.length());
643         answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object JavaDoc[] { rsIn });
644         assertEquals(2, answerResultSet.length());
645         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefList });
646         assertEquals(2, answerCollection.size());
647         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefList });
648         assertEquals(3, answerCollection.size());
649         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefSet });
650         assertEquals(2, answerCollection.size());
651         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefSet });
652         assertEquals(3, answerCollection.size());
653         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carList });
654         assertEquals(2, answerCollection.size());
655         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carSet });
656         assertEquals(2, answerCollection.size());
657         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { nodeRefArray });
658         assertEquals(2, answerArray.length);
659         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { carArray });
660         assertEquals(2, answerArray.length);
661         
662         
663         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.DENIED));
664
665         assertEquals(4, rsIn.length());
666         answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object JavaDoc[] { rsIn });
667         assertEquals(0, answerResultSet.length());
668         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefList });
669         assertEquals(0, answerCollection.size());
670         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefList });
671         assertEquals(0, answerCollection.size());
672         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefSet });
673         assertEquals(0, answerCollection.size());
674         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefSet });
675         assertEquals(0, answerCollection.size());
676         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carList });
677         assertEquals(0, answerCollection.size());
678         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carSet });
679         assertEquals(0, answerCollection.size());
680         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { nodeRefArray });
681         assertEquals(0, answerArray.length);
682         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { carArray });
683         assertEquals(0, answerArray.length);
684
685     }
686
687     public void testResultSetFilterNone2() throws Exception JavaDoc
688     {
689         runAs("admin");
690
691         NodeRef n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN,
692                 QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
693
694         runAs("andy");
695
696         Object JavaDoc o = new ClassWithMethods();
697         Method JavaDoc methodResultSet = o.getClass().getMethod("echoResultSet", new Class JavaDoc[] { ResultSet.class });
698         Method JavaDoc methodCollection = o.getClass().getMethod("echoCollection", new Class JavaDoc[] { Collection JavaDoc.class });
699         Method JavaDoc methodArray = o.getClass().getMethod("echoArray", new Class JavaDoc[] { Object JavaDoc[].class });
700
701         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
702
703         ProxyFactory proxyFactory = new ProxyFactory();
704         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_PARENT.sys:base.Read")));
705         proxyFactory.setTargetSource(new SingletonTargetSource(o));
706         Object JavaDoc proxy = proxyFactory.getProxy();
707
708         List JavaDoc<NodeRef> nodeRefList = new ArrayList JavaDoc<NodeRef>();
709         nodeRefList.add(rootNodeRef);
710         nodeRefList.add(systemNodeRef);
711         nodeRefList.add(n1);
712         nodeRefList.add(n1);
713         
714         List JavaDoc<Object JavaDoc> mixedRefList = new ArrayList JavaDoc<Object JavaDoc>();
715         mixedRefList.add(rootNodeRef);
716         mixedRefList.add(systemNodeRef);
717         mixedRefList.add(n1);
718         mixedRefList.add(n1);
719         mixedRefList.add(rootNodeRef.getStoreRef());
720
721         NodeRef[] nodeRefArray = nodeRefList.toArray(new NodeRef[] {});
722
723         Set JavaDoc<NodeRef> nodeRefSet = new HashSet JavaDoc<NodeRef>();
724         nodeRefSet.addAll(nodeRefList);
725         
726         Set JavaDoc<Object JavaDoc> mixedRefSet = new HashSet JavaDoc<Object JavaDoc>();
727         mixedRefSet.addAll(mixedRefList);
728
729         List JavaDoc<ChildAssociationRef> carList = new ArrayList JavaDoc<ChildAssociationRef>();
730         carList.add(nodeService.getPrimaryParent(rootNodeRef));
731         carList.add(nodeService.getPrimaryParent(systemNodeRef));
732         carList.add(nodeService.getPrimaryParent(n1));
733         carList.add(nodeService.getPrimaryParent(n1));
734
735         ChildAssociationRef[] carArray = carList.toArray(new ChildAssociationRef[] {});
736
737         Set JavaDoc<ChildAssociationRef> carSet = new HashSet JavaDoc<ChildAssociationRef>();
738         carSet.addAll(carList);
739
740         ChildAssocRefResultSet rsIn = new ChildAssocRefResultSet(nodeService, nodeRefList, null, false);
741
742         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
743
744         assertEquals(4, rsIn.length());
745         ResultSet answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object JavaDoc[] { rsIn });
746         assertEquals(4, answerResultSet.length());
747         Collection JavaDoc answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefList });
748         assertEquals(4, answerCollection.size());
749         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefList });
750         assertEquals(5, answerCollection.size());
751         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefSet });
752         assertEquals(3, answerCollection.size());
753         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefSet });
754         assertEquals(4, answerCollection.size());
755         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carList });
756         assertEquals(4, answerCollection.size());
757         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carSet });
758         assertEquals(3, answerCollection.size());
759         Object JavaDoc[] answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { nodeRefArray });
760         assertEquals(4, answerArray.length);
761         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { carArray });
762         assertEquals(4, answerArray.length);
763
764         permissionService.setPermission(new SimplePermissionEntry(n1, getPermission(PermissionService.READ), "andy", AccessStatus.DENIED));
765
766         assertEquals(4, rsIn.length());
767         answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object JavaDoc[] { rsIn });
768         assertEquals(4, answerResultSet.length());
769         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefList });
770         assertEquals(4, answerCollection.size());
771         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefList });
772         assertEquals(5, answerCollection.size());
773         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefSet });
774         assertEquals(3, answerCollection.size());
775         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefSet });
776         assertEquals(4, answerCollection.size());
777         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carList });
778         assertEquals(4, answerCollection.size());
779         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carSet });
780         assertEquals(3, answerCollection.size());
781         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { nodeRefArray });
782         assertEquals(4, answerArray.length);
783         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { carArray });
784         assertEquals(4, answerArray.length);
785         
786         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.DENIED));
787
788         assertEquals(4, rsIn.length());
789         answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object JavaDoc[] { rsIn });
790         assertEquals(1, answerResultSet.length());
791         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefList });
792         assertEquals(1, answerCollection.size());
793         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefList });
794         assertEquals(2, answerCollection.size());
795         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { nodeRefSet });
796         assertEquals(1, answerCollection.size());
797         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { mixedRefSet });
798         assertEquals(2, answerCollection.size());
799         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carList });
800         assertEquals(1, answerCollection.size());
801         answerCollection = (Collection JavaDoc) methodCollection.invoke(proxy, new Object JavaDoc[] { carSet });
802         assertEquals(1, answerCollection.size());
803         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { nodeRefArray });
804         assertEquals(1, answerArray.length);
805         answerArray = (Object JavaDoc[]) methodArray.invoke(proxy, new Object JavaDoc[] { carArray });
806         assertEquals(1, answerArray.length);
807
808     }
809
810     public static class ClassWithMethods
811     {
812
813         public Object JavaDoc echoObject(Object JavaDoc o)
814         {
815             return o;
816         }
817
818         public StoreRef echoStoreRef(StoreRef storeRef)
819         {
820             return storeRef;
821         }
822         
823         public NodeRef echoNodeRef(NodeRef nodeRef)
824         {
825             return nodeRef;
826         }
827
828         public ChildAssociationRef echoChildAssocRef(ChildAssociationRef car)
829         {
830             return car;
831         }
832
833         public ResultSet echoResultSet(ResultSet rs)
834         {
835             return rs;
836         }
837
838         public <T> Collection JavaDoc<T> echoCollection(Collection JavaDoc<T> nrc)
839         {
840             return nrc;
841         }
842
843         public <T> T[] echoArray(T[] nra)
844         {
845             return nra;
846         }
847
848     }
849
850     public class Interceptor implements MethodInterceptor
851     {
852         ConfigAttributeDefinition cad = new ConfigAttributeDefinition();
853
854         Interceptor(final String JavaDoc config)
855         {
856             cad.addConfigAttribute(new ConfigAttribute()
857             {
858
859                 /**
860                  * Comment for <code>serialVersionUID</code>
861                  */

862                 private static final long serialVersionUID = 1L;
863
864                 public String JavaDoc getAttribute()
865                 {
866                     return config;
867                 }
868
869             });
870         }
871
872         public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc
873         {
874             ACLEntryAfterInvocationProvider after = new ACLEntryAfterInvocationProvider();
875             after.setNamespacePrefixResolver(namespacePrefixResolver);
876             after.setPermissionService(permissionService);
877             after.setNodeService(nodeService);
878             after.setAuthenticationService(authenticationService);
879
880             Object JavaDoc returnObject = invocation.proceed();
881             return after.decide(null, invocation, cad, returnObject);
882         }
883     }
884 }
885
Popular Tags