Search in sources :

Example 46 with EntityTypeIdentity

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

the class MolgenisPermissionControllerTest method hasWritePermissionFalse.

@Test
public void hasWritePermissionFalse() {
    String entityTypeId = "entity";
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITE)).thenReturn(false);
    assertFalse(molgenisPermissionController.hasWritePermission(entityTypeId));
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Test(org.testng.annotations.Test)

Example 47 with EntityTypeIdentity

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

the class EntityTypeRepositorySecurityDecoratorTest method findOneByIdFetchUserPermissionAllowed.

@WithMockUser(username = USERNAME)
@Test
public void findOneByIdFetchUserPermissionAllowed() {
    String entityType0Name = "entity0";
    EntityType entityType0 = mock(EntityType.class);
    Fetch fetch = mock(Fetch.class);
    when(delegateRepository.findOneById(entityType0Name, fetch)).thenReturn(entityType0);
    when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(true);
    assertEquals(repo.findOneById(entityType0Name, fetch), entityType0);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 48 with EntityTypeIdentity

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

the class EntityTypeRepositorySecurityDecoratorTest method update.

@WithMockUser(username = USERNAME)
@Test
public void update() {
    String entityTypeId = "entityTypeId";
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITEMETA)).thenReturn(true);
    EntityType entityType = mock(EntityType.class);
    when(entityType.getId()).thenReturn(entityTypeId).getMock();
    repo.update(entityType);
    verify(delegateRepository).update(entityType);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 49 with EntityTypeIdentity

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

the class EntityTypeRepositorySecurityDecoratorTest method deleteNotAllowed.

@WithMockUser(username = USERNAME)
@Test(expectedExceptions = MolgenisDataAccessException.class, expectedExceptionsMessageRegExp = "No \\[WRITEMETA\\] permission on entity type \\[Entity type\\] with id \\[entityTypeId\\]")
public void deleteNotAllowed() {
    String entityTypeId = "entityTypeId";
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITEMETA)).thenReturn(false);
    EntityType entityType = mock(EntityType.class);
    when(entityType.getId()).thenReturn("entityTypeId").getMock();
    when(entityType.getIdValue()).thenReturn("entityTypeId");
    when(entityType.getLabel()).thenReturn("Entity type").getMock();
    when(entityType.getEntityType()).thenReturn(entityType);
    repo.delete(entityType);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 50 with EntityTypeIdentity

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

the class EntityTypeRepositorySecurityDecoratorTest method updateNotAllowed.

@WithMockUser(username = USERNAME)
@Test(expectedExceptions = MolgenisDataAccessException.class, expectedExceptionsMessageRegExp = "No \\[WRITEMETA\\] permission on entity type \\[Entity type\\] with id \\[entityTypeId\\]")
public void updateNotAllowed() {
    String entityTypeId = "entityTypeId";
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITEMETA)).thenReturn(false);
    EntityType entityType = mock(EntityType.class);
    when(entityType.getId()).thenReturn(entityTypeId).getMock();
    when(entityType.getIdValue()).thenReturn(entityTypeId).getMock();
    when(entityType.getLabel()).thenReturn("Entity type").getMock();
    when(entityType.getEntityType()).thenReturn(entityType);
    repo.update(entityType);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Aggregations

EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)75 Test (org.testng.annotations.Test)57 EntityType (org.molgenis.data.meta.model.EntityType)40 WithMockUser (org.springframework.security.test.context.support.WithMockUser)39 Attribute (org.molgenis.data.meta.model.Attribute)16 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)8 MutableAcl (org.springframework.security.acls.model.MutableAcl)8 EntityTypePermission (org.molgenis.data.security.EntityTypePermission)6 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)6 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)6 Sid (org.springframework.security.acls.model.Sid)6 Entity (org.molgenis.data.Entity)5 Package (org.molgenis.data.meta.model.Package)5 EntityTypePermissionUtils.getCumulativePermission (org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission)4 QueryImpl (org.molgenis.data.support.QueryImpl)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 File (java.io.File)3 Map (java.util.Map)3 ADD (org.molgenis.data.DatabaseAction.ADD)3 FileRepositoryCollection (org.molgenis.data.file.support.FileRepositoryCollection)3