Search in sources :

Example 6 with PackageIdentity

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

the class PermissionManagerControllerTest method setUp.

@BeforeMethod
public void setUp() {
    config.resetMocks();
    mockMvc = MockMvcBuilders.standaloneSetup(permissionManagerController).setMessageConverters(gsonHttpMessageConverter).build();
    user1 = when(mock(User.class).getId()).thenReturn("1").getMock();
    when(user1.isSuperuser()).thenReturn(true);
    when(user1.getUsername()).thenReturn("Ipsum");
    userSid = new PrincipalSid("Ipsum");
    user2 = when(mock(User.class).getId()).thenReturn("2").getMock();
    group1 = when(mock(Group.class).getId()).thenReturn("1").getMock();
    groupSid = new GrantedAuthoritySid("ROLE_1");
    group2 = when(mock(Group.class).getId()).thenReturn("2").getMock();
    plugin1 = when(mock(Plugin.class).getId()).thenReturn("1").getMock();
    plugin2 = when(mock(Plugin.class).getId()).thenReturn("2").getMock();
    pluginIdentity1 = new PluginIdentity(plugin1);
    pluginIdentity2 = new PluginIdentity(plugin2);
    entityType1 = when(mock(EntityType.class).getId()).thenReturn("1").getMock();
    entityType2 = when(mock(EntityType.class).getId()).thenReturn("2").getMock();
    entityType3 = when(mock(EntityType.class).getId()).thenReturn("3").getMock();
    when(entityType1.getLabel()).thenReturn("label1");
    when(entityType2.getLabel()).thenReturn("label2");
    when(entityType3.getLabel()).thenReturn("label3");
    entityIdentity1 = new EntityTypeIdentity(entityType1);
    entityIdentity2 = new EntityTypeIdentity(entityType2);
    entityIdentity3 = new EntityTypeIdentity(entityType3);
    package1 = when(mock(Package.class).getId()).thenReturn("1").getMock();
    package2 = when(mock(Package.class).getId()).thenReturn("2").getMock();
    package3 = when(mock(Package.class).getId()).thenReturn("3").getMock();
    packageIdentity1 = new PackageIdentity(package1);
    packageIdentity2 = new PackageIdentity(package2);
    packageIdentity3 = new PackageIdentity(package3);
    when(dataService.findAll(USER, User.class)).thenReturn(Stream.of(user1, user2));
    when(dataService.findAll(GROUP, Group.class)).thenReturn(Stream.of(group1, group2));
    when(dataService.findOneById(GROUP, "1", Group.class)).thenReturn(group1);
    when(dataService.findOneById(USER, "1", User.class)).thenReturn(user1);
    when(dataService.findAll(PLUGIN, Plugin.class)).thenReturn(Stream.of(plugin1, plugin2));
    when(dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(Stream.of(entityType1, entityType2, entityType3));
    when(dataService.findAll(PACKAGE, Package.class)).thenReturn(Stream.of(package1, package2, package3));
    pluginPermissionRead = PluginPermission.READ;
    cumulativeEntityPermissionWritemeta = new CumulativePermission();
    cumulativeEntityPermissionWritemeta.set(EntityTypePermission.WRITEMETA).set(EntityTypePermission.WRITE).set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
    cumulativeEntityPermissionWrite = new CumulativePermission();
    cumulativeEntityPermissionWrite.set(EntityTypePermission.WRITE).set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
    cumulativeEntityPermissionRead = new CumulativePermission();
    cumulativeEntityPermissionRead.set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
    cumulativeEntityPermissionCount = new CumulativePermission();
    cumulativeEntityPermissionCount.set(EntityTypePermission.COUNT);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Group(org.molgenis.data.security.auth.Group) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) User(org.molgenis.data.security.auth.User) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) CumulativePermission(org.springframework.security.acls.domain.CumulativePermission) PackageIdentity(org.molgenis.data.security.PackageIdentity) Package(org.molgenis.data.meta.model.Package) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Plugin(org.molgenis.data.plugin.model.Plugin) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with PackageIdentity

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

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

the class PackageRepositorySecurityDecoratorTest method testDelete.

@Test
public void testDelete() {
    Package pack = mock(Package.class);
    when(pack.getId()).thenReturn("1");
    repo.delete(pack);
    verify(mutableAclService).deleteAcl(new PackageIdentity("1"), true);
    verify(delegateRepository).delete(pack);
}
Also used : PackageIdentity(org.molgenis.data.security.PackageIdentity) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 9 with PackageIdentity

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

the class PackageRepositorySecurityDecoratorTest method testDeleteById.

@Test
public void testDeleteById() {
    repo.deleteById("1");
    verify(mutableAclService).deleteAcl(new PackageIdentity("1"), true);
    verify(delegateRepository).deleteById("1");
}
Also used : PackageIdentity(org.molgenis.data.security.PackageIdentity) Test(org.testng.annotations.Test)

Example 10 with PackageIdentity

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

PackageIdentity (org.molgenis.data.security.PackageIdentity)10 Package (org.molgenis.data.meta.model.Package)6 MutableAcl (org.springframework.security.acls.model.MutableAcl)6 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)4 Test (org.testng.annotations.Test)4 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)3 Acl (org.springframework.security.acls.model.Acl)3 EntityType (org.molgenis.data.meta.model.EntityType)1 Plugin (org.molgenis.data.plugin.model.Plugin)1 PluginIdentity (org.molgenis.data.plugin.model.PluginIdentity)1 Group (org.molgenis.data.security.auth.Group)1 User (org.molgenis.data.security.auth.User)1 CumulativePermission (org.springframework.security.acls.domain.CumulativePermission)1 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)1 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)1 BeforeMethod (org.testng.annotations.BeforeMethod)1