use of org.molgenis.data.security.EntityTypeIdentity 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.security.EntityTypeIdentity in project molgenis by molgenis.
the class EmxImportServiceIT method populateUserPermissions.
private void populateUserPermissions() {
Sid sid = new PrincipalSid(SecurityUtils.getCurrentUsername());
Map<String, EntityTypePermission> entityTypePermissionMap = new HashMap<>();
entityTypePermissionMap.put("sys_md_Package", READ);
entityTypePermissionMap.put("sys_md_EntityType", READ);
entityTypePermissionMap.put("sys_md_Attribute", READ);
entityTypePermissionMap.put("sys_md_Tag", READ);
entityTypePermissionMap.put("sys_FileMeta", READ);
entityTypePermissionMap.put("sys_dec_DecoratorConfiguration", READ);
runAsSystem(() -> entityTypePermissionMap.forEach((entityTypeId, permission) -> {
MutableAcl acl = (MutableAcl) mutableAclService.readAclById(new EntityTypeIdentity(entityTypeId));
acl.insertAce(acl.getEntries().size(), getCumulativePermission(permission), sid, true);
mutableAclService.updateAcl(acl);
}));
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class QuestionnaireServiceTest method testGetQuestionnaires.
@Test
public void testGetQuestionnaires() {
// =========== Setup ===========
EntityType entityType = mock(EntityType.class);
when(entityType.getId()).thenReturn(QUESTIONNAIRE_ID);
when(entityType.getLabel()).thenReturn("label");
when(entityType.getDescription()).thenReturn("description");
Query<EntityType> typedQuery = mock(Query.class);
Query<EntityType> query = mock(Query.class);
when(typedQuery.eq(EntityTypeMetadata.EXTENDS, QUESTIONNAIRE)).thenReturn(query);
when(dataService.query(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(typedQuery);
when(query.findAll()).thenReturn(Stream.of(entityType));
when(userPermissionEvaluator.hasPermission(new EntityTypeIdentity(QUESTIONNAIRE_ID), WRITE)).thenReturn(true);
Entity entity = mock(Entity.class);
when(dataService.findOne(QUESTIONNAIRE_ID, EQ(OWNER_USERNAME, null))).thenReturn(entity);
Questionnaire questionnaire = mock(Questionnaire.class);
when(questionnaire.getStatus()).thenReturn(OPEN);
when(questionnaireFactory.create(entity)).thenReturn(questionnaire);
// =========== Test ===========
List<QuestionnaireResponse> actual = questionnaireService.getQuestionnaires();
QuestionnaireResponse questionnaireResponse = QuestionnaireResponse.create(QUESTIONNAIRE_ID, "label", "description", OPEN);
List<QuestionnaireResponse> expected = newArrayList(questionnaireResponse);
assertEquals(actual, expected);
}
use of org.molgenis.data.security.EntityTypeIdentity 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);
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class PermissionManagerControllerTest method testUpdateUserEntityClassPermissions.
@Test
public void testUpdateUserEntityClassPermissions() {
WebRequest webRequest = mock(WebRequest.class);
when(webRequest.getParameter("radio-1")).thenReturn("write");
when(webRequest.getParameter("radio-2")).thenReturn("none");
when(webRequest.getParameter("radio-3")).thenReturn("read");
ObjectIdentity objectIdentity1 = new EntityTypeIdentity(entityType1);
ObjectIdentity objectIdentity2 = new EntityTypeIdentity(entityType2);
ObjectIdentity objectIdentity3 = new EntityTypeIdentity(entityType3);
MutableAcl acl1 = mock(MutableAcl.class);
MutableAcl acl2 = mock(MutableAcl.class);
MutableAcl acl3 = mock(MutableAcl.class);
AccessControlEntry ace1 = mock(AccessControlEntry.class);
AccessControlEntry ace2 = mock(AccessControlEntry.class);
PrincipalSid sid = new PrincipalSid("Ipsum");
when(ace1.getSid()).thenReturn(sid);
when(ace2.getSid()).thenReturn(sid);
when(acl1.getEntries()).thenReturn(Collections.singletonList(ace1));
when(acl2.getEntries()).thenReturn(Collections.singletonList(ace2));
when(acl3.getEntries()).thenReturn(Collections.emptyList());
when(mutableAclService.readAclById(objectIdentity1, singletonList(sid))).thenReturn(acl1);
when(mutableAclService.readAclById(objectIdentity2, singletonList(sid))).thenReturn(acl2);
when(mutableAclService.readAclById(objectIdentity3, singletonList(sid))).thenReturn(acl3);
permissionManagerController.updateUserEntityClassPermissions("1", webRequest);
verify(acl1).deleteAce(0);
verify(acl1).insertAce(0, cumulativeEntityPermissionWrite, sid, true);
verify(acl2).deleteAce(0);
verify(acl3).insertAce(0, cumulativeEntityPermissionRead, sid, true);
verify(mutableAclService).updateAcl(acl1);
verify(mutableAclService).updateAcl(acl2);
verify(mutableAclService).updateAcl(acl3);
}
Aggregations