Search in sources :

Example 1 with SysProvisioningBatchDto

use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningOperationService method handleFailed.

/**
 * REQUIRES_NEW => we want to have log in queue / archive all time, even original transaction ends with exception.
 */
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public SysProvisioningOperationDto handleFailed(SysProvisioningOperationDto operation, Exception ex) {
    ResultModel resultModel;
    if (ex instanceof ResultCodeException) {
        resultModel = ((ResultCodeException) ex).getError().getError();
    } else {
        String uid = getByProvisioningOperation(operation).getUid();
        resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_FAILED, ImmutableMap.of("name", uid, "system", getSystem(operation).getName(), "operationType", operation.getOperationType(), "objectClass", operation.getProvisioningContext().getConnectorObject().getObjectClass().getType()));
    }
    LOG.error(resultModel.toString(), ex);
    // 
    operation.increaseAttempt();
    operation.setMaxAttempts(provisioningConfiguration.getRetryMaxAttempts());
    operation.setResult(new OperationResult.Builder(OperationState.EXCEPTION).setModel(resultModel).setCause(ex).build());
    // 
    if (!operation.isDryRun()) {
        operation = save(operation);
        // create archive operation for the current attempt
        provisioningArchiveService.archive(operation);
        // 
        // calculate next attempt
        SysProvisioningOperationDto firstOperation = getFirstOperationByBatchId(operation.getBatch());
        if (firstOperation.equals(operation)) {
            SysProvisioningBatchDto batch = batchService.get(operation.getBatch());
            batch.setNextAttempt(batchService.calculateNextAttempt(operation));
            batch = batchService.save(batch);
        }
        // 
        if (securityService.getCurrentId() != null) {
            // TODO: check account owner
            // TODO: notification is moved into console ... simple LOG instead?
            notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
        }
    }
    return operation;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SysProvisioningBatchDto

use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.

the class ProvisioningBreakProcessorTest method testBlockSystemCreate.

