Search in sources :

Example 1 with ProvisioningEventType

use of eu.bcvsolutions.idm.acc.domain.ProvisioningEventType 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 2 with ProvisioningEventType

use of eu.bcvsolutions.idm.acc.domain.ProvisioningEventType in project CzechIdMng by bcvsolutions.

the class ProvisioningBreakProcessorTest method testGlobalConfigurationSettings.

@Test
public void testGlobalConfigurationSettings() {
    IdmIdentityDto recipient = testHelper.createIdentity();
    IdmIdentityDto recipient2 = testHelper.createIdentity();
    IdmRoleDto roleRecipient = testHelper.createRole();
    // 
    createGlobalConfiguration(ProvisioningBreakConfiguration.GLOBAL_BREAK_DELETE_OPERATION, false, 2, 3, 20l, null, roleRecipient);
    String prefix = ProvisioningBreakConfiguration.GLOBAL_BREAK_PREFIX + ProvisioningBreakConfiguration.GLOBAL_BREAK_DELETE_OPERATION;
    configurationService.setValue(prefix + ProvisioningBreakConfiguration.PROPERTY_IDENTITY_RECIPIENTS, recipient.getUsername() + ",   " + recipient2.getUsername());
    // 
    // check non existing configuration
    ProvisioningEventType eventType = ProvisioningEventType.UPDATE;
    Object value = provisioningBreakConfiguration.getDisabled(eventType);
    assertNull(value);
    value = provisioningBreakConfiguration.getDisableLimit(eventType);
    assertNull(value);
    List<IdmIdentityDto> recipients = provisioningBreakConfiguration.getIdentityRecipients(eventType);
    assertTrue(recipients.isEmpty());
    value = provisioningBreakConfiguration.getPeriod(eventType);
    assertNull(value);
    // 
    // check existing
    eventType = ProvisioningEventType.DELETE;
    Boolean disabled = provisioningBreakConfiguration.getDisabled(eventType);
    Integer warningLimit = provisioningBreakConfiguration.getWarningLimit(eventType);
    Integer disableLimit = provisioningBreakConfiguration.getDisableLimit(eventType);
    Long period = provisioningBreakConfiguration.getPeriod(eventType);
    List<IdmIdentityDto> identityRecipients = provisioningBreakConfiguration.getIdentityRecipients(eventType);
    List<IdmRoleDto> roleRecipients = provisioningBreakConfiguration.getRoleRecipients(eventType);
    // 
    assertEquals(Boolean.FALSE, disabled);
    assertEquals(Integer.valueOf(2), warningLimit);
    assertEquals(Integer.valueOf(3), disableLimit);
    assertEquals(Long.valueOf(20l), period);
    assertEquals(2, identityRecipients.size());
    assertEquals(1, roleRecipients.size());
    // 
    IdmIdentityDto foundedRecipient = identityRecipients.stream().filter(rec -> rec.getUsername().equals(recipient.getUsername())).findFirst().get();
    assertNotNull(foundedRecipient);
    assertEquals(recipient.getId(), foundedRecipient.getId());
    // 
    foundedRecipient = identityRecipients.stream().filter(rec -> rec.getUsername().equals(recipient2.getUsername())).findFirst().get();
    assertNotNull(foundedRecipient);
    assertEquals(recipient2.getId(), foundedRecipient.getId());
    // 
    IdmRoleDto foundedRole = roleRecipients.get(0);
    assertNotNull(foundedRole);
    assertEquals(roleRecipient.getId(), foundedRole.getId());
}
Also used : ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) SysProvisioningBreakRecipientService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningBreakRecipientService) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysProvisioningBreakRecipientDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakRecipientDto) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) After(org.junit.After) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) Before(org.junit.Before) SysProvisioningBreakItems(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakItems) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) InitTestData(eu.bcvsolutions.idm.InitTestData) Assert.assertNotNull(org.junit.Assert.assertNotNull) SysProvisioningOperationService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningOperationService) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) UUID(java.util.UUID) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) SysProvisioningBatchService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningBatchService) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) ProvisioningBreakConfiguration(eu.bcvsolutions.idm.acc.config.domain.ProvisioningBreakConfiguration) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) SysBlockedOperationDto(eu.bcvsolutions.idm.acc.dto.SysBlockedOperationDto) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysProvisioningBreakConfigDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto) AccountType(eu.bcvsolutions.idm.acc.domain.AccountType) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) AccIdentityAccountService(eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) TestHelper(eu.bcvsolutions.idm.acc.TestHelper) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) SysProvisioningBreakConfigService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningBreakConfigService) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

ProvisioningEventType (eu.bcvsolutions.idm.acc.domain.ProvisioningEventType)2 SysProvisioningBreakConfigDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto)2 SysProvisioningBreakItems (eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakItems)2 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)2 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)2 InitTestData (eu.bcvsolutions.idm.InitTestData)1 TestHelper (eu.bcvsolutions.idm.acc.TestHelper)1 ProvisioningBreakConfiguration (eu.bcvsolutions.idm.acc.config.domain.ProvisioningBreakConfiguration)1 AccountType (eu.bcvsolutions.idm.acc.domain.AccountType)1 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)1 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)1 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)1 SysBlockedOperationDto (eu.bcvsolutions.idm.acc.dto.SysBlockedOperationDto)1 SysProvisioningBatchDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto)1 SysProvisioningBreakRecipientDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakRecipientDto)1 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)1 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)1 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)1 AccAccountService (eu.bcvsolutions.idm.acc.service.api.AccAccountService)1 AccIdentityAccountService (eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService)1