Search in sources :

Example 36 with IdmEntityStateDto

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

the class DefaultUniformPasswordManager method endUniformPasswordProcess.

@Override
@Transactional
public void endUniformPasswordProcess(UUID transactionId) {
    Assert.notNull(transactionId, "Transaction cannot be null!");
    IdmEntityStateFilter entityStateFilter = new IdmEntityStateFilter();
    entityStateFilter.setTransactionId(transactionId);
    entityStateFilter.setResultCode(CoreResultCode.IDENTITY_UNIFORM_PASSWORD.getCode());
    entityStateFilter.setStates(Lists.newArrayList(OperationState.BLOCKED));
    List<IdmEntityStateDto> entityStateDtos = entityStateManager.findStates(entityStateFilter, null).getContent();
    // Send notification with password to identities where was uniform password used.
    entityStateDtos.stream().filter(entityState -> IdmIdentity.class.getCanonicalName().equals(entityState.getOwnerType())).filter(this::uniformPasswordUsed).forEach(entityState -> {
        UUID identityId = entityState.getOwnerId();
        if (identityId != null) {
            IdmIdentityDto identityDto = identityService.get(identityId);
            if (identityDto != null) {
                // Send notification with uniform password.
                this.sendUniformPasswordNotification(identityDto, entityState);
            }
        }
    });
    // Remove all uniform password entity states for this transaction.
    entityStateDtos.forEach(entityState -> entityStateManager.deleteState(entityState));
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with IdmEntityStateDto

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

the class DefaultEntityEventManager method saveStates.

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public List<IdmEntityStateDto> saveStates(EntityEvent<?> event, List<IdmEntityStateDto> previousStates, EventResult<?> result) {
    IdmEntityEventDto entityEvent = getEvent(event);
    List<IdmEntityStateDto> results = new ArrayList<>();
    if (entityEvent == null) {
        return results;
    }
    // simple drop - we don't need to find and update results, we'll create new ones
    if (previousStates != null && !previousStates.isEmpty()) {
        previousStates.forEach(state -> {
            entityStateManager.deleteState(state);
        });
    }
    // 
    if (result == null) {
        IdmEntityStateDto state = new IdmEntityStateDto(entityEvent);
        // default result without model
        state.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).build());
        results.add(entityStateManager.saveState(null, state));
        return results;
    }
    if (result.getResults().isEmpty()) {
        results.add(entityStateManager.saveState(null, createState(entityEvent, result, new OperationResultDto.Builder(OperationState.EXECUTED).build())));
        return results;
    }
    result.getResults().forEach(opeartionResult -> {
        results.add(entityStateManager.saveState(null, createState(entityEvent, result, opeartionResult.toDto())));
    });
    // 
    return results;
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) ArrayList(java.util.ArrayList) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with IdmEntityStateDto

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

the class DefaultEntityEventManager method createState.

private <E extends Serializable> IdmEntityStateDto createState(IdmEntityEventDto entityEvent, EventResult<E> eventResult, OperationResultDto operationResult) {
    IdmEntityStateDto state = new IdmEntityStateDto(entityEvent);
    // 
    state.setClosed(eventResult.isClosed());
    state.setSuspended(eventResult.isSuspended());
    state.setProcessedOrder(eventResult.getProcessedOrder());
    state.setProcessorId(eventResult.getProcessor().getId());
    state.setProcessorModule(eventResult.getProcessor().getModule());
    state.setProcessorName(eventResult.getProcessor().getName());
    state.setResult(operationResult);
    // 
    return state;
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)

Example 39 with IdmEntityStateDto

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

the class IdmEntityStateControllerRestTest method testFindByOperationStates.

@Test
public void testFindByOperationStates() {
    UUID ownerId = UUID.randomUUID();
    // 
    IdmEntityStateDto state = prepareDto();
    state.setOwnerId(ownerId);
    state.getResult().setState(OperationState.RUNNING);
    IdmEntityStateDto stateOne = entityStateService.save(state);
    // 
    state = prepareDto();
    state.setOwnerId(ownerId);
    state.getResult().setState(OperationState.BLOCKED);
    IdmEntityStateDto stateTwo = entityStateService.save(state);
    // 
    state = prepareDto();
    state.setOwnerId(ownerId);
    state.getResult().setState(OperationState.EXCEPTION);
    // other
    entityStateService.save(state);
    // 
    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.set("ownerId", ownerId.toString());
    parameters.put("states", Lists.newArrayList(stateOne.getResult().getState().name(), stateTwo.getResult().getState().name()));
    // 
    List<IdmEntityStateDto> results = find(parameters);
    Assert.assertEquals(2, results.size());
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateTwo.getId())));
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Lists(com.google.common.collect.Lists) 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) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) MultiValueMap(org.springframework.util.MultiValueMap) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) UUID(java.util.UUID) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) ChronoUnit(java.time.temporal.ChronoUnit) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) UUID(java.util.UUID) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 40 with IdmEntityStateDto

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

the class IdmEntityStateControllerRestTest method testFindByText.

@Test
public void testFindByText() {
    UUID ownerOne = UUID.randomUUID();
    UUID ownerTwo = UUID.randomUUID();
    String ownerTypeOne = getHelper().createName();
    String ownerTypeTwo = ownerTypeOne + getHelper().createName();
    // 
    IdmEntityStateDto state = prepareDto();
    state.setOwnerId(ownerOne);
    state.setOwnerType(ownerTypeOne);
    IdmEntityStateDto stateOne = entityStateService.save(state);
    // 
    state = prepareDto();
    state.setOwnerId(ownerTwo);
    state.setOwnerType(ownerTypeTwo);
    state.getResult().setCode("mOck-code");
    IdmEntityStateDto stateTwo = entityStateService.save(state);
    // 
    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.set("text", ownerTypeOne);
    List<IdmEntityStateDto> results = find(parameters);
    Assert.assertEquals(2, results.size());
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateTwo.getId())));
    // 
    parameters.set("text", ownerOne.toString().substring(0, 6));
    parameters.set("ownerType", ownerTypeOne);
    results = find(parameters);
    // 
    if (!getHelper().isDatabaseMssql()) {
        // search by uuid as string is not supported for mssql
        Assert.assertEquals(1, results.size());
        Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
        // 
        parameters.set("text", "moCk-");
        parameters.set("ownerType", ownerTypeTwo);
        results = find(parameters);
        Assert.assertEquals(1, results.size());
        Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateTwo.getId())));
    } else {
        // not found on mssql
        Assert.assertEquals(0, results.size());
    }
    // 
    parameters.set("text", ownerOne.toString());
    parameters.set("ownerType", ownerTypeOne);
    results = find(parameters);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Lists(com.google.common.collect.Lists) 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) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) MultiValueMap(org.springframework.util.MultiValueMap) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) UUID(java.util.UUID) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) ChronoUnit(java.time.temporal.ChronoUnit) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) UUID(java.util.UUID) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) 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