use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findAllIdsUser.
@WithMockUser(username = USERNAME)
@Test
public void findAllIdsUser() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String entityType1Name = "entity1";
EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
String attr0Name = "entity0attr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
String attr1Name = "entity1attr0";
Attribute attr1 = when(mock(Attribute.class).getName()).thenReturn(attr1Name).getMock();
when(attr1.getEntity()).thenReturn(entityType1);
Stream<Object> ids = Stream.of(mock(Object.class), mock(Object.class));
when(delegateRepository.findAll(ids)).thenReturn(Stream.of(attr0, attr1));
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(false);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.findAll(ids).collect(toList()), singletonList(attr1));
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findOneByIdUserPermissionAllowed.
@WithMockUser(username = USERNAME)
@Test
public void findOneByIdUserPermissionAllowed() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String attr0Name = "entity0attr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
Object id = mock(Object.class);
when(delegateRepository.findOneById(id)).thenReturn(attr0);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.findOneById(id), attr0);
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findAllIdsFetchUser.
@WithMockUser(username = USERNAME)
@Test
public void findAllIdsFetchUser() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String entityType1Name = "entity1";
EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
String attr0Name = "entity0attr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
String attr1Name = "entity1attr0";
Attribute attr1 = when(mock(Attribute.class).getName()).thenReturn(attr1Name).getMock();
when(attr1.getEntity()).thenReturn(entityType1);
Stream<Object> ids = Stream.of(mock(Object.class), mock(Object.class));
Fetch fetch = mock(Fetch.class);
when(delegateRepository.findAll(ids, fetch)).thenReturn(Stream.of(attr0, attr1));
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(false);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.findAll(ids, fetch).collect(toList()), singletonList(attr1));
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class HasPermissionDirectiveTest method executeWithPermission.
@Test
public void executeWithPermission() throws TemplateException, IOException {
when(permissionService.hasPermission(new EntityTypeIdentity("entity"), EntityTypePermission.COUNT)).thenReturn(true);
Map<String, Object> params = Maps.newHashMap();
params.put("entityTypeId", "entity");
params.put("permission", "COUNT");
directive.execute(new Environment(fakeTemplate, null, envWriter), params, new TemplateModel[0], out -> out.write("PERMISSION"));
assertEquals(envWriter.toString(), "PERMISSION");
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class PermissionSystemServiceImplTest method giveUserEntityPermissions.
@Test
@WithMockUser(username = "user")
public void giveUserEntityPermissions() {
String entityTypeId = "entityTypeId";
EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
MutableAcl acl = mock(MutableAcl.class);
when(mutableAclService.readAclById(new EntityTypeIdentity(entityTypeId))).thenReturn(acl);
permissionSystemServiceImpl.giveUserWriteMetaPermissions(entityType);
verify(mutableAclService).updateAcl(acl);
verify(acl).insertAce(0, new CumulativePermission().set(EntityTypePermission.WRITEMETA).set(EntityTypePermission.WRITE).set(EntityTypePermission.READ).set(EntityTypePermission.COUNT), new PrincipalSid("user"), true);
}
Aggregations