Search in sources :

Example 36 with EntityTypeIdentity

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

the class StaticContentServiceImplTest method checkPermissionsNoException.

@Test
public void checkPermissionsNoException() {
    doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(STATIC_CONTENT), EntityTypePermission.WRITE);
    staticContentService.checkPermissions("home");
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 37 with EntityTypeIdentity

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

the class StaticContentServiceImplTest method isCurrentUserCanEditTrue.

@Test
public void isCurrentUserCanEditTrue() {
    doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(STATIC_CONTENT), EntityTypePermission.WRITE);
    assertTrue(staticContentService.isCurrentUserCanEdit("home"));
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 38 with EntityTypeIdentity

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

the class StaticContentServiceImplTest method submitContentNew.

@Test
public void submitContentNew() {
    when(dataService.findOneById(STATIC_CONTENT, "home", StaticContent.class)).thenReturn(null);
    when(staticContentFactory.create("home")).thenReturn(staticContent);
    doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(STATIC_CONTENT), EntityTypePermission.WRITE);
    assertTrue(this.staticContentService.submitContent("home", "<p>New Content!</p>"));
    verify(staticContent).setContent("<p>New Content!</p>");
    verify(dataService).add(STATIC_CONTENT, staticContent);
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 39 with EntityTypeIdentity

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

the class StaticContentServiceImplTest method isCurrentUserCanEditNoEntityTypePermissionFalse.

@Test
public void isCurrentUserCanEditNoEntityTypePermissionFalse() {
    doReturn(false).when(permissionService).hasPermission(new EntityTypeIdentity(STATIC_CONTENT), EntityTypePermission.WRITE);
    assertFalse(staticContentService.isCurrentUserCanEdit("home"));
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 40 with EntityTypeIdentity

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

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