Search in sources :

Example 31 with SysSystemEntityDto

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

the class DefaultProvisioningExecutorIntegrationTest method testClearProvisioningBatchOnReadonlySystem.

@Test
public void testClearProvisioningBatchOnReadonlySystem() {
    SysSystemDto system = getHelper().createTestResourceSystem(true);
    system.setReadonly(true);
    system = systemService.save(system);
    String firstname = "firstname";
    SysProvisioningOperationDto provisioningOperation = createProvisioningOperation(system, firstname);
    Map<ProvisioningAttributeDto, Object> accoutObject = provisioningOperation.getProvisioningContext().getAccountObject();
    String uid = (String) accoutObject.get(getProvisioningAttribute(TestHelper.ATTRIBUTE_MAPPING_NAME));
    // 
    // publish event
    // 1 - create
    provisioningExecutor.execute(provisioningOperation);
    // is necessary to get again operation from service
    SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
    filter.setSystemEntity(provisioningOperation.getSystemEntity());
    filter.setSystemId(system.getId());
    SysProvisioningOperationDto readOnlyOperation = provisioningOperationService.find(filter, null).getContent().get(0);
    assertEquals(OperationState.NOT_EXECUTED, readOnlyOperation.getResultState());
    assertEquals(AccResultCode.PROVISIONING_SYSTEM_READONLY.name(), readOnlyOperation.getResult().getModel().getStatusEnum());
    SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
    // 2 - update
    provisioningExecutor.execute(updateProvisioningOperation(systemEntity, firstname + 2));
    // 
    // FIXME: how to order operations created in the same milis?
    getHelper().waitForResult(null, 1, 1);
    // 
    // 3 - update
    provisioningExecutor.execute(updateProvisioningOperation(systemEntity, firstname + 3));
    // 
    systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
    assertTrue(systemEntity.isWish());
    assertNull(getHelper().findResource(uid));
    // 
    // check batch
    SysProvisioningBatchDto batch = provisioningBatchService.findBatch(systemEntity.getId());
    Assert.assertNotNull(batch);
    // 
    // check provisioning operation requests
    List<SysProvisioningOperationDto> requests = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
    Assert.assertEquals(3, requests.size());
    // 
    // execute first operation - create
    system.setReadonly(false);
    system = systemService.save(system);
    provisioningExecutor.execute(readOnlyOperation);
    Assert.assertNull(provisioningOperationService.get(readOnlyOperation.getId()));
    // 
    systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
    assertFalse(systemEntity.isWish());
    TestResource resource = getHelper().findResource(uid);
    assertNotNull(resource);
    Assert.assertEquals(firstname, resource.getFirstname());
    Assert.assertEquals(2, provisioningOperationService.findByBatchId(batch.getId(), null).getContent().size());
    // 
    // execute whole batch
    provisioningExecutor.execute(batch);
    // 
    resource = getHelper().findResource(uid);
    Assert.assertEquals(firstname + 3, resource.getFirstname());
    Assert.assertEquals(0, provisioningOperationService.findByBatchId(batch.getId(), null).getTotalElements());
    Assert.assertNull(provisioningOperationService.get(readOnlyOperation.getId()));
    batch = provisioningBatchService.get(batch.getId());
    Assert.assertNull(batch.getNextAttempt());
}
Also used : SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) 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 32 with SysSystemEntityDto

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

the class DefaultSysSystemServiceTest method testReferentialIntegrityProvisioningOperationExists.

@Test(expected = ResultCodeException.class)
public void testReferentialIntegrityProvisioningOperationExists() {
    SysSystemDto system = new SysSystemDto();
    String systemName = "t_s_" + System.currentTimeMillis();
    system.setName(systemName);
    system = systemService.save(system);
    // system entity
    SysSystemEntityDto systemEntity = new SysSystemEntityDto();
    systemEntity.setUid("test");
    systemEntity.setSystem(system.getId());
    systemEntity.setEntityType(SystemEntityType.IDENTITY);
    systemEntity = systemEntityService.save(systemEntity);
    SysProvisioningOperationDto provisioningOperation = new SysProvisioningOperationDto();
    provisioningOperation.setSystem(system.getId());
    provisioningOperation.setEntityType(SystemEntityType.IDENTITY);
    provisioningOperation.setOperationType(ProvisioningEventType.CREATE);
    provisioningOperation.setSystemEntity(systemEntity.getId());
    provisioningOperation.setEntityIdentifier(UUID.randomUUID());
    provisioningOperation.setProvisioningContext(new ProvisioningContext());
    provisioningOperation.setResult(new OperationResult());
    provisioningOperationService.save(provisioningOperation);
    // 
    systemService.delete(system);
}
Also used : ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) 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 33 with SysSystemEntityDto

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

the class AbstractProvisioningExecutor method doInternalProvisioning.

