Search in sources :

Example 1 with EntityTypePermission

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

the class EmxImportServiceIT method populateUserPermissions.

private void populateUserPermissions() {
    Sid sid = new PrincipalSid(SecurityUtils.getCurrentUsername());
    Map<String, EntityTypePermission> entityTypePermissionMap = new HashMap<>();
    entityTypePermissionMap.put("sys_md_Package", READ);
    entityTypePermissionMap.put("sys_md_EntityType", READ);
    entityTypePermissionMap.put("sys_md_Attribute", READ);
    entityTypePermissionMap.put("sys_md_Tag", READ);
    entityTypePermissionMap.put("sys_FileMeta", READ);
    entityTypePermissionMap.put("sys_dec_DecoratorConfiguration", READ);
    runAsSystem(() -> entityTypePermissionMap.forEach((entityTypeId, permission) -> {
        MutableAcl acl = (MutableAcl) mutableAclService.readAclById(new EntityTypeIdentity(entityTypeId));
        acl.insertAce(acl.getEntries().size(), getCumulativePermission(permission), sid, true);
        mutableAclService.updateAcl(acl);
    }));
}
Also used : Iterables(com.google.common.collect.Iterables) java.util(java.util) DataProvider(org.testng.annotations.DataProvider) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.testng.annotations.Test) RunAsSystemAspect.runAsSystem(org.molgenis.security.core.runas.RunAsSystemAspect.runAsSystem) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) User(org.molgenis.data.security.auth.User) Tag(org.molgenis.data.meta.model.Tag) Assert(org.testng.Assert) PACKAGE_SEPARATOR(org.molgenis.data.meta.model.Package.PACKAGE_SEPARATOR) Arrays.asList(java.util.Arrays.asList) PACKAGE_DEFAULT(org.molgenis.data.meta.DefaultPackage.PACKAGE_DEFAULT) MutableAcl(org.springframework.security.acls.model.MutableAcl) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Collectors.toSet(java.util.stream.Collectors.toSet) ImportService(org.molgenis.data.importer.ImportService) Sid(org.springframework.security.acls.model.Sid) Collections.emptyMap(java.util.Collections.emptyMap) ADD(org.molgenis.data.DatabaseAction.ADD) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) ADD_UPDATE_EXISTING(org.molgenis.data.DatabaseAction.ADD_UPDATE_EXISTING) EntityTypePermissionUtils.getCumulativePermission(org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission) EntityImportReport(org.molgenis.data.importer.EntityImportReport) READ(org.molgenis.data.security.EntityTypePermission.READ) Instant(java.time.Instant) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) File(java.io.File) FileRepositoryCollection(org.molgenis.data.file.support.FileRepositoryCollection) SecurityUtils(org.molgenis.security.core.utils.SecurityUtils) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) WithMockUser(org.springframework.security.test.context.support.WithMockUser) LocalDate(java.time.LocalDate) Package(org.molgenis.data.meta.model.Package) MutableAclService(org.springframework.security.acls.model.MutableAclService) Entity(org.molgenis.data.Entity) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) MutableAcl(org.springframework.security.acls.model.MutableAcl) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Sid(org.springframework.security.acls.model.Sid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid)

Example 2 with EntityTypePermission

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

the class OntologyImportServiceIT method populateUserPermissions.

private void populateUserPermissions() {
    Sid sid = new PrincipalSid(SecurityUtils.getCurrentUsername());
    Map<String, EntityTypePermission> entityTypePermissionMap = new HashMap<>();
    entityTypePermissionMap.put("sys_ont_OntologyTermDynamicAnnotation", WRITE);
    entityTypePermissionMap.put("sys_ont_OntologyTermNodePath", WRITE);
    entityTypePermissionMap.put("sys_ont_OntologyTermSynonym", WRITE);
    entityTypePermissionMap.put("sys_ont_Ontology", WRITE);
    entityTypePermissionMap.put("sys_ont_OntologyTerm", WRITE);
    entityTypePermissionMap.put("sys_dec_DecoratorConfiguration", READ);
    runAsSystem(() -> entityTypePermissionMap.forEach((entityTypeId, permission) -> {
        MutableAcl acl = (MutableAcl) mutableAclService.readAclById(new EntityTypeIdentity(entityTypeId));
        acl.insertAce(acl.getEntries().size(), getCumulativePermission(permission), sid, true);
        mutableAclService.updateAcl(acl);
    }));
}
Also used : java.util(java.util) Autowired(org.springframework.beans.factory.annotation.Autowired) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) RunAsSystemAspect.runAsSystem(org.molgenis.security.core.runas.RunAsSystemAspect.runAsSystem) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) User(org.molgenis.data.security.auth.User) Ontology(org.molgenis.ontology.core.meta.Ontology) PACKAGE_DEFAULT(org.molgenis.data.meta.DefaultPackage.PACKAGE_DEFAULT) MutableAcl(org.springframework.security.acls.model.MutableAcl) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) ImportService(org.molgenis.data.importer.ImportService) Sid(org.springframework.security.acls.model.Sid) ADD(org.molgenis.data.DatabaseAction.ADD) Collections.emptySet(java.util.Collections.emptySet) ImmutableMap(com.google.common.collect.ImmutableMap) EntityTypePermissionUtils.getCumulativePermission(org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission) EntityImportReport(org.molgenis.data.importer.EntityImportReport) READ(org.molgenis.data.security.EntityTypePermission.READ) Collectors(java.util.stream.Collectors) File(java.io.File) FileRepositoryCollection(org.molgenis.data.file.support.FileRepositoryCollection) SecurityUtils(org.molgenis.security.core.utils.SecurityUtils) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) WithMockUser(org.springframework.security.test.context.support.WithMockUser) WRITE(org.molgenis.data.security.EntityTypePermission.WRITE) Assert.assertTrue(org.testng.Assert.assertTrue) MutableAclService(org.springframework.security.acls.model.MutableAclService) Entity(org.molgenis.data.Entity) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) MutableAcl(org.springframework.security.acls.model.MutableAcl) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Sid(org.springframework.security.acls.model.Sid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid)

