Search in sources :

Example 1 with IdmContractGuaranteeFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.

the class ContractGuaranteeSaveAndDeleteProcessorTest method testDeleteGuaranteeOfContractWithSlice.

@Test
public void testDeleteGuaranteeOfContractWithSlice() {
    IdmIdentityDto sliceGuarantee = getHelper().createIdentity();
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmContractSliceDto slice = getHelper().createContractSlice(identity, null, LocalDate.now().minusDays(1), null, null);
    UUID contractId = slice.getParentContract();
    getHelper().createContractSliceGuarantee(slice.getId(), sliceGuarantee.getId());
    IdmContractSliceGuaranteeFilter sliceGuaranteefilter = new IdmContractSliceGuaranteeFilter();
    sliceGuaranteefilter.setGuaranteeId(sliceGuarantee.getId());
    List<IdmContractSliceGuaranteeDto> sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
    Assert.assertEquals(1, sliceGuarantees.size());
    IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
    guaranteeFilter.setIdentityContractId(contractId);
    List<IdmContractGuaranteeDto> contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
    Assert.assertEquals(1, contractGuarantees.size());
    IdmIdentityDto sliceGuaranteeIdent = DtoUtils.getEmbedded(sliceGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
    IdmIdentityDto contractGuaranteeIdent = DtoUtils.getEmbedded(contractGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
    Assert.assertEquals(sliceGuaranteeIdent.getId(), contractGuaranteeIdent.getId());
    try {
        contractGuaranteeService.delete(contractGuarantees.get(0));
        fail("Contract guarantee can't be deleted directly when slice is applied");
    } catch (ResultCodeException ex) {
        Assert.assertTrue(CoreResultCode.CONTRACT_IS_CONTROLLED_GUARANTEE_CANNOT_BE_DELETED.toString().equals(ex.getError().getErrors().get(0).getStatusEnum()));
    }
    // guarantee can be still deleted via contract slice operation
    contractSliceGuaranteeService.delete(sliceGuarantees.get(0));
    sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
    Assert.assertEquals(0, sliceGuarantees.size());
    contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
    Assert.assertEquals(0, contractGuarantees.size());
}
Also used : IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with IdmContractGuaranteeFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.

the class IdentityRemoveContractGuaranteeBulkActionTest method isContractGuarantee.

/**
 * Tests if there are all identities contract guarantees
 * If some of them are not contract guarantees, they are returned
 * Empty returned List means that there are all identities contract guarantees
 *
 * @param contract
 * @param guarantees
 * @return
 */
private List<IdmIdentityDto> isContractGuarantee(IdmIdentityContractDto contract, List<IdmIdentityDto> guarantees) {
    IdmContractGuaranteeFilter filt = new IdmContractGuaranteeFilter();
    filt.setIdentityContractId(contract.getId());
    Set<UUID> cgUUIDs = contractGuaranteeService.find(filt, null).getContent().stream().map(IdmContractGuaranteeDto::getGuarantee).collect(Collectors.toSet());
    return guarantees.stream().filter(ident -> !cgUUIDs.contains(ident.getId())).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) HashMap(java.util.HashMap) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmContractGuarantee(eu.bcvsolutions.idm.core.model.entity.IdmContractGuarantee) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Map(java.util.Map) After(org.junit.After) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) Collectors(java.util.stream.Collectors) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) UUID(java.util.UUID) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)

Example 3 with IdmContractGuaranteeFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.

the class IdentityChangeContractGuaranteeBulkActionTest method getGuaranteesForContract.

/**
 * Gets all contractGuarantees for contract
 * @param contract
 * @return
 */
private List<IdmContractGuaranteeDto> getGuaranteesForContract(UUID contract) {
    IdmContractGuaranteeFilter filt = new IdmContractGuaranteeFilter();
    filt.setIdentityContractId(contract);
    return contractGuaranteeService.find(filt, null).getContent();
}
Also used : IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)

Example 4 with IdmContractGuaranteeFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.

