use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class IdmRoleControllerRestTest method testFindCanBeRequestedRoles.
@Test
public void testFindCanBeRequestedRoles() throws Exception {
String description = getHelper().createName();
IdmRoleDto role = prepareDto();
role.setDescription(description);
role.setCanBeRequested(true);
IdmRoleDto roleOne = createDto(role);
role = prepareDto();
role.setDescription(description);
role.setCanBeRequested(false);
// other
IdmRoleDto roleTwo = createDto(role);
//
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto assignedRole = getHelper().createRole();
//
getHelper().createIdentityRole(identity, assignedRole);
//
// create authorization policy - assign to role
getHelper().createAuthorizationPolicy(assignedRole.getId(), CoreGroupPermission.ROLE, IdmRole.class, RoleCanBeRequestedEvaluator.class, RoleBasePermission.CANBEREQUESTED);
//
IdmRoleFilter filter = new IdmRoleFilter();
filter.setText(description);
List<IdmRoleDto> roles = find("can-be-requested", filter, getAuthentication(identity.getUsername()));
//
Assert.assertFalse(roles.isEmpty());
Assert.assertTrue(roles.stream().allMatch(r -> r.isCanBeRequested()));
Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleOne.getId())));
Assert.assertFalse(roles.stream().anyMatch(r -> r.getId().equals(roleTwo.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class IdmRoleControllerRestTest method testFindByRoleCatalogueRecursivelly.
@Test
public void testFindByRoleCatalogueRecursivelly() {
// prepare role catalogue
IdmRoleCatalogueDto roleCatalogue = getHelper().createRoleCatalogue();
IdmRoleCatalogueDto roleCatalogueOne = getHelper().createRoleCatalogue(null, roleCatalogue.getId());
IdmRoleCatalogueDto roleCatalogueTwo = getHelper().createRoleCatalogue(null, roleCatalogue.getId());
IdmRoleCatalogueDto roleCatalogueOneSub = getHelper().createRoleCatalogue(null, roleCatalogueOne.getId());
IdmRoleCatalogueDto roleCatalogueOneSubSub = getHelper().createRoleCatalogue(null, roleCatalogueOneSub.getId());
IdmRoleCatalogueDto roleCatalogueOther = getHelper().createRoleCatalogue();
// create roles
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
IdmRoleDto roleThree = getHelper().createRole();
// assign role into catalogue
getHelper().createRoleCatalogueRole(roleOne, roleCatalogueOne);
getHelper().createRoleCatalogueRole(roleTwo, roleCatalogueTwo);
getHelper().createRoleCatalogueRole(roleThree, roleCatalogueOneSubSub);
//
// test
IdmRoleFilter filter = new IdmRoleFilter();
filter.setRoleCatalogueId(roleCatalogueOne.getId());
List<IdmRoleDto> roles = find(filter);
Assert.assertEquals(2, roles.size());
Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleOne.getId())));
Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleThree.getId())));
//
filter.setRoleCatalogueId(roleCatalogueOther.getId());
roles = find(filter);
Assert.assertTrue(roles.isEmpty());
//
filter.setRoleCatalogueId(roleCatalogueTwo.getId());
roles = find(filter);
Assert.assertEquals(1, roles.size());
Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleTwo.getId())));
//
filter.setRoleCatalogueId(roleCatalogue.getId());
roles = find(filter);
Assert.assertEquals(3, roles.size());
Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleOne.getId())));
Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleTwo.getId())));
Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleThree.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleWorkflowAdSyncTest method n5_testSyncWithWfSituationUnlinked.
@Test
public void n5_testSyncWithWfSituationUnlinked() {
SysSystemDto system = initData();
IdmRoleFilter roleFilter = new IdmRoleFilter();
roleFilter.setText(ROLE_NAME);
List<IdmRoleDto> roles = roleService.find(roleFilter, null).getContent();
Assert.assertEquals(0, roles.size());
IdmRoleDto role = new IdmRoleDto();
role.setCode(ROLE_NAME);
roleService.save(role);
Assert.assertNotNull(system);
SysSyncRoleConfigDto config = doCreateSyncConfig(system);
config.setLinkedActionWfKey(wfExampleKey);
config.setMissingAccountActionWfKey(wfExampleKey);
config.setMissingEntityActionWfKey(wfExampleKey);
config.setUnlinkedActionWfKey(wfExampleKey);
config = (SysSyncRoleConfigDto) syncConfigService.save(config);
// Start sync
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.UNLINKED, 1, OperationResultType.WF);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
roles = roleService.find(roleFilter, null).getContent();
Assert.assertEquals(1, roles.size());
role = roles.get(0);
List<IdmFormValueDto> dnValues = formService.getValues(role, ATTRIBUTE_DN);
Assert.assertEquals(1, dnValues.size());
Assert.assertEquals(ATTRIBUTE_DN_VALUE, dnValues.get(0).getValue());
IdmRoleCatalogueDto catalogueFirst = getCatalogueByCode(CATALOGUE_CODE_FIRST);
IdmRoleCatalogueDto catalogueSecond = getCatalogueByCode(CATALOGUE_CODE_SECOND);
Assert.assertNotNull(catalogueFirst);
Assert.assertNotNull(catalogueSecond);
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleWorkflowAdSyncTest method n92_testSyncWithWfSituationLinkedResolveMember.
@Test
public void n92_testSyncWithWfSituationLinkedResolveMember() {
createRolesInSystem();
final String newDN = "CN=" + ROLE_NAME + ",OU=Flat,OU=Pardubice,DC=bcvsolutions,DC=eu";
this.getBean().initIdentityData(ROLE_NAME, newDN);
String valueOfMemberAtt = "" + System.currentTimeMillis();
String nameOfEav = "externalIdentifier";
configurationService.setValue("idm.pub.acc.syncRole.identity.eav.externalIdentifier.code", nameOfEav);
configurationService.setValue("idm.pub.acc.syncRole.roles.attributeNameOfMembership", helper.getSchemaColumnName(ATTRIBUTE_MEMBER));
configurationService.setBooleanValue("idm.pub.acc.syncRole.update.resolveMembership", true);
IdmIdentityDto identity = this.getHelper().createIdentity();
IdmFormAttributeFilter attributeFilter = new IdmFormAttributeFilter();
attributeFilter.setCode(nameOfEav);
IdmFormAttributeDto formAttribute = formAttributeService.find(attributeFilter, null).getContent().stream().findFirst().orElse(null);
Assert.assertNotNull(formAttribute);
helper.setEavValue(identity, formAttribute, IdmIdentity.class, valueOfMemberAtt, PersistentType.SHORTTEXT);
this.getBean().deleteAllResourceData();
this.getBean().addRoleToResource(ROLE_NAME, ATTRIBUTE_DN, valueOfMemberAtt);
IdmRoleFilter roleFilter = new IdmRoleFilter();
roleFilter.setText(ROLE_NAME);
List<IdmRoleDto> roles = roleService.find(roleFilter, null).getContent();
// role is in already synced ind idm
Assert.assertEquals(1, roles.size());
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> content = identityRoleService.find(filter, null).getContent();
// identity does not have assigned this role
Assert.assertEquals(0, content.size());
SysSystemDto systemDto = systemService.getByCode(SYSTEM_NAME);
Assert.assertNotNull(systemDto);
SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
syncFilter.setSystemId(systemDto.getId());
List<AbstractSysSyncConfigDto> syncConfig = syncConfigService.find(syncFilter, null).getContent();
// find synchronization config to start sync
Assert.assertEquals(1, syncConfig.size());
// Start sync
helper.startSynchronization(syncConfig.get(0));
SysSyncLogDto log = checkSyncLog(syncConfig.get(0), SynchronizationActionType.LINKED, 1, OperationResultType.WF);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
roles = roleService.find(roleFilter, null).getContent();
Assert.assertEquals(1, roles.size());
content = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(1, content.size());
identityRoleService.delete(content.get(0));
// Delete log
syncLogService.delete(log);
configurationService.deleteValue("idm.pub.acc.syncRole.provisioningOfIdentities.system.code");
configurationService.deleteValue("idm.pub.acc.syncRole.system.mapping.attributeMemberOf");
configurationService.setBooleanValue("idm.pub.acc.syncRole.update.resolveMembership", false);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmFormDefinitionService method deleteInternal.
@Override
@Transactional
public void deleteInternal(IdmFormDefinitionDto dto) {
Assert.notNull(dto, "Form definition is required for delete.");
UUID id = dto.getId();
Assert.notNull(id, "Form definition identifier is required for delete.");
//
// delete all attributes in definition
IdmFormAttributeFilter filter = new IdmFormAttributeFilter();
filter.setDefinitionId(id);
formAttributeService.find(filter, null).forEach(formAttribute -> {
formAttributeService.delete(formAttribute);
});
//
IdmRoleFilter roleFilter = new IdmRoleFilter();
roleFilter.setAttributeFormDefinitionId(id);
List<IdmRoleDto> roles = roleService.find(roleFilter, PageRequest.of(0, 1)).getContent();
if (roles.size() > 0) {
throw new ResultCodeException(CoreResultCode.FORM_DEFINITION_DELETE_FAILED_ROLE, ImmutableMap.of("definition", dto.getCode(), "role", roles.get(0).getCode()));
}
super.deleteInternal(dto);
}
Aggregations