Search in sources :

Example 41 with AccAccountDto

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

the class AbstractSynchronizationExecutor method doCreateLink.

/**
 * Create account and relation on him
 *
 * @param uid
 * @param callProvisioning
 * @param dto
 * @param systemEntity
 * @param entityType
 * @param system
 * @param logItem
 */
@SuppressWarnings("unchecked")
protected void doCreateLink(DTO dto, boolean callProvisioning, SynchronizationContext context) {
    String uid = context.getUid();
    SystemEntityType entityType = context.getEntityType();
    SysSystemDto system = context.getSystem();
    SysSyncItemLogDto logItem = context.getLogItem();
    SysSystemEntityDto systemEntity = context.getSystemEntity();
    // Generate UID value from mapped attribute marked as UID (Unique ID).
    // UID mapped attribute must exist and returned value must be not null
    // and must be String
    String attributeUid = this.generateUID(context);
    AccAccountDto account = doCreateIdmAccount(attributeUid, system);
    if (systemEntity != null) {
        // If SystemEntity for this account already exist, then we linked
        // him to new account
        account.setSystemEntity(systemEntity.getId());
    }
    account = accountService.save(account);
    addToItemLog(logItem, MessageFormat.format("Account with uid {0} and id {1} was created", uid, account.getId()));
    // Create new entity account relation
    EntityAccountDto entityAccount = this.createEntityAccount(account, dto, context);
    entityAccount = (EntityAccountDto) getEntityAccountService().save(entityAccount);
    context.addAccount(account);
    String entityIdentification = dto.getId().toString();
    if (dto instanceof Codeable) {
        entityIdentification = ((Codeable) dto).getCode();
    }
    // Identity account Created
    addToItemLog(logItem, MessageFormat.format("Entity account relation  with id ({0}), between account ({1}) and entity ({2}) was created", entityAccount.getId(), uid, entityIdentification));
    logItem.setDisplayName(entityIdentification);
    logItem.setType(entityAccount.getClass().getSimpleName());
    logItem.setIdentification(entityAccount.getId().toString());
    if (callProvisioning) {
        // Call provisioning for this identity
        callProvisioningForEntity(dto, entityType, logItem);
    }
}
Also used : Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 42 with AccAccountDto

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

the class AbstractSynchronizationExecutor method startReconciliation.

/**
 * Start reconciliation. Is call after synchronization. Main purpose is find and
 * resolve missing accounts
 *
 * @param entityType
 * @param systemAccountsMap
 * @param config
 * @param system
 * @param log
 * @param actionsLog
 */
protected void startReconciliation(SystemEntityType entityType, Set<String> allAccountsSet, AbstractSysSyncConfigDto config, SysSystemDto system, SysSyncLogDto log, List<SysSyncActionLogDto> actionsLog) {
    if (!log.isRunning()) {
        return;
    }
    AccAccountFilter accountFilter = new AccAccountFilter();
    accountFilter.setSystemId(system.getId());
    List<AccAccountDto> accounts = accountService.find(accountFilter, null).getContent();
    for (AccAccountDto account : accounts) {
        String uid = account.getRealUid();
        if (!allAccountsSet.contains(uid)) {
            SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
            try {
                // Default setting for log item
                itemLog.setIdentification(uid);
                itemLog.setDisplayName(uid);
                itemLog.setType(entityType.getEntityType().getSimpleName());
                // Do reconciliation for one item (produces event)
                // Start in new Transaction
                SynchronizationContext builder = new SynchronizationContext();
                builder.addUid(uid).addType(IcSyncDeltaTypeEnum.DELETE).addConfig(config).addSystem(system).addEntityType(entityType).addAccount(account).addLog(log).addLogItem(itemLog).addActionLogs(actionsLog);
                CoreEvent<SysSyncItemLogDto> event = new CoreEvent<SysSyncItemLogDto>(SynchronizationEventType.START_ITEM, itemLog);
                event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, builder);
                EventResult<SysSyncItemLogDto> lastResult = entityEventManager.process(event).getLastResult();
                boolean result = false;
                if (lastResult != null && lastResult.getEvent().getProperties().containsKey(SynchronizationService.RESULT_SYNC_ITEM)) {
                    result = (boolean) lastResult.getEvent().getProperties().get(SynchronizationService.RESULT_SYNC_ITEM);
                }
                // We reload log (maybe was synchronization canceled)
                log.setRunning(synchronizationLogService.get(log.getId()).isRunning());
                if (!log.isRunning()) {
                    result = false;
                }
                if (!result) {
                    log.setRunning(false);
                    log.addToLog(MessageFormat.format("Synchronization canceled during resolve UID [{0}]", uid));
                    addToItemLog(itemLog, "Canceled!");
                    initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.WARNING, itemLog, log, actionsLog);
                }
            } catch (Exception ex) {
                String message = MessageFormat.format("Reconciliation - error for uid {0}", uid);
                log.addToLog(message);
                log.addToLog(Throwables.getStackTraceAsString(ex));
                LOG.error(message, ex);
            } finally {
                config = synchronizationConfigService.save(config);
                boolean existingItemLog = existItemLogInActions(actionsLog, itemLog);
                actionsLog = saveActionLogs(actionsLog, log.getId());
                // 
                if (!existingItemLog) {
                    addToItemLog(itemLog, MessageFormat.format("Missing action log for UID {0}!", uid));
                    initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.ERROR, itemLog, log, actionsLog);
                    itemLog = syncItemLogService.save(itemLog);
                }
            }
        }
    }
}
Also used : SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException)

