@Test void testDeletePermission() { Sid sid = mock(Sid.class); MutableAcl acl = mock(MutableAcl.class); AccessControlEntry ace = mock(AccessControlEntry.class); when(acl.getEntries()).thenReturn(singletonList(ace)); ObjectIdentity objectIdentity = new ObjectIdentityImpl("entity-typeId", "identifier"); doReturn(acl).when(mutableAclService).readAclById(objectIdentity, singletonList(sid)); when(mutableAclClassService.getAclClassTypes()).thenReturn(singletonList("entity-typeId")); when(acl.getObjectIdentity()).thenReturn(objectIdentity); AccessControlEntry ace1 = mock(AccessControlEntry.class); when(ace1.getSid()).thenReturn(sid); when(ace1.getPermission()).thenReturn(COUNT); when(acl.getEntries()).thenReturn(singletonList(ace1)); when(acl.getObjectIdentity()).thenReturn(objectIdentity); doReturn(acl).when(mutableAclService).readAclById(objectIdentity); LinkedHashSet<Sid> sids = new LinkedHashSet<>(); sids.add(sid); when(userRoleTools.sortSids(sids)).thenReturn(new LinkedList<>(sids)); permissionsApiService.deletePermission(sid, objectIdentity); verify(acl).deleteAce(0); verify(mutableAclService).updateAcl(acl); }
@Override @Transactional public void deletePermission(Sid sid, ObjectIdentity objectIdentity) { entityHelper.checkEntityExists(objectIdentity); MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity, singletonList(sid)); Set<LabelledPermission> current = getPermissionsForObject(objectIdentity, singleton(sid), false); if (acl == null || current.isEmpty()) { throw new UnknownAceException(objectIdentity, sid, "delete"); } deleteAce(sid, acl); }
PermissionServiceImpl implements PermissionService { @Override @Transactional public void deletePermission(Sid sid, ObjectIdentity objectIdentity) { entityHelper.checkEntityExists(objectIdentity); MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity, singletonList(sid)); Set<LabelledPermission> current = getPermissionsForObject(objectIdentity, singleton(sid), false); if (acl == null || current.isEmpty()) { throw new UnknownAceException(objectIdentity, sid, "delete"); } deleteAce(sid, acl); } }
PermissionServiceImpl implements PermissionService { @Override @Transactional public void deletePermission(Sid sid, ObjectIdentity objectIdentity) { entityHelper.checkEntityExists(objectIdentity); MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity, singletonList(sid)); Set<LabelledPermission> current = getPermissionsForObject(objectIdentity, singleton(sid), false); if (acl == null || current.isEmpty()) { throw new UnknownAceException(objectIdentity, sid, "delete"); } deleteAce(sid, acl); } PermissionServiceImpl(
      MutableAclService mutableAclService,
      PermissionInheritanceResolver inheritanceResolver,
      ObjectIdentityService objectIdentityService,
      DataService dataService,
      MutableAclClassService mutableAclClassService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper,
      UserPermissionEvaluator userPermissionEvaluator); }
PermissionServiceImpl implements PermissionService { @Override @Transactional public void deletePermission(Sid sid, ObjectIdentity objectIdentity) { entityHelper.checkEntityExists(objectIdentity); MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity, singletonList(sid)); Set<LabelledPermission> current = getPermissionsForObject(objectIdentity, singleton(sid), false); if (acl == null || current.isEmpty()) { throw new UnknownAceException(objectIdentity, sid, "delete"); } deleteAce(sid, acl); } PermissionServiceImpl(
      MutableAclService mutableAclService,
      PermissionInheritanceResolver inheritanceResolver,
      ObjectIdentityService objectIdentityService,
      DataService dataService,
      MutableAclClassService mutableAclClassService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper,
      UserPermissionEvaluator userPermissionEvaluator); @Override Set<LabelledType> getLabelledTypes(); @Override Set<LabelledObject> getObjects(String typeId, int page, int pageSize); @Override Set<PermissionSet> getSuitablePermissionsForType(String typeId); @Override Set<LabelledPermission> getPermissionsForObject(
      ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions); @Override Set<LabelledPermission> getPermissions(Set<Sid> sids, boolean isReturnInherited); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, int page, int pageSize); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, boolean isReturnInherited); @Override @Transactional void createAcl(ObjectIdentity objectIdentity); @Override @Transactional void createPermission(Permission permission); @Override @Transactional void createPermissions(Set<Permission> permissions); @Override @Transactional void updatePermission(Permission permission); @Override @Transactional void updatePermissions(Set<Permission> permissions); @Override @Transactional void deletePermission(Sid sid, ObjectIdentity objectIdentity); @Override @Transactional void addType(String typeId); @Override @Transactional void deleteType(String typeId); @Override boolean exists(ObjectIdentity objectIdentity, Sid sid); }
PermissionServiceImpl implements PermissionService { @Override @Transactional public void deletePermission(Sid sid, ObjectIdentity objectIdentity) { entityHelper.checkEntityExists(objectIdentity); MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity, singletonList(sid)); Set<LabelledPermission> current = getPermissionsForObject(objectIdentity, singleton(sid), false); if (acl == null || current.isEmpty()) { throw new UnknownAceException(objectIdentity, sid, "delete"); } deleteAce(sid, acl); } PermissionServiceImpl(
      MutableAclService mutableAclService,
      PermissionInheritanceResolver inheritanceResolver,
      ObjectIdentityService objectIdentityService,
      DataService dataService,
      MutableAclClassService mutableAclClassService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper,
      UserPermissionEvaluator userPermissionEvaluator); @Override Set<LabelledType> getLabelledTypes(); @Override Set<LabelledObject> getObjects(String typeId, int page, int pageSize); @Override Set<PermissionSet> getSuitablePermissionsForType(String typeId); @Override Set<LabelledPermission> getPermissionsForObject(
      ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions); @Override Set<LabelledPermission> getPermissions(Set<Sid> sids, boolean isReturnInherited); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, int page, int pageSize); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, boolean isReturnInherited); @Override @Transactional void createAcl(ObjectIdentity objectIdentity); @Override @Transactional void createPermission(Permission permission); @Override @Transactional void createPermissions(Set<Permission> permissions); @Override @Transactional void updatePermission(Permission permission); @Override @Transactional void updatePermissions(Set<Permission> permissions); @Override @Transactional void deletePermission(Sid sid, ObjectIdentity objectIdentity); @Override @Transactional void addType(String typeId); @Override @Transactional void deleteType(String typeId); @Override boolean exists(ObjectIdentity objectIdentity, Sid sid);  }