Search in sources :

Example 46 with IdmEntityStateDto

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

the class DefaultUniformPasswordManager method generateUniformPassword.

@Override
@Transactional
public GuardedString generateUniformPassword(UUID entityIdentifier, Class<? extends AbstractDto> entityType, UUID transactionId) {
    Assert.notNull(transactionId, "Transaction cannot be null!");
    Assert.notNull(entityIdentifier, "Entity identifier cannot be null!");
    Assert.notNull(entityType, "Entity type cannot be null!");
    IdmEntityStateDto entityStateDto = this.getEntityState(entityIdentifier, entityType, transactionId);
    if (entityStateDto != null) {
        GuardedString password = getPassword(entityStateDto);
        if (password == null || password.getValue().length == 0) {
            // TODO: how to generate password for all system policies.
            password = new GuardedString(passwordPolicyService.generatePasswordByDefault());
            confidentialStorage.saveGuardedString(entityStateDto, UNIFORM_PASSWORD_KEY, password);
        }
        // The uniform password was used, we need to mark it.
        Map<String, Object> parameters = entityStateDto.getResult().getModel().getParameters();
        HashMap<String, Object> newParameters = Maps.newHashMap(parameters);
        newParameters.put(PASSWORD_USED, Boolean.TRUE);
        entityStateDto.getResult().setModel(new DefaultResultModel(CoreResultCode.IDENTITY_UNIFORM_PASSWORD, newParameters));
        entityStateManager.saveState(null, entityStateDto);
        return password;
    }
    return null;
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with IdmEntityStateDto

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

the class IdentityContractDeleteProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    IdmIdentityContractDto contract = event.getContent();
    UUID contractId = contract.getId();
    Assert.notNull(contractId, "Contract must have a ID!");
    boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
    // 
    // check contract can be deleted - cannot be deleted, when is controlled by slices
    IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
    sliceFilter.setParentContract(contractId);
    if (contractSliceService.find(sliceFilter, null).getTotalElements() > 0) {
        // Cannot be enforced => contract cannot be deleted at all.
        throw new ResultCodeException(CoreResultCode.CONTRACT_IS_CONTROLLED_CANNOT_BE_DELETED, ImmutableMap.of("contractId", contractId));
    }
    // 
    // Find all concepts and remove relation on contract
    IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
    conceptRequestFilter.setIdentityContractId(contractId);
    conceptRequestService.find(conceptRequestFilter, null).getContent().forEach(concept -> {
        String message = null;
        if (concept.getState().isTerminatedState()) {
            message = MessageFormat.format("IdentityContract [{0}] (requested in concept [{1}]) was deleted (not from this role request)!", contractId, concept.getId());
        } else {
            message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested IdentityContract [{1}] was deleted (not from this role request)!", concept.getId(), contractId);
            // Cancel concept and WF
            concept = conceptRequestService.cancel(concept);
        }
        IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
        roleRequestService.addToLog(request, message);
        conceptRequestService.addToLog(concept, message);
        roleRequestService.save(request);
        conceptRequestService.save(concept);
    });
    // 
    // delete referenced roles
    List<IdmConceptRoleRequestDto> concepts = new ArrayList<>();
    identityRoleService.findAllByContract(contractId).forEach(identityRole -> {
        // but automatic roles has to be removed in the same request.
        if (identityRole.getDirectRole() == null) {
            IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
            conceptRoleRequest.setIdentityRole(identityRole.getId());
            conceptRoleRequest.setRole(identityRole.getRole());
            conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
            // ignore not found
            conceptRoleRequest.setIdentityContract(contractId);
            // 
            concepts.add(conceptRoleRequest);
        }
    });
    if (forceDelete) {
        // ~ async with force
        IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
        roleRequest.setApplicant(contract.getIdentity());
        roleRequest.setConceptRoles(concepts);
        // 
        RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
        requestEvent.setPriority(PriorityType.HIGH);
        // 
        roleRequestService.startConcepts(requestEvent, event);
    } else {
        // ~ sync
        roleRequestService.executeConceptsImmediate(contract.getIdentity(), concepts);
    }
    // delete contract guarantees
    IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
    filter.setIdentityContractId(contractId);
    contractGuaranteeService.find(filter, null).forEach(guarantee -> {
        contractGuaranteeService.delete(guarantee);
    });
    // delete contract positions
    IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
    positionFilter.setIdentityContractId(contractId);
    contractPositionService.find(positionFilter, null).forEach(position -> {
        contractPositionService.delete(position);
    });
    // 
    // delete all contract's delegations
    IdmDelegationDefinitionFilter delegationFilter = new IdmDelegationDefinitionFilter();
    delegationFilter.setDelegatorContractId(contractId);
    delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
        delegationDefinitionService.delete(delegation);
    });
    // delete identity contract
    if (forceDelete) {
        LOG.debug("Contract [{}] should be deleted by caller after all asynchronus processes are completed.", contractId);
        // 
        // 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(contract, stateDeleted);
        // 
        // set disabled
        contract.setState(ContractState.DISABLED);
        service.saveInternal(contract);
    } else {
        service.deleteInternal(contract);
    }
    return new DefaultEventResult<>(event, this);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ArrayList(java.util.ArrayList) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) IdmDelegationDefinitionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmDelegationDefinitionFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)