Example 43 with AccAccountDto

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

the class AbstractSynchronizationExecutor method doUpdateEntity.

/**
 * Fill data from IC attributes to entity (EAV and confidential storage too)
 *
 * @param account
 * @param entityType
 * @param uid
 * @param icAttributes
 * @param mappedAttributes
 * @param log
 * @param logItem
 * @param actionLogs
 */
protected void doUpdateEntity(SynchronizationContext context) {
    String uid = context.getUid();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
    AccAccountDto account = context.getAccount();
    List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
    UUID entityId = getEntityByAccount(account.getId());
    DTO entity = null;
    if (entityId != null) {
        entity = this.getService().get(entityId);
    }
    if (entity != null) {
        // Update entity
        entity = fillEntity(mappedAttributes, uid, icAttributes, entity, false, context);
        this.save(entity, true);
        // Update extended attribute (entity must be persisted first)
        updateExtendedAttributes(mappedAttributes, uid, icAttributes, entity, false, context);
        // Update confidential attribute (entity must be persisted
        // first)
        updateConfidentialAttributes(mappedAttributes, uid, icAttributes, entity, false, context);
        // Entity updated
        addToItemLog(logItem, MessageFormat.format("Entity with id {0} was updated", entity.getId()));
        if (logItem != null) {
            logItem.setDisplayName(this.getDisplayNameForEntity(entity));
        }
        // Call provisioning for entity
        this.callProvisioningForEntity(entity, context.getEntityType(), logItem);
        return;
    } else {
        addToItemLog(logItem, "Entity-account relation (with ownership = true) was not found!");
        initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
        return;
    }
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 44 with AccAccountDto

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

the class AbstractSynchronizationExecutor method resolveMissingEntitySituation.

/**
 * Method for resolve missing entity situation for one item.
 */
@Override
public void resolveMissingEntitySituation(SynchronizationMissingEntityActionType actionType, SynchronizationContext context) {
    String uid = context.getUid();
    SystemEntityType entityType = context.getEntityType();
    SysSystemDto system = context.getSystem();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
    List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
    addToItemLog(logItem, "Account and entity doesn't exist (missing entity).");
    switch(actionType) {
        case IGNORE:
            // Ignore we will do nothing
            addToItemLog(logItem, "Missing entity action is IGNORE, we will do nothing.");
            initSyncActionLog(SynchronizationActionType.MISSING_ENTITY, OperationResultType.IGNORE, logItem, log, actionLogs);
            return;
        case CREATE_ENTITY:
            // Generate UID value from mapped attribute marked as UID (Unique
            // ID).
            // UID mapped attribute must exist and returned value must be not
            // null and must be String
            String attributeUid = this.generateUID(context);
            // Create idm account
            AccAccountDto account = doCreateIdmAccount(attributeUid, system);
            // Find and set SystemEntity (must exist)
            account.setSystemEntity(this.findSystemEntity(uid, system, entityType).getId());
            account = accountService.save(account);
            // Create new entity
            doCreateEntity(entityType, mappedAttributes, logItem, uid, icAttributes, account, context);
            initSyncActionLog(SynchronizationActionType.CREATE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
    }
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 45 with AccAccountDto

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

the class DefaultAccAccountService method getAccount.

@Override
public AccAccountDto getAccount(String uid, UUID systemId) {
    Assert.notNull(uid, "UID cannot be null!");
    Assert.notNull(systemId, "System ID cannot be null!");
    AccAccountFilter filter = new AccAccountFilter();
    filter.setUid(uid);
    filter.setSystemId(systemId);
    List<AccAccountDto> accounts = this.find(filter, null).getContent();
    if (accounts.isEmpty()) {
        return null;
    }
    return accounts.get(0);
}
Also used : AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto)

Aggregations

AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)90 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)59 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)47 Test (org.junit.Test)45 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)44 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)33 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)29 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)25 AccAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter)19 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)18 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)18 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)16 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)16 ArrayList (java.util.ArrayList)16 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)15 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)14 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)14 UUID (java.util.UUID)14 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)13 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)13