use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto in project CzechIdMng by bcvsolutions.
the class CodeListItemDeleteProcessor method process.
@Override
public EventResult<IdmCodeListItemDto> process(EntityEvent<IdmCodeListItemDto> event) {
IdmCodeListItemDto item = event.getContent();
//
service.deleteInternal(item);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto in project CzechIdMng by bcvsolutions.
the class DefaultCodeListManager method createItem.
@Override
@Transactional
public IdmCodeListItemDto createItem(Serializable codeListIdentifier, String code, String name, BasePermission... permission) {
Assert.notNull(codeListIdentifier, "CodeList identifier is required.");
Assert.notNull(code, "Item code is required.");
Assert.notNull(name, "Item name is required.");
//
IdmCodeListDto codeList = get(codeListIdentifier);
Assert.notNull(codeList, "CodeList is required.");
//
IdmCodeListItemDto item = new IdmCodeListItemDto();
item.setCodeList(codeList.getId());
item.setCode(code);
item.setName(name);
//
return saveItem(item, permission);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto in project CzechIdMng by bcvsolutions.
the class CodeListItemByCodeEvaluatorIntegrationTest method testPermissions.
@Test
public void testPermissions() {
// create codelist and items
IdmIdentityDto identity = getHelper().createIdentity();
IdmCodeListDto codeListOne = codeListManager.create(getHelper().createName());
IdmCodeListItemDto itemOne = codeListManager.createItem(codeListOne.getId(), getHelper().createName(), getHelper().createName());
IdmCodeListItemDto itemTwo = codeListManager.createItem(codeListOne.getId(), getHelper().createName(), getHelper().createName());
IdmCodeListDto codeListTwo = codeListManager.create(getHelper().createName());
// other
codeListManager.createItem(codeListTwo.getId(), getHelper().createName(), getHelper().createName());
//
List<IdmCodeListItemDto> items = null;
IdmRoleDto roleOne = getHelper().createRole();
//
getHelper().createIdentityRole(identity, roleOne);
// check - read without policy
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
Assert.assertTrue(items.isEmpty());
} finally {
logout();
}
//
// without login
items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
Assert.assertTrue(items.isEmpty());
//
// create authorization policies - assign to role
getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.AUTOCOMPLETE);
ConfigurationMap properties = new ConfigurationMap();
properties.put(CodeListItemByCodeEvaluator.PARAMETER_CODELIST, codeListOne.getId());
properties.put(CodeListItemByCodeEvaluator.PARAMETER_ITEM_CODES, itemOne.getCode());
getHelper().createAuthorizationPolicy(roleOne.getId(), CoreGroupPermission.CODELISTITEM, IdmCodeListItem.class, CodeListItemByCodeEvaluator.class, properties, IdmBasePermission.AUTOCOMPLETE);
//
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
// without read permission
items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(items.isEmpty());
//
// evaluate access
items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
Assert.assertEquals(1, items.size());
Assert.assertEquals(itemOne.getId(), items.get(0).getId());
//
Set<String> permissions = codeListItemService.getPermissions(itemOne);
Assert.assertEquals(1, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.AUTOCOMPLETE.name())));
} finally {
logout();
}
// all items by default
properties = new ConfigurationMap();
properties.put(CodeListItemByCodeEvaluator.PARAMETER_CODELIST, codeListOne.getId());
getHelper().createAuthorizationPolicy(roleOne.getId(), CoreGroupPermission.CODELISTITEM, IdmCodeListItem.class, CodeListItemByCodeEvaluator.class, properties, IdmBasePermission.AUTOCOMPLETE);
//
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
Assert.assertEquals(2, items.size());
Assert.assertTrue(items.stream().anyMatch(i -> i.getId().equals(itemOne.getId())));
Assert.assertTrue(items.stream().anyMatch(i -> i.getId().equals(itemTwo.getId())));
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto in project CzechIdMng by bcvsolutions.
the class CodeListItemByCodeListEvaluatorIntegrationTest method testPermissions.
@Test
public void testPermissions() {
// create codelist and items
IdmIdentityDto identity = getHelper().createIdentity();
IdmCodeListDto codeListOne = codeListManager.create(getHelper().createName());
IdmCodeListItemDto itemOne = codeListManager.createItem(codeListOne.getId(), getHelper().createName(), getHelper().createName());
IdmCodeListDto codeListTwo = codeListManager.create(getHelper().createName());
// other
codeListManager.createItem(codeListTwo.getId(), getHelper().createName(), getHelper().createName());
//
List<IdmCodeListItemDto> items = null;
IdmRoleDto roleOne = getHelper().createRole();
//
getHelper().createIdentityRole(identity, roleOne);
// check - read without policy
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(items.isEmpty());
} finally {
logout();
}
//
// without login
items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(items.isEmpty());
//
// create authorization policies - assign to role
getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.READ);
getHelper().createAuthorizationPolicy(roleOne.getId(), CoreGroupPermission.CODELISTITEM, IdmCodeListItem.class, CodeListItemByCodeListEvaluator.class);
//
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
// without update permission
items = codeListItemService.find(null, IdmBasePermission.UPDATE).getContent();
Assert.assertTrue(items.isEmpty());
//
// evaluate access
items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
Assert.assertEquals(1, items.size());
Assert.assertEquals(itemOne.getId(), items.get(0).getId());
//
Set<String> permissions = codeListItemService.getPermissions(itemOne);
Assert.assertEquals(1, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
} finally {
logout();
}
//
getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.UPDATE);
//
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
Set<String> permissions = codeListItemService.getPermissions(itemOne);
Assert.assertEquals(2, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.UPDATE.name())));
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto in project CzechIdMng by bcvsolutions.
the class DefaultCodeListManagerIntegrationTest method testReferentialIntegrity.
@Test
public void testReferentialIntegrity() {
IdmCodeListDto codeList = manager.create(getHelper().createName());
IdmCodeListItemDto item = manager.createItem(codeList, getHelper().createName(), getHelper().createName());
//
Assert.assertNotNull(manager.get(codeList));
Assert.assertNotNull(manager.getItem(codeList, item.getCode()));
Assert.assertNotNull(formService.getDefinition(codeList.getFormDefinition().getId()));
//
manager.delete(codeList);
//
Assert.assertNull(manager.get(codeList));
Assert.assertNull(manager.getItem(codeList, item.getCode()));
Assert.assertNull(formService.getDefinition(codeList.getFormDefinition().getId()));
}
Aggregations