Search in sources :

Example 1 with AccRoleCatalogueAccountDto

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

the class DefaultAccRoleCatalogueAccountService method delete.

@Override
@Transactional
public void delete(AccRoleCatalogueAccountDto entity, boolean deleteTargetAccount, BasePermission... permission) {
    Assert.notNull(entity, "Entity is required.");
    super.delete(entity, permission);
    UUID account = entity.getAccount();
    // We check if exists another (ownership) identityAccounts, if not
    // then
    // we will delete account
    AccRoleCatalogueAccountFilter filter = new AccRoleCatalogueAccountFilter();
    filter.setAccountId(account);
    filter.setOwnership(Boolean.TRUE);
    List<AccRoleCatalogueAccountDto> entityAccounts = this.find(filter, null).getContent();
    boolean moreEntityAccounts = entityAccounts.stream().filter(treeAccount -> {
        return treeAccount.isOwnership() && !treeAccount.equals(entity);
    }).findAny().isPresent();
    if (!moreEntityAccounts && entity.isOwnership()) {
        // We delete all tree accounts first
        entityAccounts.forEach(identityAccount -> {
            super.delete(identityAccount);
        });
        // Finally we can delete account
        accountService.publish(new AccountEvent(AccountEventType.DELETE, accountService.get(account), ImmutableMap.of(AccAccountService.DELETE_TARGET_ACCOUNT_PROPERTY, deleteTargetAccount, AccAccountService.ENTITY_ID_PROPERTY, entity.getEntity())));
    }
}
Also used : AccountEvent(eu.bcvsolutions.idm.acc.event.AccountEvent) AccRoleCatalogueAccountDto(eu.bcvsolutions.idm.acc.dto.AccRoleCatalogueAccountDto) UUID(java.util.UUID) AccRoleCatalogueAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccRoleCatalogueAccountFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with AccRoleCatalogueAccountDto

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

the class RoleCatalogueProvisioningExecutor method getAttributeValue.

@Override
protected Object getAttributeValue(String uid, IdmRoleCatalogueDto dto, AttributeMapping attribute, SysSystemDto system, MappingContext mappingContext) {
    Object idmValue = super.getAttributeValue(uid, dto, attribute, system, mappingContext);
    if (attribute.isEntityAttribute() && TreeSynchronizationExecutor.PARENT_FIELD.equals(attribute.getIdmPropertyName())) {
        // parent format (UID of parent)
        if (idmValue instanceof UUID) {
            // Generally we expect IdmRoleCatalogue as parent (we will do
            // transform)
            AccRoleCatalogueAccountFilter catalogueAccountFilter = new AccRoleCatalogueAccountFilter();
            catalogueAccountFilter.setSystemId(this.getSytemFromSchemaAttribute(attribute.getSchemaAttribute()).getId());
            catalogueAccountFilter.setEntityId((UUID) idmValue);
            List<AccRoleCatalogueAccountDto> treeAccounts = catalogueAccountService.find(catalogueAccountFilter, null).getContent();
            if (treeAccounts.isEmpty()) {
                throw new ProvisioningException(AccResultCode.PROVISIONING_TREE_PARENT_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentNode", idmValue));
            }
            if (treeAccounts.size() != 1) {
                throw new ProvisioningException(AccResultCode.PROVISIONING_TREE_TOO_MANY_PARENT_ACCOUNTS, ImmutableMap.of("parentNode", idmValue));
            }
            AccRoleCatalogueAccountDto treeAccount = treeAccounts.get(0);
            String parentUid = accountService.get(treeAccount.getAccount()).getUid();
            return parentUid;
        } else {
            // without any transform
            return idmValue;
        }
    }
    return idmValue;
}
Also used : ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) AccRoleCatalogueAccountDto(eu.bcvsolutions.idm.acc.dto.AccRoleCatalogueAccountDto) UUID(java.util.UUID) AccRoleCatalogueAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccRoleCatalogueAccountFilter)

Example 3 with AccRoleCatalogueAccountDto

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

the class RoleCatalogueSynchronizationExecutor method getValueByMappedAttribute.