Example 48 with IdmEntityStateDto

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

the class EntityStateSaveProcessor method process.

@Override
public EventResult<IdmEntityStateDto> process(EntityEvent<IdmEntityStateDto> event) {
    IdmEntityStateDto entity = event.getContent();
    entity = service.saveInternal(entity);
    event.setContent(entity);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 49 with IdmEntityStateDto

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

the class ContractSliceManagerTest method createDirtyState.

/**
 * Create new dirty state for contract slice
 *
 * @param slice
 * @param parameters
 * @return
 */
private IdmEntityStateDto createDirtyState(IdmContractSliceDto slice) {
    Map<String, Object> transformedMarameters = new HashMap<String, Object>();
    transformedMarameters.put("entityId", slice.getId());
    DefaultResultModel resultModel = new DefaultResultModel(CoreResultCode.DIRTY_STATE, transformedMarameters);
    IdmEntityStateDto dirtyState = new IdmEntityStateDto();
    dirtyState.setResult(new OperationResultDto.Builder(OperationState.BLOCKED).setModel(resultModel).build());
    return entityStateManager.saveState(slice, dirtyState);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto)

Example 50 with IdmEntityStateDto

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

the class DefaultEntityEventManagerIntergationTest method testAcceptedException.

@Test
public void testAcceptedException() {
    try {
        getHelper().enableAsynchronousProcessing();
        // 
        IdmEntityEventDto event = new IdmEntityEventDto();
        AcceptedContent content = new AcceptedContent();
        content.setId(UUID.randomUUID());
        event.setContent(content);
        event.setOwnerId(content.getId());
        event.setOwnerType(manager.getOwnerType(content));
        event = manager.saveEvent(event);
        manager.executeEvent(event);
        IdmEntityEventFilter filter = new IdmEntityEventFilter();
        filter.setOwnerId(content.getId());
        filter.setStates(Lists.newArrayList(OperationState.EXECUTED));
        // 
        // wait for execute event
        getHelper().waitForResult(res -> {
            return entityEventService.find(filter, PageRequest.of(0, 1)).getContent().isEmpty();
        }, 500, 20);
        // 
        event = manager.getEvent(event.getId());
        Assert.assertEquals(OperationState.EXECUTED, event.getResult().getState());
        Assert.assertEquals(CoreResultCode.ACCEPTED.name(), event.getResult().getCode());
        // 
        // check state is executed too
        IdmEntityStateFilter stateFilter = new IdmEntityStateFilter();
        stateFilter.setEventId(event.getId());
        List<IdmEntityStateDto> states = entityStateManager.findStates(content, null).getContent();
        Assert.assertFalse(states.isEmpty());
        Assert.assertTrue(states.stream().allMatch(s -> s.getResult().getState() == OperationState.EXECUTED && s.getResult().getCode().equals(CoreResultCode.ACCEPTED.name())));
    } finally {
        getHelper().disableAsynchronousProcessing();
    }
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultEventContext(eu.bcvsolutions.idm.core.api.event.DefaultEventContext) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AcceptedContent(eu.bcvsolutions.idm.core.event.AcceptedContent) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) EntityGenerateValuesProcessor(eu.bcvsolutions.idm.core.model.event.processor.EntityGenerateValuesProcessor) Autowired(org.springframework.beans.factory.annotation.Autowired) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) MockDto(eu.bcvsolutions.idm.core.event.domain.MockDto) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdentityEventType(eu.bcvsolutions.idm.core.model.event.IdentityEvent.IdentityEventType) ObserveDtoProcessor(eu.bcvsolutions.idm.core.model.event.processor.ObserveDtoProcessor) TestEntityEventProcessorConfiguration(eu.bcvsolutions.idm.core.event.TestEntityEventProcessorConfiguration) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) PageRequest(org.springframework.data.domain.PageRequest) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) NeverEndingProcessor(eu.bcvsolutions.idm.core.model.event.processor.NeverEndingProcessor) EventType(eu.bcvsolutions.idm.core.api.event.EventType) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) TestContentTwo(eu.bcvsolutions.idm.core.event.TestContentTwo) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) ArrayList(java.util.ArrayList) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) Lists(com.google.common.collect.Lists) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdentityRoleEventType(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent.IdentityRoleEventType) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) ConditionalContent(eu.bcvsolutions.idm.core.event.ConditionalContent) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) TestIdentityNotifyProcessor(eu.bcvsolutions.idm.core.model.event.processor.TestIdentityNotifyProcessor) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) EmptyEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EmptyEntityEventProcessor) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) TestContent(eu.bcvsolutions.idm.core.event.TestContent) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) AcceptedContent(eu.bcvsolutions.idm.core.event.AcceptedContent) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)77 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)43 Test (org.junit.Test)41 UUID (java.util.UUID)40 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)30 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)30 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)24 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)23 List (java.util.List)21 Autowired (org.springframework.beans.factory.annotation.Autowired)21 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)20 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)19 Transactional (org.springframework.transaction.annotation.Transactional)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 Lists (com.google.common.collect.Lists)15 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)15 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)15 Assert (org.junit.Assert)14 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)13