Search in sources :

Example 1 with Plugin

use of org.molgenis.data.plugin.model.Plugin in project molgenis by molgenis.

the class PluginPopulatorTest method testPopulate.

@Test
public void testPopulate() throws Exception {
    PluginController pluginController0 = when(mock(PluginController.class).getId()).thenReturn("newPlugin").getMock();
    PluginController pluginController1 = when(mock(PluginController.class).getId()).thenReturn("changedPlugin").getMock();
    ApplicationContext ctx = mock(ApplicationContext.class);
    when(ctx.getBeansOfType(PluginController.class)).thenReturn(ImmutableMap.of("newPlugin", pluginController0, "changedPlugin", pluginController1));
    Plugin newPlugin = when(mock(Plugin.class).getId()).thenReturn("newPlugin").getMock();
    when(newPlugin.setLabel("newPlugin")).thenReturn(newPlugin);
    Plugin changedPlugin = when(mock(Plugin.class).getId()).thenReturn("changedPlugin").getMock();
    when(changedPlugin.setLabel("changedPlugin")).thenReturn(changedPlugin);
    Plugin existingChangedPlugin = when(mock(Plugin.class).getId()).thenReturn("changedPlugin").getMock();
    when(existingChangedPlugin.setLabel("oldChangedPlugin")).thenReturn(existingChangedPlugin);
    Plugin deletedPlugin = when(mock(Plugin.class).getId()).thenReturn("deletedPlugin").getMock();
    when(deletedPlugin.setLabel("deletedPlugin")).thenReturn(deletedPlugin);
    when(pluginFactory.create("newPlugin")).thenReturn(newPlugin);
    when(pluginFactory.create("changedPlugin")).thenReturn(changedPlugin);
    when(dataService.getRepository(PluginMetadata.PLUGIN, Plugin.class)).thenReturn(pluginRepository);
    when(dataService.findAll(PluginMetadata.PLUGIN, Plugin.class)).thenReturn(Stream.of(existingChangedPlugin, deletedPlugin));
    pluginPopulator.populate(ctx);
    verify(pluginRepository).upsertBatch(updateStreamArgumentCaptor.capture());
    assertEquals(newHashSet(updateStreamArgumentCaptor.getValue()), newHashSet(newPlugin, changedPlugin));
    verify(dataService).delete(eq(PluginMetadata.PLUGIN), deleteStreamArgumentCaptor.capture());
    assertEquals(deleteStreamArgumentCaptor.getValue().collect(toList()), singletonList(deletedPlugin));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) PluginController(org.molgenis.web.PluginController) Plugin(org.molgenis.data.plugin.model.Plugin) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 2 with Plugin

use of org.molgenis.data.plugin.model.Plugin 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 3 with Plugin

use of org.molgenis.data.plugin.model.Plugin in project molgenis by molgenis.

the class PermissionManagerController method updatePluginPermissions.

private void updatePluginPermissions(WebRequest webRequest, Sid sid) {
    for (Plugin plugin : getPlugins()) {
        String param = "radio-" + plugin.getId();
        String value = webRequest.getParameter(param);
        if (value != null) {
            if (!value.equals("none")) {
                createSidPluginPermission(plugin, sid, toPluginPermission(value));
            } else {
                removeSidPluginPermission(plugin, sid);
            }
        }
    }
}
Also used : Plugin(org.molgenis.data.plugin.model.Plugin)

Example 4 with Plugin

use of org.molgenis.data.plugin.model.Plugin in project molgenis by molgenis.

the class PermissionManagerController method toPluginPermissions.

