Search in sources :

Example 1 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testAdd.

@WithMockUser(username = USERNAME)
@Test
public void testAdd() {
    Entity entity = getEntityMock();
    MutableAcl acl = mock(MutableAcl.class);
    when(mutableAclService.createAcl(new EntityIdentity(entity))).thenReturn(acl);
    rowLevelSecurityRepositoryDecorator.add(entity);
    verify(acl).insertAce(0, new CumulativePermission().set(WRITE).set(READ).set(COUNT), new PrincipalSid(USERNAME), true);
    verify(delegateRepository).add(entity);
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) CumulativePermission(org.springframework.security.acls.domain.CumulativePermission) MutableAcl(org.springframework.security.acls.model.MutableAcl) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 2 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testDeleteStreamPermissionDenied.

@Test
public void testDeleteStreamPermissionDenied() {
    Entity entity = getEntityMock();
    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()), emptyList());
    verify(mutableAclService, times(0)).deleteAcl(new EntityIdentity(entity), true);
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) Stream(java.util.stream.Stream) Test(org.testng.annotations.Test)

Example 3 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testUpdate.

@Test
public void testUpdate() {
    Entity entity = getEntityMock();
    when(userPermissionEvaluator.hasPermission(new EntityIdentity(entity), WRITE)).thenReturn(true);
    rowLevelSecurityRepositoryDecorator.update(entity);
    verify(delegateRepository).update(entity);
}
Also used : EntityIdentity(org.molgenis.data.security.EntityIdentity) Test(org.testng.annotations.Test)

Example 4 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testFindOneById.

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

Example 5 with EntityIdentity

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

the class RowLevelSecurityRepositoryDecoratorTest method testDeleteAllStreamPermissionDenied.

@Test
public void testDeleteAllStreamPermissionDenied() {
    String entityTypeId = "entityTypeId";
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
    when(delegateRepository.getEntityType()).thenReturn(entityType);
    Object entityId = "entityId";
    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()), emptyList());
    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) Stream(java.util.stream.Stream) 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