1 17 package org.alfresco.repo.security.permissions.impl.acegi; 18 19 import java.lang.reflect.InvocationTargetException ; 20 import java.lang.reflect.Method ; 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 49 { 50 runAs("andy"); 51 52 Object o = new ClassWithMethods(); 53 Method method = o.getClass().getMethod("testOneNodeRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 63 64 try 65 { 66 method.invoke(proxy, new Object [] { rootNodeRef }); 67 assertNotNull(null); 68 } 69 catch (InvocationTargetException e) 70 { 71 72 } 73 74 try 75 { 76 method.invoke(proxy, new Object [] { systemNodeRef }); 77 assertNotNull(null); 78 } 79 catch (InvocationTargetException e) 80 { 81 82 } 83 84 86 nodeService.deleteNode(systemNodeRef); 87 88 assertNull(method.invoke(proxy, new Object [] { systemNodeRef })); 89 90 } 91 92 93 public void testBasicDenyStore() throws Exception 94 { 95 runAs("andy"); 96 97 Object o = new ClassWithMethods(); 98 Method method = o.getClass().getMethod("testOneStoreRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 108 109 try 110 { 111 method.invoke(proxy, new Object [] { rootNodeRef.getStoreRef() }); 112 assertNotNull(null); 113 } 114 catch (InvocationTargetException e) 115 { 116 117 } 118 119 } 120 121 public void testAllowNullNode() throws Exception 122 { 123 runAs("andy"); 124 125 Object o = new ClassWithMethods(); 126 Method method = o.getClass().getMethod("testOneNodeRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 136 137 method.invoke(proxy, new Object [] { null }); 138 139 } 140 141 public void testAllowNullStore() throws Exception 142 { 143 runAs("andy"); 144 145 Object o = new ClassWithMethods(); 146 Method method = o.getClass().getMethod("testOneStoreRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 156 157 method.invoke(proxy, new Object [] { null }); 158 159 } 160 161 public void testAllowNullParentOnRealChildAssoc() throws Exception 162 { 163 runAs("andy"); 164 165 Object o = new ClassWithMethods(); 166 Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 176 177 method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(rootNodeRef) }); 178 179 } 180 181 public void testAllowNullParent() throws Exception 182 { 183 runAs("andy"); 184 185 Object o = new ClassWithMethods(); 186 Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 196 197 method.invoke(proxy, new Object [] { null }); 198 199 } 200 201 public void testAllowNullChild() throws Exception 202 { 203 runAs("andy"); 204 205 Object o = new ClassWithMethods(); 206 Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 216 217 method.invoke(proxy, new Object [] { null }); 218 219 } 220 221 public void testBasicDenyChildAssocNode() throws Exception 222 { 223 runAs("andy"); 224 225 Object o = new ClassWithMethods(); 226 Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 236 237 try 238 { 239 method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(rootNodeRef) }); 240 assertNotNull(null); 241 } 242 catch (InvocationTargetException e) 243 { 244 245 } 246 } 247 248 public void testBasicDenyParentAssocNode() throws Exception 249 { 250 runAs("andy"); 251 252 Object o = new ClassWithMethods(); 253 Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 263 264 try 265 { 266 method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(systemNodeRef) }); 267 assertNotNull(null); 268 } 269 catch (InvocationTargetException e) 270 { 271 272 } 273 } 274 275 public void testBasicAllowNode() throws Exception 276 { 277 runAs("andy"); 278 279 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 280 281 Object o = new ClassWithMethods(); 282 Method method = o.getClass().getMethod("testOneNodeRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 292 293 method.invoke(proxy, new Object [] { rootNodeRef }); 294 } 295 296 297 public void testBasicAllow() throws Exception 298 { 299 runAs("andy"); 300 301 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 302 303 Object o = new ClassWithMethods(); 304 Method method = o.getClass().getMethod("testOneNodeRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 314 315 method.invoke(proxy, new Object [] { rootNodeRef }); 316 } 317 318 public void testBasicAllowStore() throws Exception 319 { 320 runAs("andy"); 321 322 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 323 324 Object o = new ClassWithMethods(); 325 Method method = o.getClass().getMethod("testOneStoreRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 335 336 method.invoke(proxy, new Object [] { rootNodeRef.getStoreRef() }); 337 } 338 339 public void testBasicAllowChildAssocNode() throws Exception 340 { 341 runAs("andy"); 342 343 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 344 345 Object o = new ClassWithMethods(); 346 Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 356 357 method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(rootNodeRef) }); 358 } 359 360 public void testBasicAllowParentAssocNode() throws Exception 361 { 362 runAs("andy"); 363 364 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 365 366 Object o = new ClassWithMethods(); 367 Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 377 378 method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(systemNodeRef) }); 379 } 380 381 public void testDenyParentAssocNode() throws Exception 382 { 383 runAs("andy"); 384 385 permissionService.setPermission(new SimplePermissionEntry(systemNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 386 387 Object o = new ClassWithMethods(); 388 Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 398 399 try 400 { 401 method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(systemNodeRef) }); 402 assertNotNull(null); 403 } 404 catch (InvocationTargetException e) 405 { 406 407 } 408 } 409 410 public void testAllowChildAssocNode() throws Exception 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 o = new ClassWithMethods(); 419 Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 429 430 method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(systemNodeRef) }); 431 432 } 433 434 public void testMultiNodeMethodsArg0() throws Exception 435 { 436 runAs("andy"); 437 438 Object o = new ClassWithMethods(); 439 Method method = o.getClass().getMethod("testManyNodeRef", 440 new Class [] { 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 proxy = proxyFactory.getProxy(); 448 449 method.invoke(proxy, new Object [] { null, null, null, null }); 450 451 try 452 { 453 method.invoke(proxy, new Object [] { rootNodeRef, null, null, null }); 454 assertNotNull(null); 455 } 456 catch (InvocationTargetException e) 457 { 458 459 } 460 461 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 462 method.invoke(proxy, new Object [] { rootNodeRef, null, null, null }); 463 } 464 465 public void testMultiNodeMethodsArg1() throws Exception 466 { 467 runAs("andy"); 468 469 Object o = new ClassWithMethods(); 470 Method method = o.getClass().getMethod("testManyNodeRef", 471 new Class [] { 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 proxy = proxyFactory.getProxy(); 479 480 method.invoke(proxy, new Object [] { null, null, null, null }); 481 482 try 483 { 484 method.invoke(proxy, new Object [] { null, rootNodeRef, null, null }); 485 assertNotNull(null); 486 } 487 catch (InvocationTargetException e) 488 { 489 490 } 491 492 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 493 method.invoke(proxy, new Object [] { null, rootNodeRef, null, null }); 494 } 495 496 public void testMultiNodeMethodsArg2() throws Exception 497 { 498 runAs("andy"); 499 500 Object o = new ClassWithMethods(); 501 Method method = o.getClass().getMethod("testManyNodeRef", 502 new Class [] { 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 proxy = proxyFactory.getProxy(); 510 511 method.invoke(proxy, new Object [] { null, null, null, null }); 512 513 try 514 { 515 method.invoke(proxy, new Object [] { null, null, rootNodeRef, null }); 516 assertNotNull(null); 517 } 518 catch (InvocationTargetException e) 519 { 520 521 } 522 523 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 524 method.invoke(proxy, new Object [] { null, null, rootNodeRef, null }); 525 } 526 527 public void testMultiNodeMethodsArg3() throws Exception 528 { 529 runAs("andy"); 530 531 Object o = new ClassWithMethods(); 532 Method method = o.getClass().getMethod("testManyNodeRef", 533 new Class [] { 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 proxy = proxyFactory.getProxy(); 541 542 method.invoke(proxy, new Object [] { null, null, null, null }); 543 544 try 545 { 546 method.invoke(proxy, new Object [] { null, null, null, rootNodeRef }); 547 assertNotNull(null); 548 } 549 catch (InvocationTargetException e) 550 { 551 552 } 553 554 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 555 method.invoke(proxy, new Object [] { null, null, null, rootNodeRef }); 556 } 557 558 public void testMultiChildAssocRefMethodsArg0() throws Exception 559 { 560 runAs("andy"); 561 562 Object o = new ClassWithMethods(); 563 Method method = o.getClass().getMethod( 564 "testManyChildAssociationRef", 565 new Class [] { 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 proxy = proxyFactory.getProxy(); 574 575 method.invoke(proxy, new Object [] { null, null, null, null }); 576 577 try 578 { 579 method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(rootNodeRef), null, null, null }); 580 assertNotNull(null); 581 } 582 catch (InvocationTargetException e) 583 { 584 585 } 586 587 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 588 method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(rootNodeRef), null, null, null }); 589 } 590 591 public void testMultiChildAssocRefMethodsArg1() throws Exception 592 { 593 runAs("andy"); 594 595 Object o = new ClassWithMethods(); 596 Method method = o.getClass().getMethod( 597 "testManyChildAssociationRef", 598 new Class [] { 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 proxy = proxyFactory.getProxy(); 607 608 method.invoke(proxy, new Object [] { null, null, null, null }); 609 610 try 611 { 612 method.invoke(proxy, new Object [] { null, nodeService.getPrimaryParent(rootNodeRef), null, null }); 613 assertNotNull(null); 614 } 615 catch (InvocationTargetException e) 616 { 617 618 } 619 620 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 621 method.invoke(proxy, new Object [] { null, nodeService.getPrimaryParent(rootNodeRef), null, null }); 622 } 623 624 public void testMultiChildAssocRefMethodsArg2() throws Exception 625 { 626 runAs("andy"); 627 628 Object o = new ClassWithMethods(); 629 Method method = o.getClass().getMethod( 630 "testManyChildAssociationRef", 631 new Class [] { 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 proxy = proxyFactory.getProxy(); 640 641 method.invoke(proxy, new Object [] { null, null, null, null }); 642 643 try 644 { 645 method.invoke(proxy, new Object [] { null, null, nodeService.getPrimaryParent(rootNodeRef), null }); 646 assertNotNull(null); 647 } 648 catch (InvocationTargetException e) 649 { 650 651 } 652 653 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 654 method.invoke(proxy, new Object [] { null, null, nodeService.getPrimaryParent(rootNodeRef), null }); 655 } 656 657 public void testMultiChildAssocRefMethodsArg3() throws Exception 658 { 659 runAs("andy"); 660 661 Object o = new ClassWithMethods(); 662 Method method = o.getClass().getMethod( 663 "testManyChildAssociationRef", 664 new Class [] { 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 proxy = proxyFactory.getProxy(); 673 674 method.invoke(proxy, new Object [] { null, null, null, null }); 675 676 try 677 { 678 method.invoke(proxy, new Object [] { null, null, null, nodeService.getPrimaryParent(rootNodeRef) }); 679 assertNotNull(null); 680 } 681 catch (InvocationTargetException e) 682 { 683 684 } 685 686 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 687 method.invoke(proxy, new Object [] { null, null, null, nodeService.getPrimaryParent(rootNodeRef) }); 688 } 689 690 public void testMethodACL() throws Exception 691 { 692 runAs("andy"); 693 694 Object o = new ClassWithMethods(); 695 Method method = o.getClass().getMethod( 696 "testMethod", 697 new Class [] { }); 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 proxy = proxyFactory.getProxy(); 705 706 method.invoke(proxy, new Object [] { }); 707 } 708 709 public void testMethodACL2() throws Exception 710 { 711 runAs("andy"); 712 713 Object o = new ClassWithMethods(); 714 Method method = o.getClass().getMethod( 715 "testMethod", 716 new Class [] { }); 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 proxy = proxyFactory.getProxy(); 724 725 method.invoke(proxy, new Object [] { }); 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 config) 768 { 769 cad.addConfigAttribute(new ConfigAttribute() 770 { 771 772 775 private static final long serialVersionUID = 1L; 776 777 public String getAttribute() 778 { 779 return config; 780 } 781 782 }); 783 } 784 785 public Object invoke(MethodInvocation invocation) throws Throwable 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 |