@Override
public void doInternalProvisioning(AccAccountDto account, DTO dto) {
    Assert.notNull(account);
    Assert.notNull(dto);
    // 
    ProvisioningOperationType operationType;
    SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system, SysSystemDto.class);
    SysSystemEntityDto systemEntity = getSystemEntity(account);
    SystemEntityType entityType = SystemEntityType.getByClass(dto.getClass());
    String uid = account.getUid();
    // 
    if (systemEntity == null) {
        // prepare system entity - uid could be changed by provisioning, but
        // we need to link her with account
        // First we try find system entity with same uid.
        systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, entityType, uid);
        if (systemEntity == null) {
            systemEntity = new SysSystemEntityDto();
            systemEntity.setEntityType(entityType);
            systemEntity.setSystem(system.getId());
            systemEntity.setUid(uid);
            systemEntity.setWish(true);
            systemEntity = systemEntityService.save(systemEntity);
        }
        account.setSystemEntity(systemEntity.getId());
        account = accountService.save(account);
        // we wont create account, but after target system call can be
        // switched to UPDATE
        operationType = ProvisioningOperationType.CREATE;
    } else {
        // we wont update account, but after target system call can be
        // switched to CREATE
        operationType = ProvisioningOperationType.UPDATE;
    }
    List<AttributeMapping> finalAttributes = resolveMappedAttributes(account, dto, system, systemEntity.getEntityType());
    if (CollectionUtils.isEmpty(finalAttributes)) {
        // nothing to do - mapping is empty
        return;
    }
    doProvisioning(systemEntity, dto, dto.getId(), operationType, finalAttributes);
}
Also used : ProvisioningOperationType(eu.bcvsolutions.idm.acc.domain.ProvisioningOperationType) SysSystemAttributeMapping(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 34 with SysSystemEntityDto

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

the class DefaultSynchronizationService method resolveUnlinkedSituation.

@Override
public SysSyncItemLogDto resolveUnlinkedSituation(String uid, SystemEntityType entityType, UUID entityId, UUID configId, String actionType) {
    Assert.notNull(uid);
    Assert.notNull(entityType);
    Assert.notNull(configId);
    Assert.notNull(actionType);
    Assert.notNull(entityId);
    AbstractSysSyncConfigDto config = synchronizationConfigService.get(configId);
    SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
    SysSchemaObjectClassDto sysSchemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
    SysSystemDto system = DtoUtils.getEmbedded(sysSchemaObjectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
    SysSystemEntityDto systemEntity = findSystemEntity(uid, system, entityType);
    SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
    SynchronizationContext context = new SynchronizationContext();
    context.addUid(uid).addSystem(system).addConfig(config).addEntityType(entityType).addEntityId(entityId).addSystemEntity(systemEntity);
    getSyncExecutor(entityType).resolveUnlinkedSituation(SynchronizationUnlinkedActionType.valueOf(actionType), context);
    return itemLog;
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 35 with SysSystemEntityDto

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

the class BasicVirtualConnector method updateSystemEntity.

/**
 * We have to change system entity directly from VS module (request can be
 * started/executed async => standard process update UID in system entity (ACC
 * module) will not works!)
 *
 * @param uidValue
 * @param attributeUidValue
 * @param systemEntityMustExists
 */
private void updateSystemEntity(String uidValue, Object attributeUidValue, boolean systemEntityMustExists) {
    SysSystemEntityFilter systemEntityFilter = new SysSystemEntityFilter();
    systemEntityFilter.setUid(uidValue);
    systemEntityFilter.setSystemId(systemId);
    List<SysSystemEntityDto> systemEntities = systemEntityService.find(systemEntityFilter, null).getContent();
    if (systemEntities.isEmpty() && !systemEntityMustExists) {
        return;
    }
    if (systemEntities.isEmpty()) {
        throw new IcException(MessageFormat.format("System entity was not found for UID [{0}] and system ID [{1}]! Change UID attribute (new [{2}]) cannot be executed!", uidValue, systemId, attributeUidValue));
    }
    if (systemEntities.size() > 1) {
        throw new IcException(MessageFormat.format("For UID [{0}] and system ID [{1}] was found too many items [{2}]! Change UID attribute (new [{3}]) cannot be executed!", uidValue, systemId, systemEntities.size(), attributeUidValue));
    }
    SysSystemEntityDto systemEntity = systemEntities.get(0);
    systemEntity.setUid((String) attributeUidValue);
    systemEntity.setWish(false);
    // Save changed system entity
    systemEntityService.save(systemEntity);
    LOG.info("Update account - UID was changed (old: {} new: {}). System entity was updated.", uidValue, attributeUidValue);
}
Also used : IcException(eu.bcvsolutions.idm.ic.exception.IcException) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter)

Aggregations

SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)69 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)49 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)36 Test (org.junit.Test)36 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)25 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)22 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)19 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)15 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)14 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)14 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)13 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)12 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)12 SysProvisioningBatchDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto)11 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)10 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)10 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)10 IcObjectClassImpl (eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl)10 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)8 SysSystemEntityFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter)8