Search in sources :

Example 11 with PluginIdentity

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

the class PermissionManagerControllerTest method testUpdateUserPluginPermissions.

@Test
public void testUpdateUserPluginPermissions() {
    WebRequest webRequest = mock(WebRequest.class);
    when(webRequest.getParameter("radio-1")).thenReturn("read");
    when(webRequest.getParameter("radio-2")).thenReturn("none");
    ObjectIdentity objectIdentity1 = new PluginIdentity(plugin1);
    ObjectIdentity objectIdentity2 = new PluginIdentity(plugin2);
    MutableAcl acl1 = mock(MutableAcl.class);
    MutableAcl acl2 = mock(MutableAcl.class);
    AccessControlEntry ace1 = mock(AccessControlEntry.class);
    when(ace1.getSid()).thenReturn(userSid);
    when(acl1.getEntries()).thenReturn(Collections.singletonList(ace1));
    when(acl2.getEntries()).thenReturn(Collections.emptyList());
    when(mutableAclService.readAclById(objectIdentity1, singletonList(userSid))).thenReturn(acl1);
    when(mutableAclService.readAclById(objectIdentity2, singletonList(userSid))).thenReturn(acl2);
    permissionManagerController.updateUserPluginPermissions("1", webRequest);
    verify(acl1).insertAce(0, pluginPermissionRead, userSid, true);
    verify(mutableAclService).updateAcl(acl1);
}
Also used : WebRequest(org.springframework.web.context.request.WebRequest) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) Test(org.testng.annotations.Test)

Example 12 with PluginIdentity

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

the class XmlMolgenisUiMenuTest method isAuthorized_partiallyAuthorized.

@Test
public void isAuthorized_partiallyAuthorized() {
    PluginType plugin1Type = new PluginType();
    String plugin1Name = "type1";
    String plugin1Id = "plugin1";
    plugin1Type.setName(plugin1Name);
    plugin1Type.setId(plugin1Id);
    PluginType plugin2Type = new PluginType();
    String plugin2Name = "type2";
    String plugin2Id = "plugin2";
    plugin2Type.setName(plugin2Name);
    plugin2Type.setId(plugin2Id);
    when(permissionService.hasPermission(new PluginIdentity(plugin1Id), PluginPermission.READ)).thenReturn(false);
    when(permissionService.hasPermission(new PluginIdentity(plugin2Id), PluginPermission.READ)).thenReturn(true);
    MenuType menuType = new MenuType();
    menuType.getMenuOrPlugin().add(plugin1Type);
    menuType.getMenuOrPlugin().add(plugin2Type);
    XmlMolgenisUiMenu xmlMolgenisUiMenu = new XmlMolgenisUiMenu(menuType, permissionService);
    assertTrue(xmlMolgenisUiMenu.isAuthorized());
}
Also used : PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) Test(org.testng.annotations.Test)

Example 13 with PluginIdentity

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

the class XmlMolgenisUiMenuTest method isAuthorized_notAuthorized.

@Test
public void isAuthorized_notAuthorized() {
    PluginType pluginType = new PluginType();
    pluginType.setId("something");
    when(permissionService.hasPermission(new PluginIdentity("something"), PluginPermission.READ)).thenReturn(false);
    MenuType menuType = new MenuType();
    menuType.getMenuOrPlugin().add(pluginType);
    XmlMolgenisUiMenu xmlMolgenisUiMenu = new XmlMolgenisUiMenu(menuType, permissionService);
    assertFalse(xmlMolgenisUiMenu.isAuthorized());
}
Also used : PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) Test(org.testng.annotations.Test)

Example 14 with PluginIdentity

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

the class XmlMolgenisUiMenuTest method isAuthorized.

@Test
public void isAuthorized() {
    PluginType pluginType = new PluginType();
    String pluginId = "plugin1";
    String pluginName = "type";
    pluginType.setName(pluginName);
    pluginType.setId(pluginId);
    when(permissionService.hasPermission(new PluginIdentity(pluginId), PluginPermission.READ)).thenReturn(true);
    MenuType menuType = new MenuType();
    menuType.getMenuOrPlugin().add(pluginType);
    XmlMolgenisUiMenu xmlMolgenisUiMenu = new XmlMolgenisUiMenu(menuType, permissionService);
    assertTrue(xmlMolgenisUiMenu.isAuthorized());
}
Also used : PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) Test(org.testng.annotations.Test)

Example 15 with PluginIdentity

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

the class PermissionRegistryImplTest method testGetPermissions.

@Test
public void testGetPermissions() {
    @SuppressWarnings("unchecked") Query<Group> query = mock(Query.class);
    when(query.eq("name", "All Users")).thenReturn(query);
    when(dataService.query("sys_sec_Group", Group.class)).thenReturn(query);
    Group group = when(mock(Group.class).getId()).thenReturn("group0").getMock();
    when(query.findOne()).thenReturn(group);
    Multimap<ObjectIdentity, Pair<Permission, Sid>> expectedPermissions = ImmutableListMultimap.of(new PluginIdentity("useraccount"), new Pair<>(PluginPermission.READ, new GrantedAuthoritySid("ROLE_group0")));
    assertEquals(permissionRegistryImpl.getPermissions(), expectedPermissions);
}
Also used : Group(org.molgenis.data.security.auth.Group) ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) Pair(org.molgenis.util.Pair) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

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