Search in sources :

Example 6 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testIterator.

@Test
public void testIterator() {
    Entity entity = getEntityMock();
    when(delegateRepository.iterator()).thenReturn(singletonList(entity).iterator());
    when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), READ)).thenReturn(true);
    assertEquals(newArrayList(rowLevelSecurityRepositoryDecorator.iterator()), singletonList(entity));
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) Test(org.testng.annotations.Test)

Example 7 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testDeleteStream.

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

Example 8 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testDeleteByIdPermissionDenied.

@Test
public void testDeleteByIdPermissionDenied() {
    String entityTypeId = "entityTypeId";
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
    when(delegateRepository.getEntityType()).thenReturn(entityType);
    Object entityId = "entityId";
    rowLevelSecurityRepositoryDecorator.deleteById(entityId);
    verify(delegateRepository, times(0)).deleteById(entityId);
    verify(mutableAclService, times(0)).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)

Example 9 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testFindOneByIdFetch.

@Test
public void testFindOneByIdFetch() {
    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), READ)).thenReturn(true);
    Entity entity = mock(Entity.class);
    Fetch fetch = mock(Fetch.class);
    when(delegateRepository.findOneById(entityId, fetch)).thenReturn(entity);
    assertEquals(rowLevelSecurityRepositoryDecorator.findOneById(entityId, fetch), entity);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityIdentity(org.molgenis.data.security.EntityIdentity) Test(org.testng.annotations.Test)

Example 10 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testFindOne.

@Test
public void testFindOne() {
    @SuppressWarnings("unchecked") Query<Entity> query = mock(Query.class);
    Entity entity = getEntityMock();
    when(delegateRepository.findOne(query)).thenReturn(entity);
    when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), READ)).thenReturn(true);
    assertEquals(entity, rowLevelSecurityRepositoryDecorator.findOne(query));
}
Also used : 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