Search in sources :

Example 1 with EntityTypeIdentity

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

the class DataExplorerController method getModule.

@GetMapping("/module/{moduleId}")
public String getModule(@PathVariable("moduleId") String moduleId, @RequestParam("entity") String entityTypeId, Model model) {
    EntityType selectedEntityType;
    Map<String, GenomeBrowserTrack> entityTracks;
    switch(moduleId) {
        case MOD_DATA:
            selectedEntityType = dataService.getMeta().getEntityTypeById(entityTypeId);
            entityTracks = genomeBrowserService.getGenomeBrowserTracks(selectedEntityType);
            model.addAttribute("genomeTracks", getTracksJson(entityTracks));
            // if multiple tracks are available we assume chrom and pos attribute are the same
            if (!entityTracks.isEmpty()) {
                // FIXME: how to do this cleaner
                GenomeBrowserTrack track = entityTracks.entrySet().iterator().next().getValue();
                model.addAttribute("pos_attr", track.getGenomeBrowserAttrs().getPos());
                model.addAttribute("chrom_attr", track.getGenomeBrowserAttrs().getChrom());
            }
            model.addAttribute("showDirectoryButton", directoryController.showDirectoryButton(entityTypeId));
            model.addAttribute("NegotiatorEnabled", directoryController.showDirectoryButton(entityTypeId));
            break;
        case MOD_ENTITIESREPORT:
            // TODO: figure out if we need to know pos and chrom attrs here
            selectedEntityType = dataService.getMeta().getEntityTypeById(entityTypeId);
            entityTracks = genomeBrowserService.getGenomeBrowserTracks(selectedEntityType);
            model.addAttribute("genomeTracks", getTracksJson(entityTracks));
            model.addAttribute("showDirectoryButton", directoryController.showDirectoryButton(entityTypeId));
            model.addAttribute("NegotiatorEnabled", directoryController.showDirectoryButton(entityTypeId));
            model.addAttribute("datasetRepository", dataService.getRepository(entityTypeId));
            model.addAttribute("viewName", dataExplorerSettings.getEntityReport(entityTypeId));
            break;
        case MOD_ANNOTATORS:
            // self-explanatory
            if (!permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITEMETA)) {
                throw new MolgenisDataAccessException("No " + Permission.WRITEMETA + " permission on entity [" + entityTypeId + "], this permission is necessary run the annotators.");
            }
            Entity annotationRun = dataService.findOne(ANNOTATION_JOB_EXECUTION, new QueryImpl<>().eq(AnnotationJobExecutionMetaData.TARGET_NAME, entityTypeId).sort(new Sort(JobExecutionMetaData.START_DATE, Sort.Direction.DESC)));
            model.addAttribute("annotationRun", annotationRun);
            model.addAttribute("entityTypeId", entityTypeId);
            break;
    }
    // TODO bad request in case of invalid module id
    return "view-dataexplorer-mod-" + moduleId;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack)

Example 2 with EntityTypeIdentity

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

the class EntityTypeRepositorySecurityDecoratorTest method countQuery.

@WithMockUser(username = USERNAME)
@Test
public void countQuery() {
    String entityType0Name = "entity0";
    EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
    String entityType1Name = "entity1";
    EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
    Query q = new QueryImpl<>();
    @SuppressWarnings("unchecked") ArgumentCaptor<Query> queryCaptor = forClass(Query.class);
    when(delegateRepository.findAll(queryCaptor.capture())).thenReturn(Stream.of(entityType0, entityType1));
    doReturn(false).when(permissionService).hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT);
    doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT);
    assertEquals(repo.count(q), 1L);
    assertEquals(queryCaptor.getValue().getOffset(), 0);
    assertEquals(queryCaptor.getValue().getPageSize(), Integer.MAX_VALUE);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) QueryImpl(org.molgenis.data.support.QueryImpl) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 3 with EntityTypeIdentity

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

the class EntityTypeRepositorySecurityDecoratorTest method findOneQueryUserPermissionAllowed.

@WithMockUser(username = USERNAME)
@Test
public void findOneQueryUserPermissionAllowed() {
    String entityType0Name = "entity0";
    EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
    @SuppressWarnings("unchecked") Query q = mock(Query.class);
    when(delegateRepository.findOne(q)).thenReturn(entityType0);
    when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(true);
    assertEquals(repo.findOne(q), entityType0);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 4 with EntityTypeIdentity

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

the class EntityTypeRepositorySecurityDecoratorTest method findOneByIdUserPermissionAllowed.

@WithMockUser(username = USERNAME)
@Test
public void findOneByIdUserPermissionAllowed() {
    String entityType0Name = "entity0";
    EntityType entityType0 = mock(EntityType.class);
    when(delegateRepository.findOneById("entity0")).thenReturn(entityType0);
    when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(true);
    assertEquals(repo.findOneById("entity0"), 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 5 with EntityTypeIdentity

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

the class EntityTypeRepositorySecurityDecoratorTest method findAllQueryUserOffsetLimit.

@WithMockUser(username = USERNAME)
@Test
public void findAllQueryUserOffsetLimit() {
    String entityType0Name = "entity0";
    EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
    String entityType1Name = "entity1";
    EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
    String entityType2Name = "entity2";
    EntityType entityType2 = when(mock(EntityType.class).getId()).thenReturn(entityType2Name).getMock();
    @SuppressWarnings("unchecked") Query q = mock(Query.class);
    when(q.getOffset()).thenReturn(1);
    when(q.getPageSize()).thenReturn(1);
    @SuppressWarnings("unchecked") ArgumentCaptor<Query<EntityType>> queryCaptor = forClass(Query.class);
    when(delegateRepository.findAll(queryCaptor.capture())).thenReturn(Stream.of(entityType0, entityType1, entityType2));
    doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT);
    doReturn(false).when(permissionService).hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT);
    doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType2Name), EntityTypePermission.COUNT);
    assertEquals(repo.findAll(q).collect(toList()), singletonList(entityType2));
    Query<EntityType> decoratedQ = queryCaptor.getValue();
    assertEquals(decoratedQ.getOffset(), 0);
    assertEquals(decoratedQ.getPageSize(), Integer.MAX_VALUE);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) 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