Search in sources :

Example 36 with IdmRoleFilter

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())));
}
Also used : IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) Collectors(java.util.stream.Collectors) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) RoleBasePermission(eu.bcvsolutions.idm.core.security.api.domain.RoleBasePermission) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) RoleCanBeRequestedEvaluator(eu.bcvsolutions.idm.core.security.evaluator.role.RoleCanBeRequestedEvaluator) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 37 with IdmRoleFilter

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())));
}
Also used : IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) Collectors(java.util.stream.Collectors) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) RoleBasePermission(eu.bcvsolutions.idm.core.security.api.domain.RoleBasePermission) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) RoleCanBeRequestedEvaluator(eu.bcvsolutions.idm.core.security.evaluator.role.RoleCanBeRequestedEvaluator) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 38 with IdmRoleFilter

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);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSyncRoleConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncRoleConfigDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 39 with IdmRoleFilter

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);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 40 with IdmRoleFilter

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);
}
Also used : IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter)54 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)46 Test (org.junit.Test)41 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)22 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)17 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)17 IdmRoleCatalogueDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto)16 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)14 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)14 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)10 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)9 List (java.util.List)9 Assert (org.junit.Assert)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 SysSyncRoleConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncRoleConfigDto)8 UUID (java.util.UUID)8 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)7 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)7 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)7 TestHelper (eu.bcvsolutions.idm.test.api.TestHelper)7