Search in sources :

Example 41 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl 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 42 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl 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 43 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl 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 44 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl in project molgenis by molgenis.

the class PackageRepositorySecurityDecoratorTest method testUpdate.

@Test
public void testUpdate() {
    Package pack = mock(Package.class);
    Package parent = mock(Package.class);
    when(pack.getId()).thenReturn("1");
    when(parent.getId()).thenReturn("2");
    when(pack.getParent()).thenReturn(parent);
    MutableAcl acl = mock(MutableAcl.class);
    MutableAcl parentAcl = mock(MutableAcl.class);
    when(mutableAclService.readAclById(any())).thenAnswer(invocation -> {
        Object argument = invocation.getArguments()[0];
        if (argument.equals(new PackageIdentity("1"))) {
            return acl;
        } else if (argument.equals(new PackageIdentity("2"))) {
            return parentAcl;
        }
        return null;
    });
    repo.update(pack);
    verify(mutableAclService).updateAcl(acl);
    verify(delegateRepository).update(pack);
}
Also used : PackageIdentity(org.molgenis.data.security.PackageIdentity) MutableAcl(org.springframework.security.acls.model.MutableAcl) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 45 with MutableAcl

use of org.springframework.security.acls.model.MutableAcl in project molgenis by molgenis.

the class PackageRepositorySecurityDecoratorTest method testAdd.

@Test
public void testAdd() {
    Package pack = mock(Package.class);
    Package parent = mock(Package.class);
    when(pack.getId()).thenReturn("1");
    when(parent.getId()).thenReturn("2");
    when(pack.getParent()).thenReturn(parent);
    MutableAcl acl = mock(MutableAcl.class);
    MutableAcl parentAcl = mock(MutableAcl.class);
    when(mutableAclService.createAcl(new PackageIdentity("1"))).thenReturn(acl);
    when(mutableAclService.readAclById(new PackageIdentity("2"))).thenReturn(parentAcl);
    repo.add(pack);
    verify(mutableAclService).createAcl(new PackageIdentity("1"));
    verify(mutableAclService).updateAcl(acl);
    verify(delegateRepository).add(pack);
}
Also used : PackageIdentity(org.molgenis.data.security.PackageIdentity) MutableAcl(org.springframework.security.acls.model.MutableAcl) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Aggregations

MutableAcl (org.springframework.security.acls.model.MutableAcl)58 Test (org.junit.jupiter.api.Test)23 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)20 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)17 Sid (org.springframework.security.acls.model.Sid)14 Authentication (org.springframework.security.core.Authentication)12 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)11 NotFoundException (org.springframework.security.acls.model.NotFoundException)10 ObjectIdentityImpl (org.springframework.security.acls.domain.ObjectIdentityImpl)9 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)8 Transactional (org.springframework.transaction.annotation.Transactional)8 Test (org.testng.annotations.Test)8 Test (org.junit.Test)7 PackageIdentity (org.molgenis.data.security.PackageIdentity)6 CumulativePermission (org.springframework.security.acls.domain.CumulativePermission)6 WithMockUser (org.springframework.security.test.context.support.WithMockUser)6 Package (org.molgenis.data.meta.model.Package)5 Acl (org.springframework.security.acls.model.Acl)5 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)5 File (java.io.File)4