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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations