use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method checkSyncLog.
private SysSyncLogDto checkSyncLog(AbstractSysSyncConfigDto config, SynchronizationActionType actionType, int count, OperationResultType resultType) {
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();
Assert.assertEquals(resultType, actionLog.getOperationResult());
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.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testEnableAutomaticRoleDuringSynchronization.
@Test
public void testEnableAutomaticRoleDuringSynchronization() {
// default initialization of system and all necessary things
SysSystemDto system = initData();
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
// we want start recalculation after synchronization
config.setStartAutoRoleRec(true);
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
this.getBean().deleteAllResourceData();
String testLastName = "test-last-name-same-" + System.currentTimeMillis();
String testFirstName = "test-first-name";
String user1 = "test-1-" + System.currentTimeMillis();
this.getBean().setTestData(user1, testFirstName, testLastName);
String user2 = "test-2-" + System.currentTimeMillis();
this.getBean().setTestData(user2, testFirstName, testLastName);
String user3 = "test-3-" + System.currentTimeMillis();
this.getBean().setTestData(user3, testFirstName, testLastName);
IdmRoleDto role1 = helper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = helper.createAutomaticRole(role1.getId());
helper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, user1);
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3, OperationResultType.WARNING);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityDto identity1 = identityService.getByUsername(user1);
IdmIdentityDto identity2 = identityService.getByUsername(user2);
IdmIdentityDto identity3 = identityService.getByUsername(user3);
// we must change username, after create contract is also save identity (change state)
identity1.setUsername(user1 + System.currentTimeMillis());
identity1 = identityService.save(identity1);
helper.createIdentityContact(identity1);
helper.createIdentityContact(identity2);
helper.createIdentityContact(identity3);
List<IdmIdentityRoleDto> identityRoles1 = identityRoleService.findAllByIdentity(identity1.getId());
List<IdmIdentityRoleDto> identityRoles2 = identityRoleService.findAllByIdentity(identity2.getId());
List<IdmIdentityRoleDto> identityRoles3 = identityRoleService.findAllByIdentity(identity3.getId());
assertEquals(0, identityRoles1.size());
assertEquals(0, identityRoles2.size());
assertEquals(0, identityRoles3.size());
// enable test processor
testIdentityProcessor.enable();
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
identityRoles1 = identityRoleService.findAllByIdentity(identity1.getId());
identityRoles2 = identityRoleService.findAllByIdentity(identity2.getId());
identityRoles3 = identityRoleService.findAllByIdentity(identity3.getId());
assertEquals(1, identityRoles1.size());
assertEquals(0, identityRoles2.size());
assertEquals(0, identityRoles3.size());
IdmIdentityRoleDto foundIdentityRole = identityRoles1.get(0);
assertEquals(automaticRole.getId(), foundIdentityRole.getRoleTreeNode());
// synchronization immediately recalculate is disabled
int size = testIdentityProcessor.getRolesByUsername(user1).size();
assertEquals(0, size);
size = testIdentityProcessor.getRolesByUsername(user2).size();
assertEquals(0, size);
size = testIdentityProcessor.getRolesByUsername(user3).size();
assertEquals(0, size);
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method handleIcObject.
/**
* Handle IC connector object
*
* @param tokenAttribute
* @param itemContext
* @return
*/
protected boolean handleIcObject(SynchronizationContext itemContext) {
Assert.notNull(itemContext);
String uid = itemContext.getUid();
IcConnectorObject icObject = itemContext.getIcObject();
AbstractSysSyncConfigDto config = itemContext.getConfig();
SysSyncLogDto log = itemContext.getLog();
List<SysSyncActionLogDto> actionLogs = itemContext.getActionLogs();
AttributeMapping tokenAttribute = itemContext.getTokenAttribute();
SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
// Synchronization by custom filter not supported DELETE
// event
IcSyncDeltaTypeEnum type = IcSyncDeltaTypeEnum.CREATE_OR_UPDATE;
itemContext.addLogItem(itemLog).addType(type);
// Find token by token attribute
// For Reconciliation can be token attribute null
Object tokenObj = null;
if (tokenAttribute != null) {
tokenObj = getValueByMappedAttribute(tokenAttribute, icObject.getAttributes(), itemContext);
}
// Token is saved in Sync as String, therefore we transform token (from
// IcObject) to String too.
String token = tokenObj != null ? tokenObj.toString() : null;
if (token != null && config.getToken() != null && token.compareTo(config.getToken()) <= -1) {
token = config.getToken();
}
// Save token
log.setToken(token);
config.setToken(token);
boolean result = startItemSynchronization(itemContext);
// We reload log (maybe was synchronization canceled)
longRunningTaskExecutor.increaseCounter();
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.IGNORE, OperationResultType.WARNING, itemLog, log, actionLogs);
}
return result;
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method exportEntity.
/**
* Start export item (entity) to target resource
*
* @param itemBuilder
* @param uidAttribute
* @param entity
*/
protected void exportEntity(SynchronizationContext itemBuilder, SysSystemAttributeMappingDto uidAttribute, AbstractDto entity) {
SystemEntityType entityType = itemBuilder.getEntityType();
AbstractSysSyncConfigDto config = itemBuilder.getConfig();
SysSyncLogDto log = itemBuilder.getLog();
List<SysSyncActionLogDto> actionsLog = itemBuilder.getActionLogs();
SysSystemDto system = itemBuilder.getSystem();
SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
try {
// Default setting for log item
itemLog.setIdentification(entity.getId().toString());
itemLog.setDisplayName(this.getDisplayNameForEntity(entity));
itemLog.setType(entityType.getEntityType().getSimpleName());
itemLog.addToLog(MessageFormat.format("Start export for entity [{0}].", this.getDisplayNameForEntity(entity)));
UUID accountId = this.getAccountByEntity(entity.getId(), system.getId());
if (accountId != null) {
initSyncActionLog(SynchronizationActionType.CREATE_ACCOUNT, OperationResultType.IGNORE, itemLog, log, actionsLog);
itemLog.addToLog(MessageFormat.format("For entity [{0}] was found AccAccount [{1}]. Export for this entity ends (only entity without AccAccount can be export)!", this.getDisplayNameForEntity(entity), accountId));
return;
}
String uid = systemAttributeMappingService.generateUid(entity, uidAttribute);
// Do export for one item (produces event)
// Start in new Transaction
//
itemBuilder.addUid(uid).addConfig(//
config).addSystem(//
system).addEntityType(//
entityType).addEntityId(entity.getId()).addLog(//
log).addLogItem(//
itemLog).addActionLogs(//
actionsLog).addExportAction(true);
CoreEvent<SysSyncItemLogDto> event = new CoreEvent<SysSyncItemLogDto>(SynchronizationEventType.START_ITEM, itemLog);
event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, itemBuilder);
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("Export - error for entity {0}", entity.getId());
log.addToLog(message);
log.addToLog(Throwables.getStackTraceAsString(ex));
LOG.error(message, ex);
} finally {
config = synchronizationConfigService.save(config);
boolean existingItemLog = existItemLogInActions(actionsLog, itemLog);
actionsLog = (List<SysSyncActionLogDto>) syncActionLogService.saveAll(actionsLog);
//
if (!existingItemLog) {
addToItemLog(itemLog, MessageFormat.format("Missing action log for entity {0}!", entity.getId()));
initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.ERROR, itemLog, log, actionsLog);
itemLog = syncItemLogService.save(itemLog);
}
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method doItemSynchronization.
@Override
public boolean doItemSynchronization(SynchronizationContext context) {
Assert.notNull(context);
String uid = context.getUid();
IcConnectorObject icObject = context.getIcObject();
IcSyncDeltaTypeEnum type = context.getType();
AbstractSysSyncConfigDto config = context.getConfig();
SysSystemDto system = context.getSystem();
SystemEntityType entityType = context.getEntityType();
AccAccountDto account = context.getAccount();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
// Set default unknown action type
context.addActionType(SynchronizationActionType.UNKNOWN);
try {
// Find system entity for uid
SysSystemEntityDto systemEntity = findSystemEntity(uid, system, entityType);
context.addSystemEntity(systemEntity);
// Find acc account for uid or system entity
if (account == null) {
account = findAccount(context);
if (systemEntity == null) {
addToItemLog(logItem, "SystemEntity for this uid doesn't exist. We will create it.");
systemEntity = createSystemEntity(uid, entityType, system);
}
}
context.addSystemEntity(systemEntity).addAccount(account);
if (IcSyncDeltaTypeEnum.CREATE == type || IcSyncDeltaTypeEnum.UPDATE == type || IcSyncDeltaTypeEnum.CREATE_OR_UPDATE == type) {
// Update or create
Assert.notNull(icObject);
List<IcAttribute> icAttributes = icObject.getAttributes();
if (account == null) {
// Account doesn't exist in IDM
resolveAccountNotExistSituation(context, systemEntity, icAttributes);
} else {
// Account exist in IdM (LINKED)
context.addActionType(config.getLinkedAction().getAction());
SynchronizationSituationType situation = SynchronizationSituationType.LINKED;
if (StringUtils.hasLength(config.getLinkedActionWfKey())) {
SynchronizationLinkedActionType linkedAction = config.getLinkedAction();
SynchronizationActionType action = linkedAction.getAction();
// We will start specific workflow
startWorkflow(config.getLinkedActionWfKey(), situation, action, null, context);
} else {
resolveLinkedSituation(config.getLinkedAction(), context);
}
addToItemLog(logItem, "Account exist in IdM (LINKED) - ended");
}
} else if (IcSyncDeltaTypeEnum.DELETE == type) {
// Missing account situation, can be call from connector
// (support delete account event) and from reconciliation
context.addActionType(config.getMissingAccountAction().getAction());
SynchronizationSituationType situation = SynchronizationSituationType.MISSING_ACCOUNT;
if (StringUtils.hasLength(config.getMissingAccountActionWfKey())) {
ReconciliationMissingAccountActionType missingAccountActionType = config.getMissingAccountAction();
SynchronizationActionType action = missingAccountActionType.getAction();
// We will start specific workflow
startWorkflow(config.getMissingAccountActionWfKey(), situation, action, null, context);
} else {
// Resolve missing account situation for one item
this.resolveMissingAccountSituation(config.getMissingAccountAction(), context);
}
} else if (context.isExportAction()) {
// Export situation - create account to system
this.resolveUnlinkedSituation(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ACCOUNT, context);
}
// Call hard hibernate session flush and clear
if (getHibernateSession().isOpen()) {
getHibernateSession().flush();
getHibernateSession().clear();
}
return true;
} catch (Exception e) {
loggingException(context.getActionType(), log, logItem, actionLogs, uid, e);
throw e;
}
}
Aggregations