Search in sources :

Example 6 with PluginIdentity

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

the class XmlMolgenisUiMenuTest method getActiveItem.

@Test
public void getActiveItem() {
    String menuId = "menuId";
    MenuType menuType = new MenuType();
    menuType.setName(menuId);
    PluginType plugin1Type = new PluginType();
    plugin1Type.setId("plugin1");
    plugin1Type.setName("plugin1");
    PluginType plugin2Type = new PluginType();
    plugin2Type.setId("plugin2");
    plugin2Type.setName("plugin2");
    PluginType plugin3Type = new PluginType();
    plugin3Type.setId("plugin3");
    plugin3Type.setName("plugin3");
    MenuType menu1Type = new MenuType();
    menu1Type.setName("menu1");
    menu1Type.getMenuOrPlugin().add(plugin3Type);
    menuType.getMenuOrPlugin().add(plugin1Type);
    menuType.getMenuOrPlugin().add(menu1Type);
    menuType.getMenuOrPlugin().add(plugin2Type);
    when(permissionService.hasPermission(new PluginIdentity("plugin1"), PluginPermission.READ)).thenReturn(false);
    when(permissionService.hasPermission(new PluginIdentity("plugin2"), PluginPermission.READ)).thenReturn(true);
    when(permissionService.hasPermission(new PluginIdentity("plugin3"), PluginPermission.READ)).thenReturn(true);
    XmlMolgenisUiMenu xmlMolgenisUiMenu = new XmlMolgenisUiMenu(menuType, permissionService);
    assertEquals(xmlMolgenisUiMenu.getActiveItem().getName(), "plugin2");
}
Also used : PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) Test(org.testng.annotations.Test)

Example 7 with PluginIdentity

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

the class XmlMolgenisUiPluginTest method isAuthorized.

@Test
public void isAuthorized() {
    String id = "plugin1";
    String type = "type";
    PluginType pluginType = new PluginType();
    pluginType.setName(type);
    pluginType.setId(id);
    when(permissionService.hasPermission(new PluginIdentity(id), PluginPermission.READ)).thenReturn(true);
    XmlMolgenisUiPlugin xmlMolgenisUiPlugin = new XmlMolgenisUiPlugin(pluginType, molgenisUiMenu, permissionService);
    assertTrue(xmlMolgenisUiPlugin.isAuthorized());
}
Also used : PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) Test(org.testng.annotations.Test)

Example 8 with PluginIdentity

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

the class MolgenisAccessDecisionVoterTest method setUp.

@BeforeMethod
public void setUp() {
    UserPermissionEvaluator permissionService = mock(UserPermissionEvaluator.class);
    when(permissionService.hasPermission(new PluginIdentity("plugingranted"), PluginPermission.READ)).thenReturn(true);
    when(permissionService.hasPermission(new PluginIdentity("plugindenied"), PluginPermission.READ)).thenReturn(false);
    Ui molgenisUi = mock(Ui.class);
    UiMenu menu = mock(UiMenu.class);
    when(molgenisUi.getMenu("menugranted")).thenReturn(menu);
    when(molgenisUi.getMenu("menudenied")).thenReturn(null);
    ApplicationContext ctx = mock(ApplicationContext.class);
    when(ctx.getBean(UserPermissionEvaluator.class)).thenReturn(permissionService);
    when(ctx.getBean(Ui.class)).thenReturn(molgenisUi);
    new ApplicationContextProvider().setApplicationContext(ctx);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) UserPermissionEvaluator(org.molgenis.security.core.UserPermissionEvaluator) Ui(org.molgenis.web.Ui) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) ApplicationContextProvider(org.molgenis.util.ApplicationContextProvider) UiMenu(org.molgenis.web.UiMenu) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 9 with PluginIdentity

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

the class PermissionRegistryImpl method getPermissions.

@Override
public Multimap<ObjectIdentity, Pair<Permission, Sid>> getPermissions() {
    ImmutableMultimap.Builder<ObjectIdentity, Pair<Permission, Sid>> mapBuilder = new ImmutableMultimap.Builder<>();
    Group allUsersGroup = dataService.query(GROUP, Group.class).eq(NAME, ALL_USER_GROUP).findOne();
    Sid allUsersGroupSid = createSid(allUsersGroup);
    ObjectIdentity pluginIdentity = new PluginIdentity(UserAccountController.ID);
    mapBuilder.putAll(pluginIdentity, new Pair<>(PluginPermission.READ, allUsersGroupSid));
    dataService.findAll(ENTITY_TYPE_META_DATA, Stream.of(ENTITY_TYPE_META_DATA, ATTRIBUTE_META_DATA, PACKAGE, TAG, LANGUAGE, L10N_STRING, FILE_META, DECORATOR_CONFIGURATION), EntityType.class).forEach(entityType -> {
        ObjectIdentity entityTypeIdentity = new EntityTypeIdentity(entityType);
        Permission entityTypePermissions = EntityTypePermissionUtils.getCumulativePermission(EntityTypePermission.READ);
        mapBuilder.putAll(entityTypeIdentity, new Pair<>(entityTypePermissions, allUsersGroupSid));
    });
    return mapBuilder.build();
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Group(org.molgenis.data.security.auth.Group) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) Permission(org.springframework.security.acls.model.Permission) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) PluginPermission(org.molgenis.data.plugin.model.PluginPermission) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Pair(org.molgenis.util.Pair) SidUtils.createSid(org.molgenis.security.acl.SidUtils.createSid) Sid(org.springframework.security.acls.model.Sid)

Example 10 with PluginIdentity

use of org.molgenis.data.plugin.model.PluginIdentity 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)

Aggregations

PluginIdentity (org.molgenis.data.plugin.model.PluginIdentity)18 Test (org.testng.annotations.Test)13 Group (org.molgenis.data.security.auth.Group)4 Pair (org.molgenis.util.Pair)3 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)3 EntityType (org.molgenis.data.meta.model.EntityType)2 PluginPermission (org.molgenis.data.plugin.model.PluginPermission)2 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)2 User (org.molgenis.data.security.auth.User)2 SidUtils.createSid (org.molgenis.security.acl.SidUtils.createSid)2 UiMenu (org.molgenis.web.UiMenu)2 GrantedAuthoritySid (org.springframework.security.acls.domain.GrantedAuthoritySid)2 Permission (org.springframework.security.acls.model.Permission)2 Sid (org.springframework.security.acls.model.Sid)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Matcher (java.util.regex.Matcher)1 Package (org.molgenis.data.meta.model.Package)1 Plugin (org.molgenis.data.plugin.model.Plugin)1 EntityTypePermission (org.molgenis.data.security.EntityTypePermission)1