@Test void testAdd() { Package pack = mock(Package.class); Package parent = mock(Package.class); when(pack.getId()).thenReturn("1"); when(parent.getId()).thenReturn("2"); when(pack.getParent()).thenReturn(parent); MutableAcl acl = mock(MutableAcl.class); MutableAcl parentAcl = mock(MutableAcl.class); when(mutableAclService.createAcl(new PackageIdentity("1"))).thenReturn(acl); when(mutableAclService.readAclById(new PackageIdentity("2"))).thenReturn(parentAcl); when(userPermissionEvaluator.hasPermission( new PackageIdentity(parent.getId()), PackagePermission.ADD_PACKAGE)) .thenReturn(true); repo.add(pack); verify(mutableAclService).createAcl(new PackageIdentity("1")); verify(mutableAclService).updateAcl(acl); verify(delegateRepository).add(pack); }
@Override public void add(Package pack) { if (isActionPermitted(pack, CREATE)) { createAcl(pack); delegate().add(pack); } else { if (pack.getParent() == null) { throw new NullParentPackageNotSuException(); } else { throw new PackagePermissionDeniedException(getPermissionForAction(CREATE), pack); } } }
PackageRepositorySecurityDecorator extends AbstractRowLevelSecurityRepositoryDecorator<Package> { @Override public void add(Package pack) { if (isActionPermitted(pack, CREATE)) { createAcl(pack); delegate().add(pack); } else { if (pack.getParent() == null) { throw new NullParentPackageNotSuException(); } else { throw new PackagePermissionDeniedException(getPermissionForAction(CREATE), pack); } } } }
PackageRepositorySecurityDecorator extends AbstractRowLevelSecurityRepositoryDecorator<Package> { @Override public void add(Package pack) { if (isActionPermitted(pack, CREATE)) { createAcl(pack); delegate().add(pack); } else { if (pack.getParent() == null) { throw new NullParentPackageNotSuException(); } else { throw new PackagePermissionDeniedException(getPermissionForAction(CREATE), pack); } } } PackageRepositorySecurityDecorator(
      Repository<Package> delegateRepository,
      MutableAclService mutableAclService,
      UserPermissionEvaluator userPermissionEvaluator); }
PackageRepositorySecurityDecorator extends AbstractRowLevelSecurityRepositoryDecorator<Package> { @Override public void add(Package pack) { if (isActionPermitted(pack, CREATE)) { createAcl(pack); delegate().add(pack); } else { if (pack.getParent() == null) { throw new NullParentPackageNotSuException(); } else { throw new PackagePermissionDeniedException(getPermissionForAction(CREATE), pack); } } } PackageRepositorySecurityDecorator(
      Repository<Package> delegateRepository,
      MutableAclService mutableAclService,
      UserPermissionEvaluator userPermissionEvaluator); @Override boolean isActionPermitted(Package updatedPack, Action action); @Override boolean isActionPermitted(Object id, Action action); @Override void throwPermissionException(Package pack, Action action); @Override Package findOneById(Object id); @Override void add(Package pack); @Override void update(Package pack); @Override Integer add(Stream<Package> packages); @Override void createAcl(Package pack); @Override void deleteAcl(Object id); @Override void deleteAcl(Package pack); @Override void updateAcl(Package pack); }
PackageRepositorySecurityDecorator extends AbstractRowLevelSecurityRepositoryDecorator<Package> { @Override public void add(Package pack) { if (isActionPermitted(pack, CREATE)) { createAcl(pack); delegate().add(pack); } else { if (pack.getParent() == null) { throw new NullParentPackageNotSuException(); } else { throw new PackagePermissionDeniedException(getPermissionForAction(CREATE), pack); } } } PackageRepositorySecurityDecorator(
      Repository<Package> delegateRepository,
      MutableAclService mutableAclService,
      UserPermissionEvaluator userPermissionEvaluator); @Override boolean isActionPermitted(Package updatedPack, Action action); @Override boolean isActionPermitted(Object id, Action action); @Override void throwPermissionException(Package pack, Action action); @Override Package findOneById(Object id); @Override void add(Package pack); @Override void update(Package pack); @Override Integer add(Stream<Package> packages); @Override void createAcl(Package pack); @Override void deleteAcl(Object id); @Override void deleteAcl(Package pack); @Override void updateAcl(Package pack);  }