1 17 package org.alfresco.repo.security.permissions.impl.acegi; 18 19 import java.lang.reflect.InvocationTargetException ; 20 import java.lang.reflect.Method ; 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.HashSet ; 24 import java.util.List ; 25 import java.util.Set ; 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 57 { 58 runAs("andy"); 59 60 Object o = new ClassWithMethods(); 61 Method method = o.getClass().getMethod("echoNodeRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 69 70 Object answer = method.invoke(proxy, new Object [] { null }); 71 assertNull(answer); 72 } 73 74 public void testBasicAllowNullStore() throws Exception 75 { 76 runAs("andy"); 77 78 Object o = new ClassWithMethods(); 79 Method method = o.getClass().getMethod("echoStoreRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 87 88 Object answer = method.invoke(proxy, new Object [] { null }); 89 assertNull(answer); 90 } 91 92 public void testBasicAllowUnrecognisedObject() throws Exception 93 { 94 runAs("andy"); 95 96 Object o = new ClassWithMethods(); 97 Method method = o.getClass().getMethod("echoObject", new Class [] { Object .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 proxy = proxyFactory.getProxy(); 105 106 Object answer = method.invoke(proxy, new Object [] { "noodle" }); 107 assertNotNull(answer); 108 } 109 110 public void testBasicDenyStore() throws Exception 111 { 112 runAs("andy"); 113 114 Object o = new ClassWithMethods(); 115 Method method = o.getClass().getMethod("echoStoreRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 123 124 try 125 { 126 Object answer = method.invoke(proxy, new Object [] { rootNodeRef.getStoreRef() }); 127 assertNotNull(answer); 128 } 129 catch (InvocationTargetException e) 130 { 131 132 } 133 134 } 135 136 public void testBasicDenyNode() throws Exception 137 { 138 runAs("andy"); 139 140 Object o = new ClassWithMethods(); 141 Method method = o.getClass().getMethod("echoNodeRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 149 150 try 151 { 152 Object answer = method.invoke(proxy, new Object [] { rootNodeRef }); 153 assertNotNull(answer); 154 } 155 catch (InvocationTargetException e) 156 { 157 158 } 159 160 } 161 162 public void testBasicAllowNode() throws Exception 163 { 164 runAs("andy"); 165 166 Object o = new ClassWithMethods(); 167 Method method = o.getClass().getMethod("echoNodeRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 175 176 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 177 178 Object answer = method.invoke(proxy, new Object [] { rootNodeRef }); 179 assertEquals(answer, rootNodeRef); 180 181 } 182 183 public void testBasicAllowStore() throws Exception 184 { 185 runAs("andy"); 186 187 Object o = new ClassWithMethods(); 188 Method method = o.getClass().getMethod("echoStoreRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 196 197 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 198 199 Object answer = method.invoke(proxy, new Object [] { rootNodeRef.getStoreRef() }); 200 assertEquals(answer, rootNodeRef.getStoreRef()); 201 202 } 203 204 public void testBasicAllowNodeParent() throws Exception 205 { 206 runAs("andy"); 207 208 Object o = new ClassWithMethods(); 209 Method method = o.getClass().getMethod("echoNodeRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 217 218 Object answer = method.invoke(proxy, new Object [] { rootNodeRef }); 219 assertEquals(answer, rootNodeRef); 220 221 try 222 { 223 answer = method.invoke(proxy, new Object [] { systemNodeRef }); 224 assertNotNull(answer); 225 } 226 catch (InvocationTargetException 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 [] { systemNodeRef }); 234 assertEquals(answer, systemNodeRef); 235 } 236 237 public void testBasicAllowNullChildAssociationRef1() throws Exception 238 { 239 runAs("andy"); 240 241 Object o = new ClassWithMethods(); 242 Method method = o.getClass().getMethod("echoChildAssocRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 250 251 Object answer = method.invoke(proxy, new Object [] { null }); 252 assertNull(answer); 253 } 254 255 public void testBasicAllowNullChildAssociationRef2() throws Exception 256 { 257 runAs("andy"); 258 259 Object o = new ClassWithMethods(); 260 Method method = o.getClass().getMethod("echoChildAssocRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 268 269 Object answer = method.invoke(proxy, new Object [] { null }); 270 assertNull(answer); 271 } 272 273 public void testBasicDenyChildAssocRef1() throws Exception 274 { 275 runAs("andy"); 276 277 Object o = new ClassWithMethods(); 278 Method method = o.getClass().getMethod("echoChildAssocRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 286 287 try 288 { 289 Object answer = method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(rootNodeRef) }); 290 assertNotNull(answer); 291 } 292 catch (InvocationTargetException e) 293 { 294 295 } 296 297 try 298 { 299 Object answer = method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(systemNodeRef) }); 300 assertNotNull(answer); 301 } 302 catch (InvocationTargetException e) 303 { 304 305 } 306 307 } 308 309 public void testBasicDenyChildAssocRef2() throws Exception 310 { 311 runAs("andy"); 312 313 Object o = new ClassWithMethods(); 314 Method method = o.getClass().getMethod("echoChildAssocRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 322 323 Object answer = method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(rootNodeRef) }); 324 assertNotNull(answer); 325 326 try 327 { 328 answer = method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(systemNodeRef) }); 329 assertNotNull(answer); 330 } 331 catch (InvocationTargetException e) 332 { 333 334 } 335 336 } 337 338 public void testBasicAllowChildAssociationRef1() throws Exception 339 { 340 runAs("andy"); 341 342 Object o = new ClassWithMethods(); 343 Method method = o.getClass().getMethod("echoChildAssocRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 351 352 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 353 354 Object answer = method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(rootNodeRef) }); 355 assertEquals(answer, nodeService.getPrimaryParent(rootNodeRef)); 356 357 answer = method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(systemNodeRef) }); 358 assertEquals(answer, nodeService.getPrimaryParent(systemNodeRef)); 359 360 } 361 362 public void testBasicAllowChildAssociationRef2() throws Exception 363 { 364 runAs("andy"); 365 366 Object o = new ClassWithMethods(); 367 Method method = o.getClass().getMethod("echoChildAssocRef", new Class [] { 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 proxy = proxyFactory.getProxy(); 375 376 permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED)); 377 378 Object answer = method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(rootNodeRef) }); 379 assertEquals(answer, nodeService.getPrimaryParent(rootNodeRef)); 380 381 answer = method.invoke(proxy, new Object [] { nodeService.getPrimaryParent(systemNodeRef) }); 382 assertEquals(answer, nodeService.getPrimaryParent(systemNodeRef)); 383 } 384 385 public void testBasicAllowNullResultSet() throws Exception 386 { 387 runAs("andy"); 388 389 Object o = new ClassWithMethods(); 390 Method methodResultSet = o.getClass().getMethod("echoResultSet", new Class [] { ResultSet.class }); 391 Method methodCollection = o.getClass().getMethod("echoCollection", new Class [] { Collection .class }); 392 Method methodArray = o.getClass().getMethod("echoArray", new Class [] { Object [].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 proxy = proxyFactory.getProxy(); 400 401 List <NodeRef> nodeRefList = new ArrayList <NodeRef>(); 402 NodeRef[] nodeRefArray = new NodeRef[0]; 403 404 Set <NodeRef> nodeRefSet = new HashSet <NodeRef>(); 405 406 List <ChildAssociationRef> carList = new ArrayList <ChildAssociationRef>(); 407 408 ChildAssociationRef[] carArray = new ChildAssociationRef[0]; 409 410 Set <ChildAssociationRef> carSet = new HashSet <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 [] { rsIn }); 416 assertEquals(0, answerResultSet.length()); 417 Collection answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefList }); 418 assertEquals(0, answerCollection.size()); 419 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefSet }); 420 assertEquals(0, answerCollection.size()); 421 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carList }); 422 assertEquals(0, answerCollection.size()); 423 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carSet }); 424 assertEquals(0, answerCollection.size()); 425 Object [] answerArray = (Object []) methodArray.invoke(proxy, new Object [] { nodeRefArray }); 426 assertEquals(0, answerArray.length); 427 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { carArray }); 428 assertEquals(0, answerArray.length); 429 430 assertEquals(0, rsIn.length()); 431 answerResultSet = (ResultSet) methodResultSet.invoke(proxy, new Object [] { null }); 432 assertNull(answerResultSet); 433 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { null }); 434 assertNull(answerCollection); 435 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { null }); 436 assertNull(answerArray); 437 } 438 439 public void testResultSetFilterAll() throws Exception 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 o = new ClassWithMethods(); 449 Method methodResultSet = o.getClass().getMethod("echoResultSet", new Class [] { ResultSet.class }); 450 Method methodCollection = o.getClass().getMethod("echoCollection", new Class [] { Collection .class }); 451 Method methodArray = o.getClass().getMethod("echoArray", new Class [] { Object [].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 proxy = proxyFactory.getProxy(); 459 460 List <NodeRef> nodeRefList = new ArrayList <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 <NodeRef> nodeRefSet = new HashSet <NodeRef>(); 469 nodeRefSet.addAll(nodeRefList); 470 471 List <ChildAssociationRef> carList = new ArrayList <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 <ChildAssociationRef> carSet = new HashSet <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 [] { rsIn }); 486 assertEquals(0, answerResultSet.length()); 487 Collection answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefList }); 488 assertEquals(0, answerCollection.size()); 489 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefSet }); 490 assertEquals(0, answerCollection.size()); 491 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carList }); 492 assertEquals(0, answerCollection.size()); 493 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carSet }); 494 assertEquals(0, answerCollection.size()); 495 Object [] answerArray = (Object []) methodArray.invoke(proxy, new Object [] { nodeRefArray }); 496 assertEquals(0, answerArray.length); 497 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { carArray }); 498 assertEquals(0, answerArray.length); 499 } 500 501 public void testResultSetFilterForNullParentOnly() throws Exception 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 o = new ClassWithMethods(); 510 Method methodResultSet = o.getClass().getMethod("echoResultSet", new Class [] { ResultSet.class }); 511 Method methodCollection = o.getClass().getMethod("echoCollection", new Class [] { Collection .class }); 512 Method methodArray = o.getClass().getMethod("echoArray", new Class [] { Object [].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 proxy = proxyFactory.getProxy(); 520 521 List <NodeRef> nodeRefList = new ArrayList <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 <NodeRef> nodeRefSet = new HashSet <NodeRef>(); 530 nodeRefSet.addAll(nodeRefList); 531 532 List <ChildAssociationRef> carList = new ArrayList <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 <ChildAssociationRef> carSet = new HashSet <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 [] { rsIn }); 548 assertEquals(1, answerResultSet.length()); 549 Collection answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefList }); 550 assertEquals(1, answerCollection.size()); 551 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefSet }); 552 assertEquals(1, answerCollection.size()); 553 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carList }); 554 assertEquals(1, answerCollection.size()); 555 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carSet }); 556 assertEquals(1, answerCollection.size()); 557 Object [] answerArray = (Object []) methodArray.invoke(proxy, new Object [] { nodeRefArray }); 558 assertEquals(1, answerArray.length); 559 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { carArray }); 560 assertEquals(1, answerArray.length); 561 } 562 563 public void testResultSetFilterNone1() throws Exception 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 o = new ClassWithMethods(); 572 Method methodResultSet = o.getClass().getMethod("echoResultSet", new Class [] { ResultSet.class }); 573 Method methodCollection = o.getClass().getMethod("echoCollection", new Class [] { Collection .class }); 574 Method methodArray = o.getClass().getMethod("echoArray", new Class [] { Object [].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 proxy = proxyFactory.getProxy(); 582 583 List <NodeRef> nodeRefList = new ArrayList <NodeRef>(); 584 nodeRefList.add(rootNodeRef); 585 nodeRefList.add(systemNodeRef); 586 nodeRefList.add(n1); 587 nodeRefList.add(n1); 588 589 List <Object > mixedRefList = new ArrayList <Object >(); 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 <NodeRef> nodeRefSet = new HashSet <NodeRef>(); 600 nodeRefSet.addAll(nodeRefList); 601 602 Set <Object > mixedRefSet = new HashSet <Object >(); 603 mixedRefSet.addAll(mixedRefList); 604 605 List <ChildAssociationRef> carList = new ArrayList <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 <ChildAssociationRef> carSet = new HashSet <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 [] { rsIn }); 622 assertEquals(4, answerResultSet.length()); 623 Collection answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefList }); 624 assertEquals(4, answerCollection.size()); 625 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefList }); 626 assertEquals(5, answerCollection.size()); 627 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefSet }); 628 assertEquals(3, answerCollection.size()); 629 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefSet }); 630 assertEquals(4, answerCollection.size()); 631 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carList }); 632 assertEquals(4, answerCollection.size()); 633 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carSet }); 634 assertEquals(3, answerCollection.size()); 635 Object [] answerArray = (Object []) methodArray.invoke(proxy, new Object [] { nodeRefArray }); 636 assertEquals(4, answerArray.length); 637 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { 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 [] { rsIn }); 644 assertEquals(2, answerResultSet.length()); 645 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefList }); 646 assertEquals(2, answerCollection.size()); 647 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefList }); 648 assertEquals(3, answerCollection.size()); 649 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefSet }); 650 assertEquals(2, answerCollection.size()); 651 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefSet }); 652 assertEquals(3, answerCollection.size()); 653 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carList }); 654 assertEquals(2, answerCollection.size()); 655 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carSet }); 656 assertEquals(2, answerCollection.size()); 657 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { nodeRefArray }); 658 assertEquals(2, answerArray.length); 659 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { 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 [] { rsIn }); 667 assertEquals(0, answerResultSet.length()); 668 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefList }); 669 assertEquals(0, answerCollection.size()); 670 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefList }); 671 assertEquals(0, answerCollection.size()); 672 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefSet }); 673 assertEquals(0, answerCollection.size()); 674 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefSet }); 675 assertEquals(0, answerCollection.size()); 676 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carList }); 677 assertEquals(0, answerCollection.size()); 678 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carSet }); 679 assertEquals(0, answerCollection.size()); 680 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { nodeRefArray }); 681 assertEquals(0, answerArray.length); 682 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { carArray }); 683 assertEquals(0, answerArray.length); 684 685 } 686 687 public void testResultSetFilterNone2() throws Exception 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 o = new ClassWithMethods(); 697 Method methodResultSet = o.getClass().getMethod("echoResultSet", new Class [] { ResultSet.class }); 698 Method methodCollection = o.getClass().getMethod("echoCollection", new Class [] { Collection .class }); 699 Method methodArray = o.getClass().getMethod("echoArray", new Class [] { Object [].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 proxy = proxyFactory.getProxy(); 707 708 List <NodeRef> nodeRefList = new ArrayList <NodeRef>(); 709 nodeRefList.add(rootNodeRef); 710 nodeRefList.add(systemNodeRef); 711 nodeRefList.add(n1); 712 nodeRefList.add(n1); 713 714 List <Object > mixedRefList = new ArrayList <Object >(); 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 <NodeRef> nodeRefSet = new HashSet <NodeRef>(); 724 nodeRefSet.addAll(nodeRefList); 725 726 Set <Object > mixedRefSet = new HashSet <Object >(); 727 mixedRefSet.addAll(mixedRefList); 728 729 List <ChildAssociationRef> carList = new ArrayList <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 <ChildAssociationRef> carSet = new HashSet <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 [] { rsIn }); 746 assertEquals(4, answerResultSet.length()); 747 Collection answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefList }); 748 assertEquals(4, answerCollection.size()); 749 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefList }); 750 assertEquals(5, answerCollection.size()); 751 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefSet }); 752 assertEquals(3, answerCollection.size()); 753 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefSet }); 754 assertEquals(4, answerCollection.size()); 755 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carList }); 756 assertEquals(4, answerCollection.size()); 757 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carSet }); 758 assertEquals(3, answerCollection.size()); 759 Object [] answerArray = (Object []) methodArray.invoke(proxy, new Object [] { nodeRefArray }); 760 assertEquals(4, answerArray.length); 761 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { 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 [] { rsIn }); 768 assertEquals(4, answerResultSet.length()); 769 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefList }); 770 assertEquals(4, answerCollection.size()); 771 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefList }); 772 assertEquals(5, answerCollection.size()); 773 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefSet }); 774 assertEquals(3, answerCollection.size()); 775 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefSet }); 776 assertEquals(4, answerCollection.size()); 777 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carList }); 778 assertEquals(4, answerCollection.size()); 779 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carSet }); 780 assertEquals(3, answerCollection.size()); 781 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { nodeRefArray }); 782 assertEquals(4, answerArray.length); 783 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { 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 [] { rsIn }); 790 assertEquals(1, answerResultSet.length()); 791 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefList }); 792 assertEquals(1, answerCollection.size()); 793 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefList }); 794 assertEquals(2, answerCollection.size()); 795 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { nodeRefSet }); 796 assertEquals(1, answerCollection.size()); 797 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { mixedRefSet }); 798 assertEquals(2, answerCollection.size()); 799 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carList }); 800 assertEquals(1, answerCollection.size()); 801 answerCollection = (Collection ) methodCollection.invoke(proxy, new Object [] { carSet }); 802 assertEquals(1, answerCollection.size()); 803 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { nodeRefArray }); 804 assertEquals(1, answerArray.length); 805 answerArray = (Object []) methodArray.invoke(proxy, new Object [] { carArray }); 806 assertEquals(1, answerArray.length); 807 808 } 809 810 public static class ClassWithMethods 811 { 812 813 public Object echoObject(Object 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 <T> echoCollection(Collection <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 config) 855 { 856 cad.addConfigAttribute(new ConfigAttribute() 857 { 858 859 862 private static final long serialVersionUID = 1L; 863 864 public String getAttribute() 865 { 866 return config; 867 } 868 869 }); 870 } 871 872 public Object invoke(MethodInvocation invocation) throws Throwable 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 returnObject = invocation.proceed(); 881 return after.decide(null, invocation, cad, returnObject); 882 } 883 } 884 } 885 | Popular Tags |