the class IdentityDeleteProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    IdmIdentityDto identity = event.getContent();
    UUID identityId = identity.getId();
    Assert.notNull(identityId, "Identity ID is required!");
    boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
    // 
    // delete contract slices
    IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
    sliceFilter.setIdentity(identityId);
    contractSliceService.find(sliceFilter, null).forEach(guarantee -> {
        contractSliceService.delete(guarantee);
    });
    // delete contract slice guarantees
    IdmContractSliceGuaranteeFilter sliceGuaranteeFilter = new IdmContractSliceGuaranteeFilter();
    sliceGuaranteeFilter.setGuaranteeId(identityId);
    contractSliceGuaranteeService.find(sliceGuaranteeFilter, null).forEach(guarantee -> {
        contractSliceGuaranteeService.delete(guarantee);
    });
    // 
    // contracts
    identityContractService.findAllByIdentity(identityId).forEach(identityContract -> {
        // when identity is deleted, then HR processes has to be skipped (prevent to update deleted identity, when contract is removed)
        Map<String, Serializable> properties = new HashMap<>();
        properties.put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
        // propagate force attribute
        properties.put(PROPERTY_FORCE_DELETE, forceDelete);
        // prepare event
        IdentityContractEvent contractEvent = new IdentityContractEvent(IdentityContractEventType.DELETE, identityContract, properties);
        contractEvent.setPriority(PriorityType.HIGH);
        // 
        identityContractService.publish(contractEvent);
    });
    // delete contract guarantees
    IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
    filter.setGuaranteeId(identityId);
    contractGuaranteeService.find(filter, null).forEach(guarantee -> {
        contractGuaranteeService.delete(guarantee);
    });
    // remove role guarantee
    IdmRoleGuaranteeFilter roleGuaranteeFilter = new IdmRoleGuaranteeFilter();
    roleGuaranteeFilter.setGuarantee(identityId);
    roleGuaranteeService.find(roleGuaranteeFilter, null).forEach(roleGuarantee -> {
        roleGuaranteeService.delete(roleGuarantee);
    });
    // remove password
    passwordProcessor.deletePassword(identity);
    // delete password history for identity
    passwordHistoryService.deleteAllByIdentity(identityId);
    // disable related tokens - tokens has to be disabled to prevent their usage (when tokens are deleted, then token is recreated)
    tokenManager.disableTokens(identity);
    // 
    // delete all identity's profiles
    IdmProfileFilter profileFilter = new IdmProfileFilter();
    profileFilter.setIdentityId(identityId);
    profileService.find(profileFilter, null).forEach(profile -> {
        profileService.delete(profile);
    });
    // remove all IdentityRoleValidRequest for this identity
    List<IdmIdentityRoleValidRequestDto> validRequests = identityRoleValidRequestService.findAllValidRequestForIdentityId(identityId);
    identityRoleValidRequestService.deleteAll(validRequests);
    // 
    // delete all identity's delegations - delegate
    IdmDelegationDefinitionFilter delegationFilter = new IdmDelegationDefinitionFilter();
    delegationFilter.setDelegateId(identityId);
    delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
        delegationDefinitionService.delete(delegation);
    });
    // 
    // delete all identity's delegations - delegator
    delegationFilter = new IdmDelegationDefinitionFilter();
    delegationFilter.setDelegatorId(identityId);
    delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
        delegationDefinitionService.delete(delegation);
    });
    // deletes identity
    if (forceDelete) {
        LOG.debug("Identity [{}] should be deleted by caller after all asynchronus processes are completed.", identityId);
        // 
        // dirty flag only - will be processed after asynchronous events ends
        IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
        stateDeleted.setEvent(event.getId());
        stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
        entityStateManager.saveState(identity, stateDeleted);
        // 
        // set disabled (automatically)
        identity.setState(IdentityState.DISABLED);
        service.saveInternal(identity);
    } else {
        // delete all role requests where is this identity applicant
        IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
        roleRequestFilter.setApplicantId(identityId);
        roleRequestService.find(roleRequestFilter, null).forEach(request -> {
            roleRequestService.delete(request);
        });
        // 
        service.deleteInternal(identity);
    }
    return new DefaultEventResult<>(event, this);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) Serializable(java.io.Serializable) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) IdmProfileFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmDelegationDefinitionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmDelegationDefinitionFilter) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmIdentityRoleValidRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleValidRequestDto)

