use of org.molgenis.security.permission.Permissions in project molgenis by molgenis.
the class PermissionManagerControllerTest method testGetGroupPackagePermissions.
@Test
public void testGetGroupPackagePermissions() {
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);
when(ace1.getSid()).thenReturn(groupSid);
when(ace2.getSid()).thenReturn(groupSid);
when(acl1.getEntries()).thenReturn(Collections.singletonList(ace1));
when(acl2.getEntries()).thenReturn(Collections.singletonList(ace2));
when(acl3.getEntries()).thenReturn(Collections.emptyList());
Map<ObjectIdentity, Acl> acls = new HashMap<>();
acls.put(packageIdentity1, acl1);
acls.put(packageIdentity2, acl2);
acls.put(packageIdentity3, acl3);
when(mutableAclService.readAclsById(Arrays.asList(packageIdentity1, packageIdentity2, packageIdentity3), singletonList(groupSid))).thenReturn(acls);
when(ace1.getPermission()).thenReturn(cumulativeEntityPermissionWrite);
when(ace2.getPermission()).thenReturn(cumulativeEntityPermissionRead);
Permissions expected = new Permissions();
org.molgenis.security.permission.Permission permission1 = new org.molgenis.security.permission.Permission();
permission1.setType("write");
org.molgenis.security.permission.Permission permission2 = new org.molgenis.security.permission.Permission();
permission2.setType("read");
expected.setGroupId("1");
expected.addGroupPermission(package1.getId(), permission1);
expected.addGroupPermission(package2.getId(), permission2);
Map<String, String> ids = new HashMap<>();
ids.put("1", "1");
ids.put("2", "2");
ids.put("3", "3");
expected.setEntityIds(ids);
assertEquals(permissionManagerController.getGroupPackagePermissions("1"), expected);
}
use of org.molgenis.security.permission.Permissions in project molgenis by molgenis.
the class PermissionManagerControllerTest method testGetUserPackagePermissions.
@Test
public void testGetUserPackagePermissions() {
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);
when(ace1.getSid()).thenReturn(userSid);
when(ace2.getSid()).thenReturn(userSid);
when(acl1.getEntries()).thenReturn(Collections.singletonList(ace1));
when(acl2.getEntries()).thenReturn(Collections.singletonList(ace2));
when(acl3.getEntries()).thenReturn(Collections.emptyList());
Map<ObjectIdentity, Acl> acls = new HashMap<>();
acls.put(packageIdentity1, acl1);
acls.put(packageIdentity2, acl2);
acls.put(packageIdentity3, acl3);
when(mutableAclService.readAclsById(Arrays.asList(packageIdentity1, packageIdentity2, packageIdentity3), singletonList(userSid))).thenReturn(acls);
when(ace1.getPermission()).thenReturn(cumulativeEntityPermissionWritemeta);
when(ace2.getPermission()).thenReturn(cumulativeEntityPermissionCount);
Permissions expected = new Permissions();
org.molgenis.security.permission.Permission permission1 = new org.molgenis.security.permission.Permission();
permission1.setType("writemeta");
org.molgenis.security.permission.Permission permission2 = new org.molgenis.security.permission.Permission();
permission2.setType("count");
expected.setUserId("Ipsum");
expected.addUserPermission(package1.getId(), permission1);
expected.addUserPermission(package2.getId(), permission2);
Map<String, String> ids = new HashMap<>();
ids.put("1", "1");
ids.put("2", "2");
ids.put("3", "3");
expected.setEntityIds(ids);
assertEquals(permissionManagerController.getUserPackagePermissions("1"), expected);
}
use of org.molgenis.security.permission.Permissions in project molgenis by molgenis.
the class PermissionManagerController method toPluginPermissions.
private Permissions toPluginPermissions(List<Plugin> plugins, Map<ObjectIdentity, Acl> aclMap, Sid sid) {
Permissions permissions = new Permissions();
// set permissions: entity ids
Map<String, String> pluginMap = plugins.stream().collect(toMap(Plugin::getId, Plugin::getId, (u, v) -> {
throw new IllegalStateException(format("Duplicate key %s", u));
}, LinkedHashMap::new));
permissions.setEntityIds(pluginMap);
// set permissions: user of group id
boolean isUser = setUserOrGroup(sid, permissions);
// set permissions: permissions
aclMap.forEach((objectIdentity, acl) -> {
String pluginId = objectIdentity.getIdentifier().toString();
acl.getEntries().forEach(ace -> {
if (ace.getSid().equals(sid)) {
org.molgenis.security.permission.Permission pluginPermission = toPluginPermission(ace);
if (isUser) {
permissions.addUserPermission(pluginId, pluginPermission);
} else {
permissions.addGroupPermission(pluginId, pluginPermission);
}
}
});
});
return permissions;
}
use of org.molgenis.security.permission.Permissions in project molgenis by molgenis.
the class PermissionManagerController method toPackagePermissions.
private Permissions toPackagePermissions(List<Package> packages, Map<ObjectIdentity, Acl> aclMap, Sid sid) {
Permissions permissions = new Permissions();
// set permissions: entity ids
Map<String, String> entityTypeMap = packages.stream().collect(toMap(Package::getId, Package::getId, (u, v) -> {
throw new IllegalStateException(format("Duplicate key %s", u));
}, LinkedHashMap::new));
permissions.setEntityIds(entityTypeMap);
return toEntityTypePermissions(aclMap, sid, permissions);
}
Aggregations