KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 import net.sf.acegisecurity.ConfigAttribute;
23 import net.sf.acegisecurity.ConfigAttributeDefinition;
24 import net.sf.acegisecurity.vote.AccessDecisionVoter;
25
26 import org.alfresco.repo.security.permissions.impl.AbstractPermissionTest;
27 import org.alfresco.repo.security.permissions.impl.SimplePermissionEntry;
28 import org.alfresco.service.cmr.repository.ChildAssociationRef;
29 import org.alfresco.service.cmr.repository.NodeRef;
30 import org.alfresco.service.cmr.repository.StoreRef;
31 import org.alfresco.service.cmr.security.AccessStatus;
32 import org.alfresco.service.cmr.security.PermissionService;
33 import org.aopalliance.intercept.MethodInterceptor;
34 import org.aopalliance.intercept.MethodInvocation;
35 import org.springframework.aop.framework.ProxyFactory;
36 import org.springframework.aop.framework.adapter.AdvisorAdapterRegistry;
37 import org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry;
38 import org.springframework.aop.target.SingletonTargetSource;
39
40 public class ACLEntryVoterTest extends AbstractPermissionTest
41 {
42
43     public ACLEntryVoterTest()
44     {
45         super();
46     }
47
48     public void testBasicDenyNode() throws Exception JavaDoc
49     {
50         runAs("andy");
51
52         Object JavaDoc o = new ClassWithMethods();
53         Method JavaDoc method = o.getClass().getMethod("testOneNodeRef", new Class JavaDoc[] { NodeRef.class });
54
55         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
56
57         ProxyFactory proxyFactory = new ProxyFactory();
58         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
59
60         proxyFactory.setTargetSource(new SingletonTargetSource(o));
61
62         Object JavaDoc proxy = proxyFactory.getProxy();
63
64         try
65         {
66             method.invoke(proxy, new Object JavaDoc[] { rootNodeRef });
67             assertNotNull(null);
68         }
69         catch (InvocationTargetException JavaDoc e)
70         {
71
72         }
73         
74         try
75         {
76             method.invoke(proxy, new Object JavaDoc[] { systemNodeRef });
77             assertNotNull(null);
78         }
79         catch (InvocationTargetException JavaDoc e)
80         {
81
82         }
83         
84         // Check we are allowed access to deleted nodes ..
85

86         nodeService.deleteNode(systemNodeRef);
87         
88         assertNull(method.invoke(proxy, new Object JavaDoc[] { systemNodeRef }));
89
90     }
91     
92     
93     public void testBasicDenyStore() throws Exception JavaDoc
94     {
95         runAs("andy");
96
97         Object JavaDoc o = new ClassWithMethods();
98         Method JavaDoc method = o.getClass().getMethod("testOneStoreRef", new Class JavaDoc[] { StoreRef.class });
99
100         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
101
102         ProxyFactory proxyFactory = new ProxyFactory();
103         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
104
105         proxyFactory.setTargetSource(new SingletonTargetSource(o));
106
107         Object JavaDoc proxy = proxyFactory.getProxy();
108
109         try
110         {
111             method.invoke(proxy, new Object JavaDoc[] { rootNodeRef.getStoreRef() });
112             assertNotNull(null);
113         }
114         catch (InvocationTargetException JavaDoc e)
115         {
116
117         }
118
119     }
120
121     public void testAllowNullNode() throws Exception JavaDoc
122     {
123         runAs("andy");
124
125         Object JavaDoc o = new ClassWithMethods();
126         Method JavaDoc method = o.getClass().getMethod("testOneNodeRef", new Class JavaDoc[] { NodeRef.class });
127
128         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
129
130         ProxyFactory proxyFactory = new ProxyFactory();
131         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
132
133         proxyFactory.setTargetSource(new SingletonTargetSource(o));
134
135         Object JavaDoc proxy = proxyFactory.getProxy();
136
137         method.invoke(proxy, new Object JavaDoc[] { null });
138
139     }
140     
141     public void testAllowNullStore() throws Exception JavaDoc
142     {
143         runAs("andy");
144
145         Object JavaDoc o = new ClassWithMethods();
146         Method JavaDoc method = o.getClass().getMethod("testOneStoreRef", new Class JavaDoc[] { StoreRef.class });
147
148         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
149
150         ProxyFactory proxyFactory = new ProxyFactory();
151         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
152
153         proxyFactory.setTargetSource(new SingletonTargetSource(o));
154
155         Object JavaDoc proxy = proxyFactory.getProxy();
156
157         method.invoke(proxy, new Object JavaDoc[] { null });
158
159     }
160
161     public void testAllowNullParentOnRealChildAssoc() throws Exception JavaDoc
162     {
163         runAs("andy");
164
165         Object JavaDoc o = new ClassWithMethods();
166         Method JavaDoc method = o.getClass().getMethod("testOneChildAssociationRef", new Class JavaDoc[] { ChildAssociationRef.class });
167
168         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
169
170         ProxyFactory proxyFactory = new ProxyFactory();
171         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_PARENT.0.sys:base.Read")));
172
173         proxyFactory.setTargetSource(new SingletonTargetSource(o));
174
175         Object JavaDoc proxy = proxyFactory.getProxy();
176
177         method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(rootNodeRef) });
178
179     }
180
181     public void testAllowNullParent() throws Exception JavaDoc
182     {
183         runAs("andy");
184
185         Object JavaDoc o = new ClassWithMethods();
186         Method JavaDoc method = o.getClass().getMethod("testOneChildAssociationRef", new Class JavaDoc[] { ChildAssociationRef.class });
187
188         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
189
190         ProxyFactory proxyFactory = new ProxyFactory();
191         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_PARENT.0.sys:base.Read")));
192
193         proxyFactory.setTargetSource(new SingletonTargetSource(o));
194
195         Object JavaDoc proxy = proxyFactory.getProxy();
196
197         method.invoke(proxy, new Object JavaDoc[] { null });
198
199     }
200
201     public void testAllowNullChild() throws Exception JavaDoc
202     {
203         runAs("andy");
204
205         Object JavaDoc o = new ClassWithMethods();
206         Method JavaDoc method = o.getClass().getMethod("testOneChildAssociationRef", new Class JavaDoc[] { ChildAssociationRef.class });
207
208         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
209
210         ProxyFactory proxyFactory = new ProxyFactory();
211         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
212
213         proxyFactory.setTargetSource(new SingletonTargetSource(o));
214
215         Object JavaDoc proxy = proxyFactory.getProxy();
216
217         method.invoke(proxy, new Object JavaDoc[] { null });
218
219     }
220
221     public void testBasicDenyChildAssocNode() throws Exception JavaDoc
222     {
223         runAs("andy");
224
225         Object JavaDoc o = new ClassWithMethods();
226         Method JavaDoc method = o.getClass().getMethod("testOneChildAssociationRef", new Class JavaDoc[] { ChildAssociationRef.class });
227
228         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
229
230         ProxyFactory proxyFactory = new ProxyFactory();
231         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
232
233         proxyFactory.setTargetSource(new SingletonTargetSource(o));
234
235         Object JavaDoc proxy = proxyFactory.getProxy();
236
237         try
238         {
239             method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(rootNodeRef) });
240             assertNotNull(null);
241         }
242         catch (InvocationTargetException JavaDoc e)
243         {
244
245         }
246     }
247
248     public void testBasicDenyParentAssocNode() throws Exception JavaDoc
249     {
250         runAs("andy");
251
252         Object JavaDoc o = new ClassWithMethods();
253         Method JavaDoc method = o.getClass().getMethod("testOneChildAssociationRef", new Class JavaDoc[] { ChildAssociationRef.class });
254
255         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
256
257         ProxyFactory proxyFactory = new ProxyFactory();
258         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_PARENT.0.sys:base.Read")));
259
260         proxyFactory.setTargetSource(new SingletonTargetSource(o));
261
262         Object JavaDoc proxy = proxyFactory.getProxy();
263
264         try
265         {
266             method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(systemNodeRef) });
267             assertNotNull(null);
268         }
269         catch (InvocationTargetException JavaDoc e)
270         {
271
272         }
273     }
274
275     public void testBasicAllowNode() throws Exception JavaDoc
276     {
277         runAs("andy");
278
279         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
280
281         Object JavaDoc o = new ClassWithMethods();
282         Method JavaDoc method = o.getClass().getMethod("testOneNodeRef", new Class JavaDoc[] { NodeRef.class });
283
284         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
285
286         ProxyFactory proxyFactory = new ProxyFactory();
287         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
288
289         proxyFactory.setTargetSource(new SingletonTargetSource(o));
290
291         Object JavaDoc proxy = proxyFactory.getProxy();
292
293         method.invoke(proxy, new Object JavaDoc[] { rootNodeRef });
294     }
295     
296     
297     public void testBasicAllow() throws Exception JavaDoc
298     {
299         runAs("andy");
300
301         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
302
303         Object JavaDoc o = new ClassWithMethods();
304         Method JavaDoc method = o.getClass().getMethod("testOneNodeRef", new Class JavaDoc[] { NodeRef.class });
305
306         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
307
308         ProxyFactory proxyFactory = new ProxyFactory();
309         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_ALLOW")));
310
311         proxyFactory.setTargetSource(new SingletonTargetSource(o));
312
313         Object JavaDoc proxy = proxyFactory.getProxy();
314
315         method.invoke(proxy, new Object JavaDoc[] { rootNodeRef });
316     }
317     
318     public void testBasicAllowStore() throws Exception JavaDoc
319     {
320         runAs("andy");
321
322         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
323
324         Object JavaDoc o = new ClassWithMethods();
325         Method JavaDoc method = o.getClass().getMethod("testOneStoreRef", new Class JavaDoc[] { StoreRef.class });
326
327         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
328
329         ProxyFactory proxyFactory = new ProxyFactory();
330         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
331
332         proxyFactory.setTargetSource(new SingletonTargetSource(o));
333
334         Object JavaDoc proxy = proxyFactory.getProxy();
335
336         method.invoke(proxy, new Object JavaDoc[] { rootNodeRef.getStoreRef() });
337     }
338
339     public void testBasicAllowChildAssocNode() throws Exception JavaDoc
340     {
341         runAs("andy");
342
343         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
344
345         Object JavaDoc o = new ClassWithMethods();
346         Method JavaDoc method = o.getClass().getMethod("testOneChildAssociationRef", new Class JavaDoc[] { ChildAssociationRef.class });
347
348         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
349
350         ProxyFactory proxyFactory = new ProxyFactory();
351         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
352
353         proxyFactory.setTargetSource(new SingletonTargetSource(o));
354
355         Object JavaDoc proxy = proxyFactory.getProxy();
356
357         method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(rootNodeRef) });
358     }
359
360     public void testBasicAllowParentAssocNode() throws Exception JavaDoc
361     {
362         runAs("andy");
363
364         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
365
366         Object JavaDoc o = new ClassWithMethods();
367         Method JavaDoc method = o.getClass().getMethod("testOneChildAssociationRef", new Class JavaDoc[] { ChildAssociationRef.class });
368
369         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
370
371         ProxyFactory proxyFactory = new ProxyFactory();
372         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_PARENT.0.sys:base.Read")));
373
374         proxyFactory.setTargetSource(new SingletonTargetSource(o));
375
376         Object JavaDoc proxy = proxyFactory.getProxy();
377
378         method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(systemNodeRef) });
379     }
380
381     public void testDenyParentAssocNode() throws Exception JavaDoc
382     {
383         runAs("andy");
384
385         permissionService.setPermission(new SimplePermissionEntry(systemNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
386
387         Object JavaDoc o = new ClassWithMethods();
388         Method JavaDoc method = o.getClass().getMethod("testOneChildAssociationRef", new Class JavaDoc[] { ChildAssociationRef.class });
389
390         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
391
392         ProxyFactory proxyFactory = new ProxyFactory();
393         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_PARENT.0.sys:base.Read")));
394
395         proxyFactory.setTargetSource(new SingletonTargetSource(o));
396
397         Object JavaDoc proxy = proxyFactory.getProxy();
398
399         try
400         {
401             method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(systemNodeRef) });
402             assertNotNull(null);
403         }
404         catch (InvocationTargetException JavaDoc e)
405         {
406
407         }
408     }
409
410     public void testAllowChildAssocNode() throws Exception JavaDoc
411     {
412         runAs("andy");
413
414         permissionService.setPermission(new SimplePermissionEntry(systemNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
415         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ_CHILDREN), "andy",
416                 AccessStatus.ALLOWED));
417
418         Object JavaDoc o = new ClassWithMethods();
419         Method JavaDoc method = o.getClass().getMethod("testOneChildAssociationRef", new Class JavaDoc[] { ChildAssociationRef.class });
420
421         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
422
423         ProxyFactory proxyFactory = new ProxyFactory();
424         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
425
426         proxyFactory.setTargetSource(new SingletonTargetSource(o));
427
428         Object JavaDoc proxy = proxyFactory.getProxy();
429
430         method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(systemNodeRef) });
431
432     }
433
434     public void testMultiNodeMethodsArg0() throws Exception JavaDoc
435     {
436         runAs("andy");
437
438         Object JavaDoc o = new ClassWithMethods();
439         Method JavaDoc method = o.getClass().getMethod("testManyNodeRef",
440                 new Class JavaDoc[] { NodeRef.class, NodeRef.class, NodeRef.class, NodeRef.class });
441
442         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
443
444         ProxyFactory proxyFactory = new ProxyFactory();
445         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
446         proxyFactory.setTargetSource(new SingletonTargetSource(o));
447         Object JavaDoc proxy = proxyFactory.getProxy();
448
449         method.invoke(proxy, new Object JavaDoc[] { null, null, null, null });
450
451         try
452         {
453             method.invoke(proxy, new Object JavaDoc[] { rootNodeRef, null, null, null });
454             assertNotNull(null);
455         }
456         catch (InvocationTargetException JavaDoc e)
457         {
458
459         }
460
461         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
462         method.invoke(proxy, new Object JavaDoc[] { rootNodeRef, null, null, null });
463     }
464
465     public void testMultiNodeMethodsArg1() throws Exception JavaDoc
466     {
467         runAs("andy");
468
469         Object JavaDoc o = new ClassWithMethods();
470         Method JavaDoc method = o.getClass().getMethod("testManyNodeRef",
471                 new Class JavaDoc[] { NodeRef.class, NodeRef.class, NodeRef.class, NodeRef.class });
472
473         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
474
475         ProxyFactory proxyFactory = new ProxyFactory();
476         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.1.sys:base.Read")));
477         proxyFactory.setTargetSource(new SingletonTargetSource(o));
478         Object JavaDoc proxy = proxyFactory.getProxy();
479
480         method.invoke(proxy, new Object JavaDoc[] { null, null, null, null });
481
482         try
483         {
484             method.invoke(proxy, new Object JavaDoc[] { null, rootNodeRef, null, null });
485             assertNotNull(null);
486         }
487         catch (InvocationTargetException JavaDoc e)
488         {
489
490         }
491
492         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
493         method.invoke(proxy, new Object JavaDoc[] { null, rootNodeRef, null, null });
494     }
495
496     public void testMultiNodeMethodsArg2() throws Exception JavaDoc
497     {
498         runAs("andy");
499
500         Object JavaDoc o = new ClassWithMethods();
501         Method JavaDoc method = o.getClass().getMethod("testManyNodeRef",
502                 new Class JavaDoc[] { NodeRef.class, NodeRef.class, NodeRef.class, NodeRef.class });
503
504         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
505
506         ProxyFactory proxyFactory = new ProxyFactory();
507         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.2.sys:base.Read")));
508         proxyFactory.setTargetSource(new SingletonTargetSource(o));
509         Object JavaDoc proxy = proxyFactory.getProxy();
510
511         method.invoke(proxy, new Object JavaDoc[] { null, null, null, null });
512
513         try
514         {
515             method.invoke(proxy, new Object JavaDoc[] { null, null, rootNodeRef, null });
516             assertNotNull(null);
517         }
518         catch (InvocationTargetException JavaDoc e)
519         {
520
521         }
522
523         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
524         method.invoke(proxy, new Object JavaDoc[] { null, null, rootNodeRef, null });
525     }
526
527     public void testMultiNodeMethodsArg3() throws Exception JavaDoc
528     {
529         runAs("andy");
530
531         Object JavaDoc o = new ClassWithMethods();
532         Method JavaDoc method = o.getClass().getMethod("testManyNodeRef",
533                 new Class JavaDoc[] { NodeRef.class, NodeRef.class, NodeRef.class, NodeRef.class });
534
535         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
536
537         ProxyFactory proxyFactory = new ProxyFactory();
538         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.3.sys:base.Read")));
539         proxyFactory.setTargetSource(new SingletonTargetSource(o));
540         Object JavaDoc proxy = proxyFactory.getProxy();
541
542         method.invoke(proxy, new Object JavaDoc[] { null, null, null, null });
543
544         try
545         {
546             method.invoke(proxy, new Object JavaDoc[] { null, null, null, rootNodeRef });
547             assertNotNull(null);
548         }
549         catch (InvocationTargetException JavaDoc e)
550         {
551
552         }
553
554         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
555         method.invoke(proxy, new Object JavaDoc[] { null, null, null, rootNodeRef });
556     }
557
558     public void testMultiChildAssocRefMethodsArg0() throws Exception JavaDoc
559     {
560         runAs("andy");
561
562         Object JavaDoc o = new ClassWithMethods();
563         Method JavaDoc method = o.getClass().getMethod(
564                 "testManyChildAssociationRef",
565                 new Class JavaDoc[] { ChildAssociationRef.class, ChildAssociationRef.class, ChildAssociationRef.class,
566                         ChildAssociationRef.class });
567
568         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
569
570         ProxyFactory proxyFactory = new ProxyFactory();
571         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.0.sys:base.Read")));
572         proxyFactory.setTargetSource(new SingletonTargetSource(o));
573         Object JavaDoc proxy = proxyFactory.getProxy();
574
575         method.invoke(proxy, new Object JavaDoc[] { null, null, null, null });
576
577         try
578         {
579             method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(rootNodeRef), null, null, null });
580             assertNotNull(null);
581         }
582         catch (InvocationTargetException JavaDoc e)
583         {
584
585         }
586
587         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
588         method.invoke(proxy, new Object JavaDoc[] { nodeService.getPrimaryParent(rootNodeRef), null, null, null });
589     }
590
591     public void testMultiChildAssocRefMethodsArg1() throws Exception JavaDoc
592     {
593         runAs("andy");
594
595         Object JavaDoc o = new ClassWithMethods();
596         Method JavaDoc method = o.getClass().getMethod(
597                 "testManyChildAssociationRef",
598                 new Class JavaDoc[] { ChildAssociationRef.class, ChildAssociationRef.class, ChildAssociationRef.class,
599                         ChildAssociationRef.class });
600
601         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
602
603         ProxyFactory proxyFactory = new ProxyFactory();
604         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.1.sys:base.Read")));
605         proxyFactory.setTargetSource(new SingletonTargetSource(o));
606         Object JavaDoc proxy = proxyFactory.getProxy();
607
608         method.invoke(proxy, new Object JavaDoc[] { null, null, null, null });
609
610         try
611         {
612             method.invoke(proxy, new Object JavaDoc[] { null, nodeService.getPrimaryParent(rootNodeRef), null, null });
613             assertNotNull(null);
614         }
615         catch (InvocationTargetException JavaDoc e)
616         {
617
618         }
619
620         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
621         method.invoke(proxy, new Object JavaDoc[] { null, nodeService.getPrimaryParent(rootNodeRef), null, null });
622     }
623
624     public void testMultiChildAssocRefMethodsArg2() throws Exception JavaDoc
625     {
626         runAs("andy");
627
628         Object JavaDoc o = new ClassWithMethods();
629         Method JavaDoc method = o.getClass().getMethod(
630                 "testManyChildAssociationRef",
631                 new Class JavaDoc[] { ChildAssociationRef.class, ChildAssociationRef.class, ChildAssociationRef.class,
632                         ChildAssociationRef.class });
633
634         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
635
636         ProxyFactory proxyFactory = new ProxyFactory();
637         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.2.sys:base.Read")));
638         proxyFactory.setTargetSource(new SingletonTargetSource(o));
639         Object JavaDoc proxy = proxyFactory.getProxy();
640
641         method.invoke(proxy, new Object JavaDoc[] { null, null, null, null });
642
643         try
644         {
645             method.invoke(proxy, new Object JavaDoc[] { null, null, nodeService.getPrimaryParent(rootNodeRef), null });
646             assertNotNull(null);
647         }
648         catch (InvocationTargetException JavaDoc e)
649         {
650
651         }
652
653         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
654         method.invoke(proxy, new Object JavaDoc[] { null, null, nodeService.getPrimaryParent(rootNodeRef), null });
655     }
656
657     public void testMultiChildAssocRefMethodsArg3() throws Exception JavaDoc
658     {
659         runAs("andy");
660
661         Object JavaDoc o = new ClassWithMethods();
662         Method JavaDoc method = o.getClass().getMethod(
663                 "testManyChildAssociationRef",
664                 new Class JavaDoc[] { ChildAssociationRef.class, ChildAssociationRef.class, ChildAssociationRef.class,
665                         ChildAssociationRef.class });
666
667         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
668
669         ProxyFactory proxyFactory = new ProxyFactory();
670         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_NODE.3.sys:base.Read")));
671         proxyFactory.setTargetSource(new SingletonTargetSource(o));
672         Object JavaDoc proxy = proxyFactory.getProxy();
673
674         method.invoke(proxy, new Object JavaDoc[] { null, null, null, null });
675
676         try
677         {
678             method.invoke(proxy, new Object JavaDoc[] { null, null, null, nodeService.getPrimaryParent(rootNodeRef) });
679             assertNotNull(null);
680         }
681         catch (InvocationTargetException JavaDoc e)
682         {
683
684         }
685
686         permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));
687         method.invoke(proxy, new Object JavaDoc[] { null, null, null, nodeService.getPrimaryParent(rootNodeRef) });
688     }
689
690     public void testMethodACL() throws Exception JavaDoc
691     {
692         runAs("andy");
693
694         Object JavaDoc o = new ClassWithMethods();
695         Method JavaDoc method = o.getClass().getMethod(
696                 "testMethod",
697                 new Class JavaDoc[] { });
698
699         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
700
701         ProxyFactory proxyFactory = new ProxyFactory();
702         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_METHOD.andy")));
703         proxyFactory.setTargetSource(new SingletonTargetSource(o));
704         Object JavaDoc proxy = proxyFactory.getProxy();
705
706         method.invoke(proxy, new Object JavaDoc[] { });
707     }
708     
709     public void testMethodACL2() throws Exception JavaDoc
710     {
711         runAs("andy");
712
713         Object JavaDoc o = new ClassWithMethods();
714         Method JavaDoc method = o.getClass().getMethod(
715                 "testMethod",
716                 new Class JavaDoc[] { });
717
718         AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
719
720         ProxyFactory proxyFactory = new ProxyFactory();
721         proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_METHOD."+PermissionService.ALL_AUTHORITIES)));
722         proxyFactory.setTargetSource(new SingletonTargetSource(o));
723         Object JavaDoc proxy = proxyFactory.getProxy();
724
725         method.invoke(proxy, new Object JavaDoc[] { });
726     }
727
728     
729     public static class ClassWithMethods
730     {
731         public void testMethod()
732         {
733             
734         }
735         
736         public void testOneStoreRef(StoreRef storeRef)
737         {
738             
739         }
740         
741         public void testOneNodeRef(NodeRef nodeRef)
742         {
743
744         }
745
746         public void testManyNodeRef(NodeRef nodeRef1, NodeRef nodeRef2, NodeRef nodeRef3, NodeRef nodeRef4)
747         {
748
749         }
750
751         public void testOneChildAssociationRef(ChildAssociationRef car)
752         {
753
754         }
755
756         public void testManyChildAssociationRef(ChildAssociationRef car1, ChildAssociationRef car2,
757                 ChildAssociationRef car3, ChildAssociationRef car4)
758         {
759
760         }
761     }
762
763     public class Interceptor implements MethodInterceptor
764     {
765         ConfigAttributeDefinition cad = new ConfigAttributeDefinition();
766
767         Interceptor(final String JavaDoc config)
768         {
769             cad.addConfigAttribute(new ConfigAttribute()
770             {
771
772                 /**
773                  * Comment for <code>serialVersionUID</code>
774                  */

775                 private static final long serialVersionUID = 1L;
776
777                 public String JavaDoc getAttribute()
778                 {
779                     return config;
780                 }
781
782             });
783         }
784
785         public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc
786         {
787             ACLEntryVoter voter = new ACLEntryVoter();
788             voter.setNamespacePrefixResolver(namespacePrefixResolver);
789             voter.setPermissionService(permissionService);
790             voter.setNodeService(nodeService);
791             voter.setAuthenticationService(authenticationService);
792             voter.setAuthorityService(authorityService);
793
794             if (!(voter.vote(null, invocation, cad) == AccessDecisionVoter.ACCESS_DENIED))
795             {
796                 return invocation.proceed();
797             }
798             else
799             {
800                 throw new ACLEntryVoterException("Access denied");
801             }
802
803         }
804     }
805 }
806
Popular Tags