Search in sources :

Example 11 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testFindAllStreamFetch.

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

Example 12 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testFindAllQuery.

@Test
public void testFindAllQuery() {
    @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), READ)).thenReturn(true);
    assertEquals(rowLevelSecurityRepositoryDecorator.findAll(query).collect(toList()), singletonList(entity));
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) Test(org.testng.annotations.Test)

Example 13 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testForEachBatched.

@SuppressWarnings("unchecked")
@Test
public void testForEachBatched() {
    Entity entity = getEntityMock();
    Fetch fetch = mock(Fetch.class);
    List<Entity> actualEntities = new ArrayList<>();
    doAnswer(invocation -> {
        ((Consumer<List<Entity>>) invocation.getArgument(1)).accept(singletonList(entity));
        return null;
    }).when(delegateRepository).forEachBatched(eq(fetch), any(), eq(1000));
    when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), READ)).thenReturn(true);
    rowLevelSecurityRepositoryDecorator.forEachBatched(fetch, actualEntities::addAll, 1000);
    assertEquals(actualEntities, singletonList(entity));
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) Consumer(java.util.function.Consumer) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Test(org.testng.annotations.Test)

Example 14 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecorator method deleteAcl.

@Override
public void deleteAcl(Entity entity) {
    EntityIdentity entityIdentity = new EntityIdentity(entity);
    deleteAcl(entityIdentity);
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity)

Example 15 with EntityIdentity

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

the class PermissionManagerControllerTest method testUpdateEntityClassRlsEnableRls.

@Test
public void testUpdateEntityClassRlsEnableRls() {
    String entityTypeId = "entityTypeId";
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
    Attribute idAttribute = when(mock(Attribute.class).getDataType()).thenReturn(LONG).getMock();
    when(entityType.getIdAttribute()).thenReturn(idAttribute);
    when(dataService.getEntityType(entityTypeId)).thenReturn(entityType);
    Entity entity = when(mock(Entity.class).getEntityType()).thenReturn(entityType).getMock();
    when(entity.getIdValue()).thenReturn("entityId");
    when(dataService.findAll(entityTypeId)).thenReturn(Stream.of(entity));
    EntityTypeRlsRequest entityTypeRlsRequest = new EntityTypeRlsRequest(entityTypeId, true);
    permissionManagerController.updateEntityClassRls(entityTypeRlsRequest);
    verify(mutableAclClassService).createAclClass("entity-entityTypeId", Long.class);
    verify(mutableAclService).createAcl(new EntityIdentity(entity));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) EntityIdentity(org.molgenis.data.security.EntityIdentity) Attribute(org.molgenis.data.meta.model.Attribute) 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