Search in sources :

Example 21 with EntityIdentity

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);
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) Test(org.testng.annotations.Test)

Example 22 with EntityIdentity

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);
}
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 23 with EntityIdentity

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);
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) CumulativePermission(org.springframework.security.acls.domain.CumulativePermission) MutableAcl(org.springframework.security.acls.model.MutableAcl) Stream(java.util.stream.Stream) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 24 with EntityIdentity

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);
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) Test(org.testng.annotations.Test)

Example 25 with EntityIdentity

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);
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity)

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