Search in sources :

Example 36 with SystemEntityType

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

the class AccountDeleteProcessor method process.

@Override
public EventResult<AccAccountDto> process(EntityEvent<AccAccountDto> event) {
    AccAccountDto account = event.getContent();
    UUID entityId = null;
    Object entityIdObj = event.getProperties().get(AccAccountService.ENTITY_ID_PROPERTY);
    if (entityIdObj instanceof UUID) {
        entityId = (UUID) entityIdObj;
    }
    boolean deleteTargetAccount = false;
    Object deleteTargetAccountObj = event.getProperties().get(AccAccountService.DELETE_TARGET_ACCOUNT_PROPERTY);
    if (deleteTargetAccountObj instanceof Boolean) {
        deleteTargetAccount = (boolean) deleteTargetAccountObj;
    }
    Assert.notNull(account, "Account cannot be null!");
    // We do not allow delete account in protection
    if (account.isAccountProtectedAndValid()) {
        throw new ResultCodeException(AccResultCode.ACCOUNT_CANNOT_BE_DELETED_IS_PROTECTED, ImmutableMap.of("uid", account.getUid()));
    }
    // delete all identity accounts
    AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
    identityAccountFilter.setAccountId(account.getId());
    List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(identityAccountFilter, null).getContent();
    identityAccounts.forEach(identityAccount -> {
        identityAccountService.delete(identityAccount);
    });
    // delete all role accounts
    AccRoleAccountFilter roleAccountFilter = new AccRoleAccountFilter();
    roleAccountFilter.setAccountId(account.getId());
    List<AccRoleAccountDto> roleAccounts = roleAccountService.find(roleAccountFilter, null).getContent();
    roleAccounts.forEach(roleAccount -> {
        roleAccountService.delete(roleAccount);
    });
    // delete all roleCatalogue accounts
    AccRoleCatalogueAccountFilter roleCatalogueAccountFilter = new AccRoleCatalogueAccountFilter();
    roleCatalogueAccountFilter.setAccountId(account.getId());
    List<AccRoleCatalogueAccountDto> roleCatalogueAccounts = roleCatalogueAccountService.find(roleCatalogueAccountFilter, null).getContent();
    roleCatalogueAccounts.forEach(roleCatalogueAccount -> {
        roleCatalogueAccountService.delete(roleCatalogueAccount);
    });
    // delete all tree accounts
    AccTreeAccountFilter treeAccountFilter = new AccTreeAccountFilter();
    treeAccountFilter.setAccountId(account.getId());
    List<AccTreeAccountDto> treeAccounts = treeAccountService.find(treeAccountFilter, null).getContent();
    treeAccounts.forEach(treeAccount -> {
        treeAccountService.delete(treeAccount);
    });
    // delete all contract accounts
    AccContractAccountFilter contractAccountFilter = new AccContractAccountFilter();
    contractAccountFilter.setAccountId(account.getId());
    List<AccContractAccountDto> contractAccounts = contractAccountService.find(contractAccountFilter, null).getContent();
    contractAccounts.forEach(contractAccount -> {
        contractAccountService.delete(contractAccount);
    });
    // delete all contract slice accounts
    AccContractSliceAccountFilter contractSliceAccountFilter = new AccContractSliceAccountFilter();
    contractSliceAccountFilter.setAccountId(account.getId());
    contractAccountSliceService.find(contractSliceAccountFilter, null).forEach(contractAccount -> {
        contractAccountSliceService.delete(contractAccount);
    });
    // 
    AccAccountDto refreshAccount = accountService.get(account.getId());
    // directly now
    if (refreshAccount != null) {
        accountService.deleteInternal(refreshAccount);
    }
    if (deleteTargetAccount && account.getEntityType() != null) {
        SystemEntityType entityType = account.getEntityType();
        if (!entityType.isSupportsProvisioning()) {
            LOG.warn(MessageFormat.format("Provisioning is not supported for [{1}] now [{0}]!", account.getUid(), entityType));
            return new DefaultEventResult<>(event, this);
        }
        LOG.debug(MessageFormat.format("Call delete provisioning for account with UID [{0}] and entity ID [{1}].", account.getUid(), entityId));
        // Create context for systemEntity in account DTO and set ID of role-request to it.
        UUID roleRequestId = this.getRoleRequestIdProperty(event.getProperties());
        this.initContext(account, roleRequestId);
        this.provisioningService.doDeleteProvisioning(account, account.getEntityType(), entityId);
    }
    return new DefaultEventResult<>(event, this);
}
Also used : AccRoleAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccRoleAccountFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AccContractAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter) AccContractAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractAccountDto) AccContractSliceAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter) AccTreeAccountDto(eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto) AccRoleAccountDto(eu.bcvsolutions.idm.acc.dto.AccRoleAccountDto) AccTreeAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccTreeAccountFilter) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) AccRoleCatalogueAccountDto(eu.bcvsolutions.idm.acc.dto.AccRoleCatalogueAccountDto) UUID(java.util.UUID) AccRoleCatalogueAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccRoleCatalogueAccountFilter)

