Search in sources :

Example 66 with EntityTypeIdentity

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

the class PermissionSystemServiceImpl method giveUserWriteMetaPermissions.

@Override
public void giveUserWriteMetaPermissions(Collection<EntityType> entityTypes) {
    Sid sid = SidUtils.createSid(getCurrentUsername());
    runAsSystem(() -> {
        CumulativePermission permission = getCumulativePermission(EntityTypePermission.WRITEMETA);
        entityTypes.forEach(entityType -> {
            MutableAcl acl = (MutableAcl) mutableAclService.readAclById(new EntityTypeIdentity(entityType));
            acl.insertAce(acl.getEntries().size(), permission, sid, true);
            mutableAclService.updateAcl(acl);
        });
    });
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) CumulativePermission(org.springframework.security.acls.domain.CumulativePermission) EntityTypePermissionUtils.getCumulativePermission(org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission) MutableAcl(org.springframework.security.acls.model.MutableAcl) Sid(org.springframework.security.acls.model.Sid)

Example 67 with EntityTypeIdentity

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

the class AnnotatorController method setMapOfAnnotators.

/**
 * Sets a map of annotators, whether they can be used by the selected data set.
 *
 * @return mapOfAnnotators
 */
private Map<String, Map<String, Object>> setMapOfAnnotators(String dataSetName) {
    Map<String, Map<String, Object>> mapOfAnnotators = new HashMap<>();
    if (dataSetName != null) {
        EntityType entityType = dataService.getEntityType(dataSetName);
        for (RepositoryAnnotator annotator : annotationService.getAllAnnotators()) {
            List<Attribute> outputAttrs = annotator.getOutputAttributes();
            outputAttrs = getAtomicAttributesFromList(outputAttrs);
            Map<String, Object> map = new HashMap<>();
            map.put("description", annotator.getDescription());
            map.put("canAnnotate", annotator.canAnnotate(entityType));
            map.put("inputAttributes", createAttrsResponse(annotator.getRequiredAttributes()));
            map.put("inputAttributeTypes", toMap(annotator.getRequiredAttributes()));
            map.put("outputAttributes", createAttrsResponse(outputAttrs));
            map.put("outputAttributeTypes", toMap(annotator.getOutputAttributes()));
            String settingsEntityName = PACKAGE_SETTINGS + PACKAGE_SEPARATOR + annotator.getInfo().getCode();
            map.put("showSettingsButton", permissionService.hasPermission(new EntityTypeIdentity(settingsEntityName), EntityTypePermission.WRITE));
            mapOfAnnotators.put(annotator.getSimpleName(), map);
        }
    }
    return mapOfAnnotators;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) HashMap(java.util.HashMap) RepositoryAnnotator(org.molgenis.data.annotation.core.RepositoryAnnotator) Attribute(org.molgenis.data.meta.model.Attribute) HashMap(java.util.HashMap) Map(java.util.Map)

Example 68 with EntityTypeIdentity

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

the class DataExplorerController method checkExistsAndPermission.

private void checkExistsAndPermission(@RequestParam(value = "entity", required = false) String selectedEntityName, StringBuilder message) {
    boolean entityExists = dataService.hasRepository(selectedEntityName);
    boolean hasEntityPermission = permissionService.hasPermission(new EntityTypeIdentity(selectedEntityName), EntityTypePermission.COUNT);
    if (!(entityExists && hasEntityPermission)) {
        if (selectedEntityName != null) {
            message.append("Entity does not exist or you do not have permission on this entity");
            if (!SecurityUtils.currentUserIsAuthenticated()) {
                message.append(", log in to view more entities");
            } else {
                message.append(", please specify the fully qualified entity name");
            }
        }
    }
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity)

Example 69 with EntityTypeIdentity

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

the class DataExplorerController method getModules.

/**
 * Returns modules configuration for this entity based on current user permissions.
 */