@Override
protected Object getValueByMappedAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
    Object transformedValue = super.getValueByMappedAttribute(attribute, icAttributes, context);
    if (transformedValue != null && PARENT_FIELD.equals(attribute.getIdmPropertyName())) {
        String parentUid = transformedValue.toString();
        SysSystemMappingDto systemMapping = systemMappingService.get(((SysSystemAttributeMappingDto) attribute).getSystemMapping());
        try {
            UUID parentUUID = UUID.fromString(parentUid);
            IdmRoleCatalogueDto parentNode = catalogueService.get(parentUUID);
            if (parentNode != null) {
                addToItemLog(context.getLogItem(), MessageFormat.format("Transformed value from the parent attribute contains the UUID of idmRoleCatalogue [{0}].", parentNode.getCode()));
                return parentNode.getId();
            }
        } catch (IllegalArgumentException ex) {
            // OK this is not UUID of role catalogue
            addToItemLog(context.getLogItem(), MessageFormat.format("Parent value [{0}] is not UUID of a role catalogue.", parentUid));
        }
        SysSchemaObjectClassDto schemaObjectClass = schemaObjectClassService.get(systemMapping.getObjectClass());
        UUID systemId = schemaObjectClass.getSystem();
        // Find account by UID from parent field
        AccAccountFilter accountFilter = new AccAccountFilter();
        accountFilter.setUid(parentUid);
        accountFilter.setSystemId(systemId);
        List<AccAccountDto> parentAccounts = accountService.find(accountFilter, null).getContent();
        if (!parentAccounts.isEmpty()) {
            UUID parentAccount = parentAccounts.get(0).getId();
            // Find relation between catalogue and account
            AccRoleCatalogueAccountFilter catalogueAccountFilter = new AccRoleCatalogueAccountFilter();
            catalogueAccountFilter.setAccountId(parentAccount);
            List<AccRoleCatalogueAccountDto> catalogueAccounts = catalogueAccountService.find(catalogueAccountFilter, null).getContent();
            if (!catalogueAccounts.isEmpty()) {
                // Find parent role catalogue by ID
                // TODO: resolve more catalogueAccounts situations
                // parent uuid - we are working with dtos
                transformedValue = catalogueAccounts.get(0).getRoleCatalogue();
            } else {
                LOG.warn("For parent UID: [{}] on system ID [{}] and acc account: [{}], were not found catalogue accounts! Return null value in parent!!", parentUid, systemId, parentAccount);
                throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_ROLE_CATALOGUE_TREE_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentUid", parentUid, "systemId", systemId, "parentAccount", parentAccount));
            }
        } else {
            LOG.warn("For parent UID: [{}] on system ID [{}], was not found parents account! Return null value in parent!!", parentUid, systemId);
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_ROLE_CATALOGUE_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentUid", parentUid, "systemId", systemId));
        }
    }
    return transformedValue;
}
Also used : SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) AccRoleCatalogueAccountDto(eu.bcvsolutions.idm.acc.dto.AccRoleCatalogueAccountDto) UUID(java.util.UUID) AccRoleCatalogueAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccRoleCatalogueAccountFilter)

Example 4 with AccRoleCatalogueAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccRoleCatalogueAccountDto 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 5 with AccRoleCatalogueAccountDto

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

the class RoleCatalogueProvisioningExecutor method getAttributeValue.

@Override
protected Object getAttributeValue(String uid, IdmRoleCatalogueDto dto, AttributeMapping attribute) {
    Object idmValue = super.getAttributeValue(uid, dto, attribute);
    if (attribute.isEntityAttribute() && TreeSynchronizationExecutor.PARENT_FIELD.equals(attribute.getIdmPropertyName())) {
        // parent format (UID of parent)
        if (idmValue instanceof UUID) {
            // Generally we expect IdmRoleCatalogue as parent (we will do
            // transform)
            AccRoleCatalogueAccountFilter catalogueAccountFilter = new AccRoleCatalogueAccountFilter();
            catalogueAccountFilter.setSystemId(this.getSytemFromSchemaAttribute(attribute.getSchemaAttribute()).getId());
            catalogueAccountFilter.setEntityId((UUID) idmValue);
            List<AccRoleCatalogueAccountDto> treeAccounts = catalogueAccountService.find(catalogueAccountFilter, null).getContent();
            if (treeAccounts.isEmpty()) {
                throw new ProvisioningException(AccResultCode.PROVISIONING_TREE_PARENT_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentNode", idmValue));
            }
            if (treeAccounts.size() != 1) {
                throw new ProvisioningException(AccResultCode.PROVISIONING_TREE_TOO_MANY_PARENT_ACCOUNTS, ImmutableMap.of("parentNode", idmValue));
            }
            AccRoleCatalogueAccountDto treeAccount = treeAccounts.get(0);
            String parentUid = accountService.get(treeAccount.getAccount()).getUid();
            return parentUid;
        } else {
            // without any transform
            return idmValue;
        }
    }
    return idmValue;
}
Also used : ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) AccRoleCatalogueAccountDto(eu.bcvsolutions.idm.acc.dto.AccRoleCatalogueAccountDto) UUID(java.util.UUID) AccRoleCatalogueAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccRoleCatalogueAccountFilter)

Aggregations

AccRoleCatalogueAccountDto (eu.bcvsolutions.idm.acc.dto.AccRoleCatalogueAccountDto)6 AccRoleCatalogueAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccRoleCatalogueAccountFilter)6 UUID (java.util.UUID)5 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)3 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)2 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)1 AccContractAccountDto (eu.bcvsolutions.idm.acc.dto.AccContractAccountDto)1 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)1 AccRoleAccountDto (eu.bcvsolutions.idm.acc.dto.AccRoleAccountDto)1 AccTreeAccountDto (eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto)1 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1 AccAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter)1 AccContractAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter)1 AccContractSliceAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter)1 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)1 AccRoleAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccRoleAccountFilter)1 AccTreeAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccTreeAccountFilter)1 AccountEvent (eu.bcvsolutions.idm.acc.event.AccountEvent)1 IdmRoleCatalogueDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto)1