private Permissions toPluginPermissions(List<Plugin> plugins, Map<ObjectIdentity, Acl> aclMap, Sid sid) {
    Permissions permissions = new Permissions();
    // set permissions: entity ids
    Map<String, String> pluginMap = plugins.stream().collect(toMap(Plugin::getId, Plugin::getId, (u, v) -> {
        throw new IllegalStateException(format("Duplicate key %s", u));
    }, LinkedHashMap::new));
    permissions.setEntityIds(pluginMap);
    // set permissions: user of group id
    boolean isUser = setUserOrGroup(sid, permissions);
    // set permissions: permissions
    aclMap.forEach((objectIdentity, acl) -> {
        String pluginId = objectIdentity.getIdentifier().toString();
        acl.getEntries().forEach(ace -> {
            if (ace.getSid().equals(sid)) {
                org.molgenis.security.permission.Permission pluginPermission = toPluginPermission(ace);
                if (isUser) {
                    permissions.addUserPermission(pluginId, pluginPermission);
                } else {
                    permissions.addGroupPermission(pluginId, pluginPermission);
                }
            }
        });
    });
    return permissions;
}
Also used : PluginController(org.molgenis.web.PluginController) java.util(java.util) EntityTypeMetadata(org.molgenis.data.meta.model.EntityTypeMetadata) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) WebRequest(org.springframework.web.context.request.WebRequest) LoggerFactory(org.slf4j.LoggerFactory) PackageMetadata(org.molgenis.data.meta.model.PackageMetadata) Controller(org.springframework.stereotype.Controller) Collections.singletonList(java.util.Collections.singletonList) Valid(javax.validation.Valid) User(org.molgenis.data.security.auth.User) Model(org.springframework.ui.Model) Lists(com.google.common.collect.Lists) ANONYMOUS_USERNAME(org.molgenis.security.core.utils.SecurityUtils.ANONYMOUS_USERNAME) Collectors.toMap(java.util.stream.Collectors.toMap) USER(org.molgenis.data.security.auth.UserMetaData.USER) PluginPermission(org.molgenis.data.plugin.model.PluginPermission) Objects.requireNonNull(java.util.Objects.requireNonNull) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) SystemEntityTypeRegistry(org.molgenis.data.meta.system.SystemEntityTypeRegistry) org.springframework.security.acls.model(org.springframework.security.acls.model) Comparator.comparing(java.util.Comparator.comparing) URI(org.molgenis.core.ui.admin.permission.PermissionManagerController.URI) SidUtils(org.molgenis.security.acl.SidUtils) Logger(org.slf4j.Logger) USERNAME(org.molgenis.data.security.auth.UserMetaData.USERNAME) org.molgenis.data.security(org.molgenis.data.security) SidUtils.createAnonymousSid(org.molgenis.security.acl.SidUtils.createAnonymousSid) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) MutableAclClassService(org.molgenis.security.acl.MutableAclClassService) String.format(java.lang.String.format) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) HttpStatus(org.springframework.http.HttpStatus) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) GROUP(org.molgenis.data.security.auth.GroupMetaData.GROUP) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) DataService(org.molgenis.data.DataService) Package(org.molgenis.data.meta.model.Package) Group(org.molgenis.data.security.auth.Group) PLUGIN(org.molgenis.data.plugin.model.PluginMetadata.PLUGIN) Permissions(org.molgenis.security.permission.Permissions) Plugin(org.molgenis.data.plugin.model.Plugin) Transactional(org.springframework.transaction.annotation.Transactional) Permissions(org.molgenis.security.permission.Permissions)

Aggregations

Plugin (org.molgenis.data.plugin.model.Plugin)4 EntityType (org.molgenis.data.meta.model.EntityType)2 Package (org.molgenis.data.meta.model.Package)2 PluginIdentity (org.molgenis.data.plugin.model.PluginIdentity)2 Group (org.molgenis.data.security.auth.Group)2 User (org.molgenis.data.security.auth.User)2 PluginController (org.molgenis.web.PluginController)2 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)2 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)2 Lists (com.google.common.collect.Lists)1 String.format (java.lang.String.format)1 java.util (java.util)1 Collections.singletonList (java.util.Collections.singletonList)1 Comparator.comparing (java.util.Comparator.comparing)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Stream (java.util.stream.Stream)1 Valid (javax.validation.Valid)1