Search in sources :

Example 21 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class ProvisioningBreakProcessor method process.

@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
    try {
        SysProvisioningOperationDto provisioningOperation = event.getContent();
        ProvisioningEventType operationType = provisioningOperation.getOperationType();
        SysSystemDto system = systemService.get(provisioningOperation.getSystem());
        // system may be blocked
        boolean blocked = isSystemBlockedOperation(operationType, system);
        // 
        if (blocked) {
            // system is already blocked
            provisioningOperation = blockOperation(provisioningOperation, system);
            event.setContent(provisioningOperation);
            return new DefaultEventResult<>(event, this, blocked);
        }
        // 
        // try found provisioning break configuration
        SysProvisioningBreakConfigDto breakConfig = breakConfigService.getConfig(operationType, system.getId());
        if (breakConfig == null) {
            LOG.debug("Provisioning break configuration for system name: [{}] and operation: [{}] not found. Global configuration will be used.", system.getCode(), operationType.toString());
            breakConfig = breakConfigService.getGlobalBreakConfiguration(operationType);
        }
        // 
        if (breakConfig == null) {
            LOG.debug("Global configuration for provisioning break isn't found.");
            return new DefaultEventResult<>(event, this, blocked);
        }
        // 
        if (breakConfig.isDisabled()) {
            LOG.debug("Provisioning break configuration id: [{}] for system name: [{}] and operation: [{}] is disabled.", breakConfig.getId(), system.getCode(), operationType.toString());
            // break configuration is disable continue
            return new DefaultEventResult<>(event, this, blocked);
        }
        Long currentTimeMillis = System.currentTimeMillis();
        // 
        // get cache for system
        SysProvisioningBreakItems cache = breakConfigService.getCacheProcessedItems(system.getId());
        // calculate timestamp without period
        Long timestampWithoutPeriod = currentTimeMillis - breakConfig.getPeriod(TimeUnit.MILLISECONDS);
        // remove older records
        cache.removeOlderRecordsThan(operationType, timestampWithoutPeriod);
        // get actual count - processed items from timestampWithoutPeriod
        int actualCount = cache.getSizeRecordsNewerThan(operationType, timestampWithoutPeriod);
        // operation count is sum all previous operation except this operation
        if (breakConfig.getWarningLimit() != null && breakConfig.getWarningLimit().equals(actualCount)) {
            // disabled may be null
            if (breakConfig.getDisableLimit() == null) {
                LOG.warn("Block for the system id [{}] and operation [{}] is not set. Operation counter [{}].", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), actualCount);
            } else {
                LOG.warn("To block the system id [{}] for operation [{}] remains [{}] operations + send message.", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), breakConfig.getDisableLimit() - actualCount);
            }
            IdmNotificationTemplateDto template = null;
            if (breakConfig.getWarningTemplate() == null) {
                LOG.debug("Warning template for provisioning break id [{}] missing.", breakConfig.getId());
            } else {
                template = DtoUtils.getEmbedded(breakConfig, SysProvisioningBreakConfig_.warningTemplate, IdmNotificationTemplateDto.class);
            }
            // 
            sendMessage(AccModuleDescriptor.TOPIC_PROVISIONING_BREAK_WARNING, system, actualCount, template, breakConfig, operationType, cache.getDiffBetweenActualAndLast(operationType, currentTimeMillis));
        } else if (breakConfig.getDisableLimit() != null && actualCount >= breakConfig.getDisableLimit()) {
            // check count is higher than disable limit
            // block system for operation
            blockSystemForOperation(operationType, system);
            // 
            IdmNotificationTemplateDto template = null;
            if (breakConfig.getWarningTemplate() == null) {
                LOG.debug("Warning template for provisioning break id [{}] missing.", breakConfig.getId());
            } else {
                template = DtoUtils.getEmbedded(breakConfig, SysProvisioningBreakConfig_.disableTemplate, IdmNotificationTemplateDto.class);
            }
            // 
            sendMessage(AccModuleDescriptor.TOPIC_PROVISIONING_BREAK_DISABLE, system, actualCount, template, breakConfig, operationType, cache.getDiffBetweenActualAndLast(operationType, currentTimeMillis));
            // 
            LOG.warn("System id: [{}] will be blocked for operation: [{}].", provisioningOperation.getSystem(), operationType.toString());
            provisioningOperation = blockOperation(provisioningOperation, system);
            blocked = true;
        } else if (breakConfig.getWarningLimit() != null && actualCount > breakConfig.getWarningLimit()) {
            // after overrun warning limit, isn't send any another notification - add at least log
            if (breakConfig.getDisableLimit() == null) {
                LOG.warn("Block for the system id [{}] and operation [{}] is not set. Operation counter [{}].", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), actualCount);
            } else {
                LOG.warn("To block the system id [{}] for operation [{}] remains [{}] operations.", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), breakConfig.getDisableLimit() - actualCount);
            }
        }
        // remove all unless items in cache
        cache.addItem(operationType, currentTimeMillis);
        breakConfigService.saveCacheProcessedItems(provisioningOperation.getSystem(), cache);
        // 
        event.setContent(provisioningOperation);
        return new DefaultEventResult<>(event, this, blocked);
    } catch (Exception ex) {
        LOG.error("Unexpect error while evaluate provisioning break.", ex);
        throw new ProvisioningException(AccResultCode.PROVISIONING_FAILED, ex);
    }
}
Also used : ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) SysProvisioningBreakConfigDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysProvisioningBreakItems(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakItems) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException)

