use of org.molgenis.security.permission.Permissions in project molgenis by molgenis.
the class PermissionManagerController method toEntityTypePermissions.
private Permissions toEntityTypePermissions(List<EntityType> entityTypes, Map<ObjectIdentity, Acl> aclMap, Sid sid) {
Permissions permissions = new Permissions();
// set permissions: entity ids
Map<String, String> entityTypeMap = entityTypes.stream().collect(toMap(EntityType::getId, EntityType::getId, (u, v) -> {
throw new IllegalStateException(format("Duplicate key %s", u));
}, LinkedHashMap::new));
permissions.setEntityIds(entityTypeMap);
return toEntityTypePermissions(aclMap, sid, permissions);
}
use of org.molgenis.security.permission.Permissions in project molgenis by molgenis.
the class PermissionManagerControllerTest method testGetUserPluginPermissions.
@Test
public void testGetUserPluginPermissions() {
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());
Map<ObjectIdentity, Acl> acls = new HashMap<>();
acls.put(pluginIdentity1, acl1);
acls.put(pluginIdentity2, acl2);
when(mutableAclService.readAclsById(Arrays.asList(pluginIdentity1, pluginIdentity2), singletonList(userSid))).thenReturn(acls);
when(ace1.getPermission()).thenReturn(pluginPermissionRead);
Permissions expected = new Permissions();
org.molgenis.security.permission.Permission permission = new org.molgenis.security.permission.Permission();
permission.setType("read");
expected.setUserId("Ipsum");
expected.addUserPermission(plugin1.getId(), permission);
Map<String, String> ids = new HashMap<>();
ids.put("1", "1");
ids.put("2", "2");
expected.setEntityIds(ids);
assertEquals(permissionManagerController.getUserPluginPermissions("1"), expected);
}
use of org.molgenis.security.permission.Permissions in project molgenis by molgenis.
the class PermissionManagerControllerTest method testGetGroupEntityTypePermissions.
@Test
public void testGetGroupEntityTypePermissions() {
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(entityIdentity1, acl1);
acls.put(entityIdentity2, acl2);
acls.put(entityIdentity3, acl3);
when(mutableAclService.readAclsById(Arrays.asList(entityIdentity1, entityIdentity2, entityIdentity3), 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(entityType1.getId(), permission1);
expected.addGroupPermission(entityType2.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.getGroupEntityClassPermissions("1"), expected);
}
use of org.molgenis.security.permission.Permissions in project molgenis by molgenis.
the class PermissionManagerControllerTest method testGetUserEntityClassPermissions.
@Test
public void testGetUserEntityClassPermissions() {
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(entityIdentity1, acl1);
acls.put(entityIdentity2, acl2);
acls.put(entityIdentity3, acl3);
when(mutableAclService.readAclsById(Arrays.asList(entityIdentity1, entityIdentity2, entityIdentity3), 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(entityType1.getId(), permission1);
expected.addUserPermission(entityType2.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.getUserEntityClassPermissions("1"), expected);
}
use of org.molgenis.security.permission.Permissions in project molgenis by molgenis.
the class PermissionManagerControllerTest method testGetGroupPluginPermissions.
@Test
public void testGetGroupPluginPermissions() {
MutableAcl acl1 = mock(MutableAcl.class);
MutableAcl acl2 = mock(MutableAcl.class);
AccessControlEntry ace1 = mock(AccessControlEntry.class);
when(ace1.getSid()).thenReturn(groupSid);
when(acl1.getEntries()).thenReturn(Collections.singletonList(ace1));
when(acl2.getEntries()).thenReturn(Collections.emptyList());
Map<ObjectIdentity, Acl> acls = new HashMap<>();
acls.put(pluginIdentity1, acl1);
acls.put(pluginIdentity2, acl2);
when(mutableAclService.readAclsById(Arrays.asList(pluginIdentity1, pluginIdentity2), singletonList(groupSid))).thenReturn(acls);
when(ace1.getPermission()).thenReturn(pluginPermissionRead);
Permissions expected = new Permissions();
org.molgenis.security.permission.Permission permission = new org.molgenis.security.permission.Permission();
permission.setType("read");
expected.setGroupId("1");
expected.addGroupPermission(entityType1.getId(), permission);
Map<String, String> ids = new HashMap<>();
ids.put("1", "1");
ids.put("2", "2");
expected.setEntityIds(ids);
assertEquals(permissionManagerController.getGroupPluginPermissions("1"), expected);
}
Aggregations