Search in sources :

Example 16 with EntityIdentity

use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.

the class RowLevelSecurityRepositoryDecoratorTest method testFindAllStream.

@SuppressWarnings("unchecked")
@Test
public void testFindAllStream() {
    Object entityId = "entityId";
    Entity entity = getEntityMock();
    when(delegateRepository.findAll(any(Stream.class))).thenAnswer(invocation -> Stream.of(entity));
    when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), READ)).thenReturn(true);
    assertEquals(rowLevelSecurityRepositoryDecorator.findAll(Stream.of(entityId)).collect(toList()), singletonList(entity));
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) Stream(java.util.stream.Stream) Test(org.testng.annotations.Test)

Example 17 with EntityIdentity

use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.

the class RowLevelSecurityRepositoryDecoratorTest method testCount.

@Test
public void testCount() {
    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(), 1L);
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) Test(org.testng.annotations.Test)

Example 18 with EntityIdentity

use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.

the class RowLevelSecurityRepositoryDecoratorTest method testDeleteAll.

@Test
public void testDeleteAll() {
    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), WRITE)).thenReturn(true);
    rowLevelSecurityRepositoryDecorator.deleteAll();
    @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Entity>> entityStreamCaptor = ArgumentCaptor.forClass(Stream.class);
    verify(delegateRepository).delete(entityStreamCaptor.capture());
    assertEquals(entityStreamCaptor.getValue().collect(toList()), singletonList(entity));
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) Stream(java.util.stream.Stream) Test(org.testng.annotations.Test)

Example 19 with EntityIdentity

use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.

the class RowLevelSecurityRepositoryDecoratorTest method testUpdateStream.

@Test
public void testUpdateStream() {
    Entity entity = getEntityMock();
    EntityType entityType = entity.getEntityType();
    when(delegateRepository.getEntityType()).thenReturn(entityType);
    when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), WRITE)).thenReturn(true);
    rowLevelSecurityRepositoryDecorator.update(Stream.of(entity));
    @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Entity>> entityStreamCaptor = ArgumentCaptor.forClass(Stream.class);
    verify(delegateRepository).update(entityStreamCaptor.capture());
    assertEquals(entityStreamCaptor.getValue().collect(toList()), singletonList(entity));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityIdentity(org.molgenis.data.security.EntityIdentity) Stream(java.util.stream.Stream) Test(org.testng.annotations.Test)

Example 20 with EntityIdentity

use of org.molgenis.data.security.EntityIdentity in project molgenis by molgenis.

the class RowLevelSecurityRepositoryDecoratorTest method testDeleteById.

@Test
public void testDeleteById() {
    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.deleteById(entityId);
    verify(delegateRepository).deleteById(entityId);
    verify(mutableAclService).deleteAcl(new EntityIdentity(entityTypeId, entityId), true);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityIdentity(org.molgenis.data.security.EntityIdentity) Test(org.testng.annotations.Test)

Aggregations

EntityIdentity (org.molgenis.data.security.EntityIdentity)26 Test (org.testng.annotations.Test)23 Stream (java.util.stream.Stream)9 EntityType (org.molgenis.data.meta.model.EntityType)8 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)3 MutableAcl (org.springframework.security.acls.model.MutableAcl)3 CumulativePermission (org.springframework.security.acls.domain.CumulativePermission)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 Consumer (java.util.function.Consumer)1 Entity (org.molgenis.data.Entity)1 Attribute (org.molgenis.data.meta.model.Attribute)1 Sid (org.springframework.security.acls.model.Sid)1