@Test
public void testBlockSystemCreate() {
    SysSystemDto system = getHelper().createTestResourceSystem(true);
    SysBlockedOperationDto blockedOperationDto = new SysBlockedOperationDto();
    blockedOperationDto.blockCreate();
    system.setBlockedOperation(blockedOperationDto);
    system = systemService.save(system);
    // 
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    createProvisioningBreak(20l, 3, 2, ProvisioningEventType.CREATE, system.getId());
    // 
    this.createAccount(system, identity);
    // 
    // create block
    provisioningService.doProvisioning(identity);
    SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
    // 
    SysProvisioningBatchDto batch = batchService.findBatch(systemEntity.getId());
    // 
    List<SysProvisioningOperationDto> content = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
    assertEquals(1, content.size());
    SysProvisioningOperationDto sysProvisioningOperationDto = content.get(0);
    // 
    assertEquals(ProvisioningEventType.CREATE, sysProvisioningOperationDto.getOperationType());
    assertEquals(OperationState.BLOCKED, sysProvisioningOperationDto.getResult().getState());
}
Also used : SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) SysBlockedOperationDto(eu.bcvsolutions.idm.acc.dto.SysBlockedOperationDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with SysProvisioningBatchDto

use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.

the class ProvisioningBreakProcessorTest method testPeriod.

@Test
public void testPeriod() {
    SysSystemDto system = getHelper().createTestResourceSystem(true);
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    SysProvisioningBreakConfigDto breakConfig = createProvisioningBreak(20l, 2, null, ProvisioningEventType.UPDATE, system.getId());
    IdmIdentityDto recipient = getHelper().createIdentity((GuardedString) null);
    createRecipient(breakConfig.getId(), recipient.getId(), null);
    // 
    this.createAccount(system, identity);
    // 
    // 
    // create
    provisioningService.doProvisioning(identity);
    provisioningService.doProvisioning(identity);
    provisioningService.doProvisioning(identity);
    // 
    SysProvisioningBreakItems cacheProcessedItems = provisioningBreakConfig.getCacheProcessedItems(system.getId());
    // 
    // subtrack only 19 minutes from all items
    long subtrackMinutes = 1140000;
    List<Long> execudedItems = cacheProcessedItems.getExecutedItems(ProvisioningEventType.UPDATE);
    // it isn't possible use foreEach or another stream function (reference)
    for (Long item : execudedItems) {
        execudedItems.set(execudedItems.indexOf(item), item - subtrackMinutes);
    }
    // 
    // block
    provisioningService.doProvisioning(identity);
    // 
    SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
    SysProvisioningBatchDto batch = batchService.findBatch(systemEntity.getId());
    // 
    assertNotNull(batch);
    // 
    List<SysProvisioningOperationDto> content = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
    assertEquals(1, content.size());
    // 
    SysProvisioningOperationDto sysProvisioningOperationDto = content.get(0);
    // 
    assertEquals(ProvisioningEventType.UPDATE, sysProvisioningOperationDto.getOperationType());
    assertEquals(OperationState.BLOCKED, sysProvisioningOperationDto.getResult().getState());
}
Also used : SysProvisioningBreakConfigDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysProvisioningBreakItems(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakItems) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with SysProvisioningBatchDto

use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.

the class ProvisioningBreakProcessorTest method testPeriodOld.

@Test
public void testPeriodOld() {
    SysSystemDto system = getHelper().createTestResourceSystem(true);
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    SysProvisioningBreakConfigDto breakConfig = createProvisioningBreak(20l, 3, null, ProvisioningEventType.UPDATE, system.getId());
    IdmIdentityDto recipient = getHelper().createIdentity((GuardedString) null);
    createRecipient(breakConfig.getId(), recipient.getId(), null);
    // 
    this.createAccount(system, identity);
    // 
    // 
    // create
    provisioningService.doProvisioning(identity);
    provisioningService.doProvisioning(identity);
    provisioningService.doProvisioning(identity);
    // 
    SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
    SysProvisioningBatchDto batch = batchService.findBatch(systemEntity.getId());
    List<SysProvisioningOperationDto> content = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
    // 
    assertTrue(content.isEmpty());
    // 
    SysProvisioningBreakItems cacheProcessedItems = provisioningBreakConfig.getCacheProcessedItems(system.getId());
    // 
    // subtrack 25 minutes from all items
    long subtrackMinutes = 1500000;
    List<Long> execudedItems = cacheProcessedItems.getExecutedItems(ProvisioningEventType.UPDATE);
    // it isn't possible use foreEach or another stream function (reference)
    for (Long item : execudedItems) {
        execudedItems.set(execudedItems.indexOf(item), item - subtrackMinutes);
    }
    // 
    provisioningService.doProvisioning(identity);
    provisioningService.doProvisioning(identity);
    // 
    systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
    batch = batchService.findBatch(systemEntity.getId());
    content = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
    // 
    assertTrue(content.isEmpty());
}
Also used : SysProvisioningBreakConfigDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysProvisioningBreakItems(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakItems) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 5 with SysProvisioningBatchDto

use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.

the class CancelProvisioningQueueTaskExecutor method processItem.

@Override
public Optional<OperationResult> processItem(SysProvisioningOperationDto dto) {
    // 
    if (dto.getBatch() == null) {
        // cancel single operation - batch was deleted for some reason (previously saved operations without batch, truncate in database ...)
        provisioningExecutor.cancel(dto);
        // 
        return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
    }
    SysProvisioningBatchDto batch = DtoUtils.getEmbedded(dto, SysProvisioningOperation_.batch, (SysProvisioningBatchDto) null);
    if (batch == null) {
        batch = provisioningBatchService.get(dto.getBatch());
    }
    // 
    provisioningExecutor.cancel(batch);
    // 
    return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
}
Also used : SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto)

Aggregations

SysProvisioningBatchDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto)24 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)16 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)15 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)14 Test (org.junit.Test)14 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)11 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)9 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)8 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)5 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)5 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)4 SysProvisioningArchiveDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto)3 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)3 RetryProvisioningTaskExecutor (eu.bcvsolutions.idm.acc.scheduler.task.impl.RetryProvisioningTaskExecutor)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)3 UUID (java.util.UUID)3