Search in sources :

Example 1 with IdentityEvent

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

the class PasswordExpiredTaskExecutor method processItem.

@Override
public Optional<OperationResult> processItem(IdmPasswordDto dto) {
    IdmIdentityDto identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, dto.getIdentity());
    LOG.info("Publishing [{}] event to identity [{}], password expired in [{}]", IdentityEventType.PASSWORD_EXPIRED, identity.getUsername(), dto.getValidTill());
    try {
        entityEventManager.process(new IdentityEvent(IdentityEventType.PASSWORD_EXPIRED, identity));
        return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
    } catch (Exception ex) {
        LOG.error("Publishing [{}] event to identity [{}], password expired in [{}] failed", IdentityEventType.PASSWORD_EXPIRED, dto.getIdentity(), dto.getValidTill(), ex);
        return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build());
    }
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 2 with IdentityEvent

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

the class IdentityContractExclusionProcessor method process.

/**
 * Check identity state after contract is excluded
 *
 * @param contract
 * @param skipRecalculation Skip automatic role recalculation
 * @return
 */
public OperationResult process(IdmIdentityContractDto contract, Boolean skipRecalculation) {
    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 necessary 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);
    }
    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 3 with IdentityEvent

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

the class IdentityContractSaveProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    IdmIdentityContractDto contract = event.getContent();
    contract = service.saveInternal(contract);
    event.setContent(contract);
    // 
    // check identity state
    IdmIdentityContractDto previousContract = event.getOriginalSource();
    IdmIdentityDto identity = DtoUtils.getEmbedded(contract, IdmIdentityContract_.identity.getName(), IdmIdentityDto.class);
    if ((identity.getState() == IdentityState.CREATED || identity.isDisabled()) && contractChanged(previousContract, contract)) {
        // synchronize identity states, which has no effect on HR processes
        identity = identityService.get(contract.getIdentity());
        IdentityState newState = identityService.evaluateState(identity.getId());
        if (newState.isDisabled() && identity.getState() != newState) {
            identity.setState(newState);
            // publish new save event for identity with skip recalculation
            IdentityEvent identityEvent = new IdentityEvent(IdentityEventType.UPDATE, identity);
            identityEvent.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, true);
            identityService.publish(identityEvent);
        }
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState)

Example 4 with IdentityEvent

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

the class IdentitySynchronizationExecutor method callProvisioningForEntity.

/**
 * Call provisioning for given account
 *
 * @param entity
 * @param entityType
 * @param logItem
 */
@Override
protected void callProvisioningForEntity(IdmIdentityDto entity, SystemEntityType entityType, SysSyncItemLogDto logItem) {
    addToItemLog(logItem, MessageFormat.format("Call provisioning (process IdentityEventType.SAVE) for identity ({0}) with username ({1}).", entity.getId(), entity.getUsername()));
    // 
    IdentityEvent event = new IdentityEvent(IdentityEventType.UPDATE, entity);
    // We don't want recalculate automatic role by attribute recalculation for every contract.
    // Recalculation will be started only once.
    event.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, Boolean.TRUE);
    identityService.publish(event);
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent)

Example 5 with IdentityEvent

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

the class DefaultIdmIdentityServiceIntegrationTest method testSkipDefaultContract.

/**
 * When identity is created with the event property
 * IdmIdentityContractService.SKIP_CREATION_OF_DEFAULT_POSITION = TRUE, then
 * default contract haven't to be created.
 */
@Test
public void testSkipDefaultContract() {
    IdmIdentityDto identity = new IdmIdentityDto();
    String username = "contract_test_" + System.currentTimeMillis();
    identity.setUsername(username);
    // confidential storage
    identity.setPassword(new GuardedString("heslo"));
    identity.setFirstName("Test");
    identity.setLastName("Identity");
    EntityEvent<IdmIdentityDto> event = new IdentityEvent(IdentityEventType.CREATE, identity, ImmutableMap.of(// In the identity sync are creation of the default contract skipped.
    IdmIdentityContractService.SKIP_CREATION_OF_DEFAULT_POSITION, Boolean.TRUE));
    identity = identityService.publish(event).getContent();
    // 
    List<IdmIdentityContractDto> contracts = identityContractService.findAllByIdentity(identity.getId());
    assertEquals(0, contracts.size());
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) 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