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