use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testCountQuery.
@Test
public void testCountQuery() {
@SuppressWarnings("unchecked") Query<Entity> query = mock(Query.class);
Entity entity = getEntityMock();
when(delegateRepository.findAll(new QueryImpl<>().setOffset(0).setPageSize(Integer.MAX_VALUE))).thenAnswer(invocation -> Stream.of(entity));
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), COUNT)).thenReturn(true);
assertEquals(rowLevelSecurityRepositoryDecorator.count(query), 1L);
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testDeleteAllStream.
@Test
public void testDeleteAllStream() {
String entityTypeId = "entityTypeId";
EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
when(delegateRepository.getEntityType()).thenReturn(entityType);
Object entityId = "entityId";
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entityTypeId, entityId), WRITE)).thenReturn(true);
rowLevelSecurityRepositoryDecorator.deleteAll(Stream.of(entityId));
@SuppressWarnings("unchecked") ArgumentCaptor<Stream<Object>> entityStreamCaptor = ArgumentCaptor.forClass(Stream.class);
verify(delegateRepository).deleteAll(entityStreamCaptor.capture());
assertEquals(entityStreamCaptor.getValue().collect(toList()), singletonList(entityId));
verify(mutableAclService).deleteAcl(new EntityIdentity(entityTypeId, entityId), true);
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testAddStream.
@WithMockUser(username = USERNAME)
@Test
public void testAddStream() {
Entity entity = getEntityMock();
MutableAcl acl = mock(MutableAcl.class);
when(mutableAclService.createAcl(new EntityIdentity(entity))).thenReturn(acl);
rowLevelSecurityRepositoryDecorator.add(Stream.of(entity));
@SuppressWarnings("unchecked") ArgumentCaptor<Stream<Entity>> entityStreamCaptor = ArgumentCaptor.forClass(Stream.class);
verify(delegateRepository).add(entityStreamCaptor.capture());
assertEquals(entityStreamCaptor.getValue().collect(toList()), singletonList(entity));
verify(acl).insertAce(0, new CumulativePermission().set(WRITE).set(READ).set(COUNT), new PrincipalSid(USERNAME), true);
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testDelete.
@Test
public void testDelete() {
Entity entity = getEntityMock();
when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), WRITE)).thenReturn(true);
rowLevelSecurityRepositoryDecorator.delete(entity);
verify(delegateRepository).delete(entity);
verify(mutableAclService).deleteAcl(new EntityIdentity(entity), true);
}
use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecorator method deleteAcl.
@Override
public void deleteAcl(Object id) {
EntityIdentity entityIdentity = toEntityIdentity(id);
deleteAcl(entityIdentity);
}
Aggregations