Search in sources :

Example 41 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity 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 42 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity 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)

Example 43 with EntityTypeIdentity

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

the class MolgenisPermissionControllerTest method hasReadPermissionTrue.

@Test
public void hasReadPermissionTrue() {
    String entityTypeId = "entity";
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.READ)).thenReturn(true);
    assertTrue(molgenisPermissionController.hasReadPermission(entityTypeId));
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Test(org.testng.annotations.Test)

Example 44 with EntityTypeIdentity

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

the class MolgenisPermissionControllerTest method hasWritePermissionTrue.

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

Example 45 with EntityTypeIdentity

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

the class MolgenisPermissionControllerTest method hasReadPermissionFalse.

@Test
public void hasReadPermissionFalse() {
    String entityTypeId = "entity";
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.READ)).thenReturn(false);
    assertFalse(molgenisPermissionController.hasReadPermission(entityTypeId));
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) 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