Example 22 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class ProvisioningStartProcessor method process.

@Override
public EventResult<AccAccountDto> process(EntityEvent<AccAccountDto> event) {
    AccAccountDto account = event.getContent();
    Assert.notNull(account);
    LOG.info("Provisioning event start, for account id: [{}], account uid: [{}], real uid [{}] , system id: [{}]", account.getId(), account.getUid(), account.getRealUid(), account.getSystem());
    if (account.isInProtection()) {
        if (!isCanceledProvisioningProtectionBreak(event.getProperties())) {
            LOG.info("Account [{}] is in protection. Provisioning is skipped.", account.getUid());
            return new DefaultEventResult<>(event, this);
        }
        LOG.info("Account [{}] is in protection, but cancel attribute is TRUE. Provisioning is not skipped.", account.getUid());
    }
    provisioningService.doInternalProvisioning(account, (AbstractDto) event.getProperties().get(ProvisioningService.DTO_PROPERTY_NAME));
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto)

Example 23 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class ReadonlySystemProcessor method process.

@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
    SysProvisioningOperationDto provisioningOperation = event.getContent();
    SysSystemDto system = systemService.get(provisioningOperation.getSystem());
    boolean closed = false;
    if (system.isReadonly()) {
        String uid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
        ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_SYSTEM_READONLY, ImmutableMap.of("name", uid, "system", system.getName()));
        provisioningOperation.setResult(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(resultModel).build());
        // 
        provisioningOperation = provisioningOperationService.save(provisioningOperation);
        // 
        LOG.info(resultModel.toString());
        notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
        // 
        closed = true;
    }
    // set back to event content
    event.setContent(provisioningOperation);
    return new DefaultEventResult<>(event, this, closed);
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 24 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class RemoveProcessedOperationProcessor method process.

@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
    SysProvisioningOperationDto provisioningOperation = event.getContent();
    if (OperationState.EXECUTED == provisioningOperation.getResultState() || ProvisioningEventType.CANCEL == event.getType()) {
        provisioningOperationService.delete(provisioningOperation);
        LOG.debug("Executed provisioning operation [{}] was removed from queue.", provisioningOperation.getId());
        // 
        if (ProvisioningEventType.DELETE == event.getType()) {
            // We successfully deleted account on target system. We need to delete system entity
            systemEntityService.delete(systemEntityService.getByProvisioningOperation(provisioningOperation));
        }
    }
    return new DefaultEventResult<>(event, this, isClosable());
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Example 25 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class SynchronizationCancelProcessor method process.

@Override
public EventResult<AbstractSysSyncConfigDto> process(EntityEvent<AbstractSysSyncConfigDto> event) {
    LOG.info("Synchronization event cancel");
    AbstractSysSyncConfigDto config = event.getContent();
    synchronizationService.stopSynchronization(config);
    return new DefaultEventResult<>(event, this);
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Aggregations

DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)91 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)20 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)12 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)11 UUID (java.util.UUID)11 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)10 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)7 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)7 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)6 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)5 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)5 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)5 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)5 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)5 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)4 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)4 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)4 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)4 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)4 ArrayList (java.util.ArrayList)4