use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method checkSyncLog.
private SysSyncLogDto checkSyncLog(AbstractSysSyncConfigDto config, SynchronizationActionType actionType, int count) {
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(config.getId());
List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
SysSyncLogDto log = logs.get(0);
SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
actionLogFilter.setSynchronizationLogId(log.getId());
List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
return actionType == action.getSyncAction();
}).findFirst().get();
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
Assert.assertEquals(count, items.size());
return log;
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method updateAccountUid.
/**
* Update account UID from system. UID mapped attribute must exist and returned
* value must be not null and must be String
*
* @param context
*/
private void updateAccountUid(SynchronizationContext context) {
Assert.notNull(context, "Context is required!");
SysSyncItemLogDto logItem = context.getLogItem();
AccAccountDto account = context.getAccount();
// 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);
if (!account.getUid().equals(attributeUid)) {
addToItemLog(logItem, MessageFormat.format("IdM Account UID [{0}] is different [{1}]. We will update it.", account.getUid(), attributeUid));
account.setUid(attributeUid);
accountService.save(account);
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method resolveAccountNotExistSituation.
/**
* Resolve "Account doesn't exist in IDM" situation. Result can be UNLINKED or
* UNMATCHED situations.
*
* @param context
* @param systemEntity
* @param icAttributes
*/
protected void resolveAccountNotExistSituation(SynchronizationContext context, SysSystemEntityDto systemEntity, List<IcAttribute> icAttributes) {
Assert.notNull(context, "Context is required.");
AbstractSysSyncConfigDto config = context.getConfig();
SysSyncItemLogDto logItem = context.getLogItem();
addToItemLog(logItem, "Account doesn't exist in IdM");
DTO entity = findByCorrelationAttribute(systemAttributeMappingService.get(config.getCorrelationAttribute()), icAttributes, context);
if (entity != null) {
// Account not exist but, entity by correlation was
// found (UNLINKED)
context.addActionType(config.getUnlinkedAction().getAction());
SynchronizationSituationType situation = SynchronizationSituationType.UNLINKED;
if (StringUtils.hasLength(config.getUnlinkedActionWfKey())) {
SynchronizationUnlinkedActionType unlinkedActionType = config.getUnlinkedAction();
SynchronizationActionType action = unlinkedActionType.getAction();
// We will start specific workflow
startWorkflow(config.getUnlinkedActionWfKey(), situation, action, entity, context);
} else {
context.addEntityId(entity.getId()).addSystemEntity(systemEntity);
resolveUnlinkedSituation(config.getUnlinkedAction(), context);
}
} else {
// Account not exist and entity too (UNMATCHED)
context.addActionType(config.getMissingEntityAction().getAction());
SynchronizationSituationType situation = SynchronizationSituationType.MISSING_ENTITY;
if (StringUtils.hasLength(config.getMissingEntityActionWfKey())) {
SynchronizationMissingEntityActionType missingEntityAction = config.getMissingEntityAction();
SynchronizationActionType action = missingEntityAction.getAction();
// We will start specific workflow
startWorkflow(config.getMissingEntityActionWfKey(), situation, action, entity, context);
} else {
resolveMissingEntitySituation(config.getMissingEntityAction(), context);
}
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto 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 allAccountsSet
* @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) {
if (!log.isRunning()) {
return;
}
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<>(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);
}
// Update (increased counter) and check state of sync (maybe was cancelled from
// sync or LRT)
updateAndCheckState(result, log);
} 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);
syncItemLogService.save(itemLog);
}
}
}
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method resolveLinkedSituation.
/**
* Method for resolve linked situation for one item.
*
* @param action
* @param context
*/
@Override
public void resolveLinkedSituation(SynchronizationLinkedActionType action, SynchronizationContext context) {
SystemEntityType entityType = context.getEntityType();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
AccAccountDto account = context.getAccount();
addToItemLog(logItem, MessageFormat.format("IdM Account [{0}] exists in IDM (LINKED)", account.getUid()));
addToItemLog(logItem, MessageFormat.format("Linked action is [{0}]", action));
switch(action) {
case IGNORE:
// Linked action is IGNORE. We will do nothing
initSyncActionLog(SynchronizationActionType.LINKED, OperationResultType.IGNORE, logItem, log, actionLogs);
return;
case UNLINK:
// Linked action is UNLINK
updateAccountUid(context);
doUnlink(account, false, log, logItem, actionLogs);
initSyncActionLog(SynchronizationActionType.UNLINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
case UNLINK_AND_REMOVE_ROLE:
// Linked action is UNLINK_AND_REMOVE_ROLE
updateAccountUid(context);
doUnlink(account, true, log, logItem, actionLogs);
initSyncActionLog(SynchronizationActionType.UNLINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
case UPDATE_ENTITY:
// Linked action is UPDATE_ENTITY
updateAccountUid(context);
doUpdateEntity(context);
if (context.getConfig().isDifferentialSync() && !context.isEntityDifferent()) {
// If differential sync is enabled and this entity should be not updated, then
// set item to ignore action.
initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.IGNORE, logItem, log, actionLogs);
return;
}
initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
case UPDATE_ACCOUNT:
// Linked action is UPDATE_ACCOUNT
updateAccountUid(context);
doUpdateAccount(account, entityType, log, logItem, actionLogs);
initSyncActionLog(SynchronizationActionType.UPDATE_ACCOUNT, OperationResultType.SUCCESS, logItem, log, actionLogs);
default:
break;
}
}
Aggregations