Search in sources :

Example 6 with IdentityEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityEvent in project CzechIdMng by bcvsolutions.

the class EntityEventProcessorUnitTest method testSupportAllIdentityEvents.

@Test
public void testSupportAllIdentityEvents() {
    EntityEventProcessor<?> processor = new EventProcessorIdentity();
    assertTrue(processor.supports(new IdentityEvent(IdentityEventType.CREATE, new IdmIdentityDto())));
    assertTrue(processor.supports(new IdentityEvent(IdentityEventType.UPDATE, new IdmIdentityDto())));
    assertTrue(processor.supports(new IdentityEvent(IdentityEventType.DELETE, new IdmIdentityDto())));
    assertFalse(processor.supports(new RoleEvent(RoleEventType.DELETE, new IdmRoleDto())));
    assertTrue(processor.supports(new CoreEvent<IdmIdentityDto>(CustomType.SAVE, new IdmIdentityDto())));
    assertTrue(processor.supports(new CoreEvent<>(CustomType.CUSTOM, new IdmIdentityDto())));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) RoleEvent(eu.bcvsolutions.idm.core.model.event.RoleEvent) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 7 with IdentityEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityEvent in project CzechIdMng by bcvsolutions.

the class EntityEventProcessorUnitTest method testSuppotsAll.

@Test
public void testSuppotsAll() {
    EntityEventProcessor<?> processor = new EventProcessorBase();
    assertTrue(processor.supports(new IdentityEvent(IdentityEventType.UPDATE, new IdmIdentityDto())));
    assertTrue(processor.supports(new IdentityEvent(IdentityEventType.DELETE, new IdmIdentityDto())));
    assertTrue(processor.supports(new IdentityContractEvent(IdentityContractEventType.DELETE, new IdmIdentityContractDto())));
    assertTrue(processor.supports(new CoreEvent<IdmIdentityDto>(CustomType.SAVE, new IdmIdentityDto())));
    assertTrue(processor.supports(new CoreEvent<>(CustomType.CUSTOM, new IdmIdentityDto())));
    assertTrue(processor.supports(new CoreEvent<IdmIdentityContractDto>(IdentityContractEventType.UPDATE, new IdmIdentityContractDto())));
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 8 with IdentityEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityEvent in project CzechIdMng by bcvsolutions.

the class IdentityContractEnableProcessor method process.

/**
 * Check identity state after contract is enabled
 *
 * @param contract
 * @param skipRecalculation Skip automatic role recalculation
 * @return
 */
public OperationResult process(IdmIdentityContractDto contract, Boolean skipRecalculation) {
    if (contract.isValid() && contract.getState() != ContractState.EXCLUDED) {
        IdmIdentityDto identity = identityService.get(contract.getIdentity());
        IdentityState newState = identityService.evaluateState(identity.getId());
        // we want to enable identity with contract other than default one
        if (newState == IdentityState.VALID && (identity.isDisabled() || identity.getState() == IdentityState.CREATED)) {
            LOG.info("Change identity [{}] state [{}]", identity.getUsername(), IdentityState.VALID);
            // 
            identity.setState(IdentityState.VALID);
            // is neccessary publish new event with skip recalculation automatic roles
            IdentityEvent event = new IdentityEvent(IdentityEventType.UPDATE, identity);
            event.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, skipRecalculation);
            identityService.publish(event);
        }
    }
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState)

Example 9 with IdentityEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityEvent in project CzechIdMng by bcvsolutions.

the class IdentityContractEndProcessor method process.

/**
 * Check identity state after contract ended
 *
 * @param contract
 * @param skipRecalculation Skip automatic role recalculation
 * @return
 */
public OperationResult process(IdmIdentityContractDto contract, Boolean skipRecalculation) {
    // update identity state
    IdmIdentityDto identity = identityService.get(contract.getIdentity());
    IdentityState newState = identityService.evaluateState(identity.getId());
    if (identity.getState() != newState) {
        LOG.info("Change identity [{}] state [{}]", identity.getUsername(), newState);
        // 
        identity.setState(newState);
        // is neccessary publish new event with skip recalculation automatic roles
        IdentityEvent identityEvent = new IdentityEvent(IdentityEventType.UPDATE, identity);
        identityEvent.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, skipRecalculation);
        identityService.publish(identityEvent);
    }
    // TODO: remove? It's solved by different process
    if (!contract.isValidNowOrInFuture()) {
        identityRoleService.findAllByContract(contract.getId()).forEach(role -> {
            identityRoleService.delete(role);
        });
    }
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState)

Example 10 with IdentityEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityEvent in project CzechIdMng by bcvsolutions.

the class EntityEventProcessorUnitTest method testHasEventType.

@Test
public void testHasEventType() {
    EntityEvent<IdmIdentityDto> event = new IdentityEvent(IdentityEventType.UPDATE, new IdmIdentityDto());
    // 
    assertTrue(event.hasType(IdentityEventType.UPDATE));
    assertFalse(event.hasType(IdentityEventType.CREATE));
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Aggregations

IdentityEvent (eu.bcvsolutions.idm.core.model.event.IdentityEvent)13 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)12 Test (org.junit.Test)6 IdentityState (eu.bcvsolutions.idm.core.api.domain.IdentityState)4 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)4 AbstractVerifiableUnitTest (eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest)4 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3 CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 RoleEvent (eu.bcvsolutions.idm.core.model.event.RoleEvent)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 IdmAccountDto (eu.bcvsolutions.idm.core.api.dto.IdmAccountDto)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 IdentityContractEvent (eu.bcvsolutions.idm.core.model.event.IdentityContractEvent)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 Transactional (org.springframework.transaction.annotation.Transactional)1