Example 37 with SystemEntityType

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

the class DefaultSysProvisioningArchiveServiceIntegrationTest method resultStateFilterTest.

@Test
@Transactional
public void resultStateFilterTest() {
    SystemEntityType entityType = SystemEntityType.IDENTITY;
    SysSystemDto system = createSystem();
    OperationResult resultState = new OperationResult();
    resultState.setState(OperationState.CREATED);
    SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system);
    SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system);
    provisioningArchive2.setResult(resultState);
    service.save(provisioningArchive2);
    SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
    filter.setSystemId(system.getId());
    filter.setResultState(OperationState.CREATED);
    Page<SysProvisioningArchiveDto> result = service.find(filter, null);
    assertEquals(1, result.getTotalElements());
    assertFalse(result.getContent().contains(provisioningArchive1));
    assertTrue(result.getContent().contains(provisioningArchive2));
}
Also used : SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with SystemEntityType

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

the class DefaultSysProvisioningArchiveServiceIntegrationTest method entityIdentifierFilterTest.

@Test
@Transactional
public void entityIdentifierFilterTest() {
    SystemEntityType entityType = SystemEntityType.IDENTITY;
    SysSystemDto system = createSystem();
    createProvisioningArchive(entityType, system);
    SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system);
    provisioningArchive1.setEntityIdentifier(UUID.randomUUID());
    provisioningArchive1 = service.save(provisioningArchive1);
    SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system);
    SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
    filter.setEntityIdentifier(provisioningArchive1.getEntityIdentifier());
    Page<SysProvisioningArchiveDto> result = service.find(filter, null);
    assertEquals(1, result.getTotalElements());
    assertTrue(result.getContent().contains(provisioningArchive1));
    assertFalse(result.getContent().contains(provisioningArchive2));
}
Also used : SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with SystemEntityType

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

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

the class DefaultSysProvisioningArchiveServiceTest method entityIdentifierFilterTest.

@Test
public void entityIdentifierFilterTest() {
    IdmBasePermission permission = IdmBasePermission.ADMIN;
    SystemEntityType entityType = SystemEntityType.IDENTITY;
    SysSystemDto system = createRoleSystem();
    createProvisioningArchive(entityType, system);
    SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system);
    provisioningArchive1.setEntityIdentifier(UUID.randomUUID());
    provisioningArchive1 = archiveService.save(provisioningArchive1);
    SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system);
    SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
    filter.setEntityIdentifier(provisioningArchive1.getEntityIdentifier());
    Page<SysProvisioningArchiveDto> result = archiveService.find(filter, null, permission);
    assertEquals(1, result.getTotalElements());
    assertTrue(result.getContent().contains(provisioningArchive1));
    assertFalse(result.getContent().contains(provisioningArchive2));
}
Also used : SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)71 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)51 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)36 Test (org.junit.Test)36 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)28 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)28 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)26 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)21 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)17 UUID (java.util.UUID)17 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)15 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)15 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)15 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)13 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)11 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)11 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)11 AttributeMappingStrategyType (eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType)10 SysProvisioningArchiveDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto)10