@GetMapping("/modules")
@ResponseBody
public ModulesConfigResponse getModules(@RequestParam("entity") String entityTypeId) {
    boolean modAggregates = dataExplorerSettings.getModAggregates();
    boolean modAnnotators = dataExplorerSettings.getModAnnotators();
    boolean modData = dataExplorerSettings.getModData();
    boolean modReports = dataExplorerSettings.getModReports();
    if (modAggregates) {
        modAggregates = dataService.getCapabilities(entityTypeId).contains(RepositoryCapability.AGGREGATEABLE);
    }
    // set data explorer permission
    Permission pluginPermission = null;
    if (permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITE))
        pluginPermission = WRITE;
    else if (permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.READ))
        pluginPermission = READ;
    else if (permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.COUNT))
        pluginPermission = Permission.COUNT;
    ModulesConfigResponse modulesConfig = new ModulesConfigResponse();
    String aggregatesTitle = messageSource.getMessage("dataexplorer_aggregates_title", new Object[] {}, LocaleContextHolder.getLocale());
    if (pluginPermission != null) {
        switch(pluginPermission) {
            case COUNT:
                if (modAggregates) {
                    modulesConfig.add(new ModuleConfig("aggregates", aggregatesTitle, "grid-icon.png"));
                }
                break;
            case READ:
            case WRITE:
                if (modData) {
                    modulesConfig.add(new ModuleConfig("data", "Data", "grid-icon.png"));
                }
                if (modAggregates) {
                    modulesConfig.add(new ModuleConfig("aggregates", aggregatesTitle, "aggregate-icon.png"));
                }
                if (modAnnotators && pluginPermission == WRITE) {
                    modulesConfig.add(new ModuleConfig("annotators", "Annotators", "annotator-icon.png"));
                }
                if (modReports) {
                    String modEntitiesReportName = dataExplorerSettings.getEntityReport(entityTypeId);
                    if (modEntitiesReportName != null) {
                        modulesConfig.add(new ModuleConfig("entitiesreport", modEntitiesReportName, "report-icon.png"));
                    }
                }
                break;
            case NONE:
                break;
            default:
                throw new UnexpectedEnumException(pluginPermission);
        }
    }
    return modulesConfig;
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) Permission(org.molgenis.security.core.Permission) EntityTypePermission(org.molgenis.data.security.EntityTypePermission)

Example 70 with EntityTypeIdentity

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

the class DataExplorerControllerTest method beforeTest.

@BeforeMethod
public void beforeTest() {
    when(permissionService.hasPermission(new EntityTypeIdentity("yes"), EntityTypePermission.WRITEMETA)).thenReturn(true);
    when(permissionService.hasPermission(new EntityTypeIdentity("no"), EntityTypePermission.WRITEMETA)).thenReturn(false);
    when(idAttr.getDataType()).thenReturn(STRING);
    when(entityType.getIdAttribute()).thenReturn(idAttr);
    when(package_.getLabel()).thenReturn("pack");
    when(package_.getId()).thenReturn("packId");
    when(parentPackage.getLabel()).thenReturn("parent");
    when(parentPackage.getId()).thenReturn("parentId");
    when(package_.getParent()).thenReturn(parentPackage);
    when(entityType.getPackage()).thenReturn(package_);
    when(repository.findOneById(entityId)).thenReturn(entity);
    when(dataService.getEntityType(entityTypeId)).thenReturn(entityType);
    when(dataService.getRepository(entityTypeId)).thenReturn(repository);
    when(dataExplorerSettings.getEntityReport(entityTypeId)).thenReturn("template");
    when(dataExplorerSettings.getModStandaloneReports()).thenReturn(true);
    when(freemarkerConfigurer.getConfiguration()).thenReturn(configuration);
    Menu menu = mock(Menu.class);
    when(menuReaderService.getMenu()).thenReturn(menu);
    when(menu.findMenuItemPath(NAVIGATOR)).thenReturn(null);
    when(localeResolver.resolveLocale(any())).thenReturn(Locale.ENGLISH);
    mockMvc = MockMvcBuilders.standaloneSetup(controller).setMessageConverters(gsonHttpMessageConverter).build();
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Menu(org.molgenis.core.ui.menu.Menu) BeforeMethod(org.testng.annotations.BeforeMethod)

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