Example 5 with IdmContractGuaranteeFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityServiceIntegrationTest method testReferentialIntegrity.

@Test
@Transactional
public void testReferentialIntegrity() {
    IdmIdentityDto identity = getHelper().createIdentity();
    String username = identity.getUsername();
    // eav
    IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
    IdmFormValueDto value1 = new IdmFormValueDto(formDefinition.getMappedAttributeByCode(InitDemoDataProcessor.FORM_ATTRIBUTE_PASSWORD));
    value1.setValue("one");
    formService.saveValues(identity.getId(), IdmIdentity.class, formDefinition, Lists.newArrayList(value1));
    // role with guarantee
    IdmRoleDto role = getHelper().createRole();
    getHelper().createRoleGuarantee(role, identity);
    // contract
    IdmIdentityContractDto contract = getHelper().createContract(identity);
    // contract guarantee
    IdmIdentityContractDto contract2 = getHelper().createContract(identityService.getByUsername(InitTestDataProcessor.TEST_USER_1));
    contractGuaranteeService.save(new IdmContractGuaranteeDto(contract2.getId(), identity.getId()));
    // assigned role
    getHelper().createIdentityRole(contract, role);
    IdmIdentityRoleFilter identityRolefilter = new IdmIdentityRoleFilter();
    identityRolefilter.setIdentityId(identity.getId());
    // profile
    getHelper().createProfile(identity);
    // token
    IdmTokenDto token = new IdmTokenDto();
    token.setToken("token");
    token.setTokenType("test");
    token = tokenManager.saveToken(identity, token);
    // 
    Assert.assertNotNull(tokenManager.getToken(token.getId()));
    Assert.assertNotNull(profileService.findOneByIdentity(identity.getId()));
    Assert.assertNotNull(identityService.getByUsername(username));
    Assert.assertNotNull(passwordService.findOneByIdentity(identity.getId()));
    Assert.assertEquals(1, formService.getValues(identity).size());
    Assert.assertEquals(identity.getId(), roleGuaranteeService.findByRole(role.getId(), null).getContent().get(0).getGuarantee());
    Assert.assertEquals(1, identityRoleService.find(identityRolefilter, null).getTotalElements());
    // + default contract is created
    Assert.assertEquals(2, identityContractService.findAllByIdentity(identity.getId()).size());
    IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
    filter.setIdentityContractId(contract2.getId());
    List<IdmContractGuaranteeDto> guarantees = contractGuaranteeService.find(filter, null).getContent();
    Assert.assertEquals(1, guarantees.size());
    Assert.assertEquals(identity.getId(), guarantees.get(0).getGuarantee());
    // 
    identityService.delete(identity);
    role = roleService.get(role.getId());
    // 
    Assert.assertEquals(0L, roleGuaranteeService.findByRole(role.getId(), null).getTotalElements());
    Assert.assertNull(identityService.getByUsername(username));
    Assert.assertNull(passwordService.findOneByIdentity(identity.getId()));
    Assert.assertEquals(0, identityContractService.findAllByIdentity(identity.getId()).size());
    Assert.assertEquals(0, identityRoleService.find(identityRolefilter, null).getTotalElements());
    Assert.assertEquals(0, contractGuaranteeService.find(filter, null).getTotalElements());
    Assert.assertNull(profileService.findOneByIdentity(identity.getId()));
    Assert.assertTrue(tokenManager.getToken(token.getId()).isDisabled());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmContractGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)27 IdmContractGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto)20 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)20 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)18 Test (org.junit.Test)15 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)12 UUID (java.util.UUID)12 IdmContractGuaranteeService (eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService)8 List (java.util.List)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 HashMap (java.util.HashMap)7 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)6 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)6 Map (java.util.Map)6 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)5 Collectors (java.util.stream.Collectors)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)4 IdmContractPositionFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter)4 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)4