Example 3 with EntityTypePermission

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

the class TestPermissionPopulator method populate.

/**
 * Populate entity type permissions for the current user.
 */
@Transactional
public void populate(Map<String, EntityTypePermission> entityTypePermissionMap, String username) {
    Sid sid = new PrincipalSid(username);
    runAsSystem(() -> entityTypePermissionMap.forEach((entityTypeId, permission) -> {
        MutableAcl acl = (MutableAcl) mutableAclService.readAclById(new EntityTypeIdentity(entityTypeId));
        acl.insertAce(acl.getEntries().size(), getCumulativePermission(permission), sid, true);
        mutableAclService.updateAcl(acl);
    }));
}
Also used : Sid(org.springframework.security.acls.model.Sid) EntityTypePermissionUtils.getCumulativePermission(org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission) RunAsSystemAspect.runAsSystem(org.molgenis.security.core.runas.RunAsSystemAspect.runAsSystem) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) SecurityUtils(org.molgenis.security.core.utils.SecurityUtils) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Component(org.springframework.stereotype.Component) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) MutableAcl(org.springframework.security.acls.model.MutableAcl) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) MutableAclService(org.springframework.security.acls.model.MutableAclService) Transactional(org.springframework.transaction.annotation.Transactional) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) MutableAcl(org.springframework.security.acls.model.MutableAcl) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Sid(org.springframework.security.acls.model.Sid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with EntityTypePermission

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

the class VcfImportServiceIT method populateUserPermissions.

private void populateUserPermissions() {
    Sid sid = new PrincipalSid(SecurityUtils.getCurrentUsername());
    Map<String, EntityTypePermission> entityTypePermissionMap = new HashMap<>();
    entityTypePermissionMap.put("sys_md_Package", READ);
    entityTypePermissionMap.put("sys_md_EntityType", READ);
    entityTypePermissionMap.put("sys_md_Attribute", READ);
    entityTypePermissionMap.put("sys_dec_DecoratorConfiguration", READ);
    runAsSystem(() -> entityTypePermissionMap.forEach((entityTypeId, permission) -> {
        MutableAcl acl = (MutableAcl) mutableAclService.readAclById(new EntityTypeIdentity(entityTypeId));
        acl.insertAce(acl.getEntries().size(), getCumulativePermission(permission), sid, true);
        mutableAclService.updateAcl(acl);
    }));
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) RunAsSystemAspect.runAsSystem(org.molgenis.security.core.runas.RunAsSystemAspect.runAsSystem) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) User(org.molgenis.data.security.auth.User) VcfAttributes(org.molgenis.data.vcf.model.VcfAttributes) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) PACKAGE_DEFAULT(org.molgenis.data.meta.DefaultPackage.PACKAGE_DEFAULT) MutableAcl(org.springframework.security.acls.model.MutableAcl) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) ImportService(org.molgenis.data.importer.ImportService) Sid(org.springframework.security.acls.model.Sid) ADD(org.molgenis.data.DatabaseAction.ADD) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) EntityTypePermissionUtils.getCumulativePermission(org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission) EntityImportReport(org.molgenis.data.importer.EntityImportReport) READ(org.molgenis.data.security.EntityTypePermission.READ) File(java.io.File) FileRepositoryCollection(org.molgenis.data.file.support.FileRepositoryCollection) SecurityUtils(org.molgenis.security.core.utils.SecurityUtils) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) WithMockUser(org.springframework.security.test.context.support.WithMockUser) MutableAclService(org.springframework.security.acls.model.MutableAclService) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) HashMap(java.util.HashMap) MutableAcl(org.springframework.security.acls.model.MutableAcl) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Sid(org.springframework.security.acls.model.Sid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid)

Aggregations

EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)4 EntityTypePermission (org.molgenis.data.security.EntityTypePermission)4 EntityTypePermissionUtils.getCumulativePermission (org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission)4 RunAsSystemAspect.runAsSystem (org.molgenis.security.core.runas.RunAsSystemAspect.runAsSystem)4 SecurityUtils (org.molgenis.security.core.utils.SecurityUtils)4 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)4 MutableAcl (org.springframework.security.acls.model.MutableAcl)4 MutableAclService (org.springframework.security.acls.model.MutableAclService)4 Sid (org.springframework.security.acls.model.Sid)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 File (java.io.File)3 ADD (org.molgenis.data.DatabaseAction.ADD)3 FileRepositoryCollection (org.molgenis.data.file.support.FileRepositoryCollection)3 EntityImportReport (org.molgenis.data.importer.EntityImportReport)3 ImportService (org.molgenis.data.importer.ImportService)3 PACKAGE_DEFAULT (org.molgenis.data.meta.DefaultPackage.PACKAGE_DEFAULT)3 READ (org.molgenis.data.security.EntityTypePermission.READ)3 User (org.molgenis.data.security.auth.User)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3