use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto in project CzechIdMng by bcvsolutions.
the class DefaultCodeListManager method create.
@Override
@Transactional
public IdmCodeListDto create(String code, BasePermission... permission) {
IdmCodeListDto codeList = new IdmCodeListDto();
codeList.setCode(code);
codeList.setName(code);
//
return save(codeList, permission);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto in project CzechIdMng by bcvsolutions.
the class DefaultCodeListManager method get.
@Override
public IdmCodeListDto get(Serializable codeListIdentifier, BasePermission... permission) {
Assert.notNull(codeListIdentifier, "CodeList identifier is required.");
//
IdmCodeListDto codeList = (IdmCodeListDto) lookupService.lookupDto(IdmCodeListDto.class, codeListIdentifier);
if (codeList == null) {
return null;
}
if (ObjectUtils.isEmpty(PermissionUtils.trimNull(permission))) {
return codeList;
}
//
return codeListService.get(codeList, permission);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto 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.IdmCodeListDto in project CzechIdMng by bcvsolutions.
the class FormAttributteByCodeListEvaluatorIntegrationTest method testPermissions.
@Test
public void testPermissions() {
// create codelist and items
IdmIdentityDto identity = getHelper().createIdentity();
IdmCodeListDto codeListOne = codeListManager.create(getHelper().createName());
IdmFormAttributeDto attributeOne = new IdmFormAttributeDto();
attributeOne.setCode(getHelper().createName());
attributeOne.setName(attributeOne.getCode());
attributeOne.setPersistentType(PersistentType.SHORTTEXT);
attributeOne.setFormDefinition(codeListOne.getFormDefinition().getId());
attributeOne = formService.saveAttribute(attributeOne);
IdmCodeListDto codeListTwo = codeListManager.create(getHelper().createName());
IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto();
attributeTwo.setCode(getHelper().createName());
attributeTwo.setName(attributeTwo.getCode());
attributeTwo.setPersistentType(PersistentType.SHORTTEXT);
attributeTwo.setFormDefinition(codeListTwo.getFormDefinition().getId());
formService.saveAttribute(attributeTwo);
//
List<IdmFormAttributeDto> attributes = null;
IdmRoleDto roleOne = getHelper().createRole();
//
getHelper().createIdentityRole(identity, roleOne);
// check - read without policy
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
attributes = formAttributeService.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(attributes.isEmpty());
} finally {
logout();
}
//
// without login
attributes = formAttributeService.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(attributes.isEmpty());
//
// create authorization policies - assign to role
getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.READ);
getHelper().createAuthorizationPolicy(roleOne.getId(), CoreGroupPermission.FORMATTRIBUTE, IdmFormAttribute.class, FormAttributteByCodeListEvaluator.class);
//
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
// without update permission
attributes = formAttributeService.find(null, IdmBasePermission.UPDATE).getContent();
Assert.assertTrue(attributes.isEmpty());
//
// evaluate access
attributes = formAttributeService.find(null, IdmBasePermission.READ).getContent();
Assert.assertEquals(1, attributes.size());
Assert.assertEquals(attributeOne.getId(), attributes.get(0).getId());
//
Set<String> permissions = formAttributeService.getPermissions(attributeOne);
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 = formAttributeService.getPermissions(attributeOne);
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.IdmCodeListDto 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();
}
}
Aggregations