use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class EntityTypeRepositorySecurityDecorator method updateAcl.
@Override
public void updateAcl(EntityType entityType) {
MutableAcl acl = (MutableAcl) mutableAclService.readAclById(new EntityTypeIdentity(entityType.getId()));
Package pack = entityType.getPackage();
if (pack != null) {
ObjectIdentity objectIdentity = new PackageIdentity(pack);
Acl parentAcl = mutableAclService.readAclById(objectIdentity);
if (!parentAcl.equals(acl.getParentAcl())) {
acl.setParent(parentAcl);
mutableAclService.updateAcl(acl);
}
}
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findAllQueryUser.
@WithMockUser(username = USERNAME)
@Test
public void findAllQueryUser() 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);
Query<Attribute> q = new QueryImpl<>();
@SuppressWarnings("unchecked") ArgumentCaptor<Query<Attribute>> queryCaptor = forClass(Query.class);
when(delegateRepository.findAll(queryCaptor.capture())).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(q).collect(toList()), singletonList(attr1));
assertEquals(queryCaptor.getValue().getOffset(), 0);
assertEquals(queryCaptor.getValue().getPageSize(), Integer.MAX_VALUE);
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findOneByIdUserPermissionAllowedAttrInCompoundWithOneAttr.
@WithMockUser(username = USERNAME)
@Test
public void findOneByIdUserPermissionAllowedAttrInCompoundWithOneAttr() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String attr0Name = "entity0attrCompoundattr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
String attrCompoundName = "entity0attrCompound";
Attribute attrCompound = when(mock(Attribute.class).getName()).thenReturn(attrCompoundName).getMock();
when(attrCompound.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 findOneQueryUserPermissionAllowed.
@WithMockUser(username = USERNAME)
@Test
public void findOneQueryUserPermissionAllowed() 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);
Query<Attribute> q = new QueryImpl<>();
when(delegateRepository.findOne(q)).thenReturn(attr0);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.findOne(q), attr0);
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findOneByIdFetchUserPermissionDenied.
@WithMockUser(username = USERNAME)
@Test
public void findOneByIdFetchUserPermissionDenied() 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);
Fetch fetch = mock(Fetch.class);
when(delegateRepository.findOneById(id, fetch)).thenReturn(attr0);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(false);
assertNull(repo.findOneById(id, fetch));
}
Aggregations