use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class IdentitySynchronizationExecutor method createEntityAccount.
@Override
protected EntityAccountDto createEntityAccount(AccAccountDto account, IdmIdentityDto entity, SynchronizationContext context) {
Assert.notNull(account, "Account is required.");
Assert.notNull(entity, "Entity is required.");
EntityAccountDto entityAccount = super.createEntityAccount(account, entity, context);
Assert.isInstanceOf(AccIdentityAccountDto.class, entityAccount, "For identity sync must be entity-account relation instance of AccIdentityAccountDto!");
AccIdentityAccountDto identityAccount = (AccIdentityAccountDto) entityAccount;
SysSyncIdentityConfigDto config = this.getConfig(context);
SysSyncItemLogDto itemLog = context.getLogItem();
UUID defaultRoleId = config.getDefaultRole();
if (defaultRoleId == null) {
return identityAccount;
}
// Default role is defined
IdmRoleDto defaultRole = DtoUtils.getEmbedded(config, SysSyncIdentityConfig_.defaultRole);
Assert.notNull(defaultRole, "Default role must be found for this sync configuration!");
this.addToItemLog(itemLog, (MessageFormat.format("Default role [{1}] is defined and will be assigned to the identity [{0}].", entity.getCode(), defaultRole.getCode())));
List<IdmIdentityContractDto> contracts = Lists.newArrayList();
// Could be default role assigned to all valid or future valid contracts?
if (config.isAssignDefaultRoleToAll()) {
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setValidNowOrInFuture(Boolean.TRUE);
contractFilter.setIdentity(entity.getId());
contracts = identityContractService.find(contractFilter, null).getContent();
this.addToItemLog(itemLog, (MessageFormat.format("Default role will be assigned to all valid or future valid contracts, number of found contracts [{0}].", contracts.size())));
} else {
// Default role will be assigned only to prime contract
IdmIdentityContractDto primeContract = identityContractService.getPrimeValidContract(entity.getId());
if (primeContract != null) {
contracts.add(primeContract);
}
}
if (contracts.isEmpty()) {
SynchronizationInactiveOwnerBehaviorType inactiveOwnerBehavior = config.getInactiveOwnerBehavior();
if (SynchronizationInactiveOwnerBehaviorType.LINK_PROTECTED == inactiveOwnerBehavior) {
this.addToItemLog(itemLog, (MessageFormat.format("Default role is set, but it will not be assigned - no contract was found for identity [{0}]," + " so the account will be in protection.", entity.getCode())));
} else {
this.addToItemLog(itemLog, ("Warning! - Default role is set, but could not be assigned to identity, because the identity has not any suitable contract!"));
this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
}
return identityAccount;
}
List<IdmConceptRoleRequestDto> concepts = new ArrayList<>(contracts.size());
for (IdmIdentityContractDto contract : contracts) {
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setIdentityContract(contract.getId());
// filled automatically - prevent to provision future valid roles by default
concept.setValidFrom(contract.getValidFrom());
// #1887: its not filled automatically form contract (validity will be controlled by contract validity dynamically)
concept.setValidTill(null);
concept.setRole(defaultRole.getId());
concept.setOperation(ConceptRoleRequestOperation.ADD);
concepts.add(concept);
}
// Create role request for default role and primary contract
// Add skip of provisioning property. We don't want execute provisioning now, but after update of entity (only once).
Map<String, Serializable> properties = new LinkedHashMap<>();
properties.put(ProvisioningService.SKIP_PROVISIONING, Boolean.TRUE);
IdmRoleRequestDto roleRequest = roleRequestService.executeConceptsImmediate(entity.getId(), concepts, properties);
// Load concepts and try to find duplicate identity account
AccIdentityAccountDto duplicate = null;
IdmConceptRoleRequestFilter conceptFilter = new IdmConceptRoleRequestFilter();
conceptFilter.setRoleRequestId(roleRequest.getId());
for (IdmConceptRoleRequestDto concept : conceptRoleRequestService.find(conceptFilter, null)) {
UUID identityRoleId = concept.getIdentityRole();
Assert.notNull(identityRoleId, "Identity role relation had to been created!");
identityAccount.setIdentityRole(identityRoleId);
duplicate = this.findDuplicate(identityAccount);
if (duplicate != null) {
break;
}
}
if (duplicate != null) {
// This IdentityAccount is new and duplicated, we do not want create duplicated
// relation.
// Same IdentityAccount had to be created by assigned default role!
this.addToItemLog(itemLog, (MessageFormat.format("This identity-account (identity-role id: [{2}]) is new and duplicated, " + "we do not want create duplicated relation! " + "We will reuse already persisted identity-account [{3}]. " + "Probable reason: Same identity-account had to be created by assigned default role!", identityAccount.getAccount(), identityAccount.getIdentity(), identityAccount.getIdentityRole(), duplicate.getId())));
// Reusing duplicate
return duplicate;
}
return identityAccount;
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method checkSyncLog.
private SysSyncLogDto checkSyncLog(AbstractSysSyncConfigDto config, SynchronizationActionType actionType, int count, OperationResultType resultType) {
SysSyncConfigFilter logFilter = new SysSyncConfigFilter();
logFilter.setId(config.getId());
logFilter.setIncludeLastLog(Boolean.TRUE);
List<AbstractSysSyncConfigDto> configs = syncConfigService.find(logFilter, null).getContent();
Assert.assertEquals(1, configs.size());
SysSyncLogDto log = configs.get(0).getLastSyncLog();
if (actionType == null) {
return log;
}
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.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest 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();
List<SysSyncActionLogDto> actionLogs = actions.stream().filter(action -> {
return actionType == action.getSyncAction();
}).collect(Collectors.toList());
List<SysSyncItemLogDto> result = new ArrayList<>();
actionLogs.forEach(actionLog -> {
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
result.addAll(items);
});
Assert.assertEquals(count, result.size());
return log;
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class DefaultRoleSynchronizationServiceTest method doStartSyncB_Linked_doEntityUpdate.
@Test
public void doStartSyncB_Linked_doEntityUpdate() {
SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
configFilter.setName(SYNC_CONFIG_NAME);
List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
// Change node code to changed
this.getBean().changeOne();
Assert.assertEquals(1, syncConfigs.size());
AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
// Set sync config
syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY);
syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
syncConfigService.save(syncConfigCustom);
// Check state before sync
IdmRoleFilter roleFilter = new IdmRoleFilter();
roleFilter.setProperty(IdmRole_.code.getName());
roleFilter.setValue("1");
Assert.assertEquals("1", roleService.find(roleFilter, null).getContent().get(0).getDescription());
helper.startSynchronization(syncConfigCustom);
//
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
SysSyncLogDto log = logs.get(0);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
actionLogFilter.setSynchronizationLogId(log.getId());
List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
Assert.assertEquals(1, actions.size());
SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction();
}).findFirst().get();
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
Assert.assertEquals(5, items.size());
// Check state after sync
Assert.assertEquals(CHANGED, roleService.find(roleFilter, null).getContent().get(0).getDescription());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class DefaultRoleSynchronizationServiceTest method doStartSyncB_MissingAccount_DeleteEntity.
@Test
public void doStartSyncB_MissingAccount_DeleteEntity() {
SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
configFilter.setName(SYNC_CONFIG_NAME);
List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
// Remove node code to changed
this.getBean().removeOne();
Assert.assertEquals(1, syncConfigs.size());
AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
// Set sync config
syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.DELETE_ENTITY);
syncConfigCustom.setReconciliation(true);
syncConfigService.save(syncConfigCustom);
// Check state before sync
IdmRoleFilter roleFilter = new IdmRoleFilter();
roleFilter.setProperty(IdmRole_.code.getName());
roleFilter.setValue("1");
IdmRoleDto roleOne = roleService.find(roleFilter, null).getContent().get(0);
Assert.assertNotNull(roleOne);
helper.startSynchronization(syncConfigCustom);
//
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
SysSyncLogDto log = logs.get(0);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
actionLogFilter.setSynchronizationLogId(log.getId());
List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
Assert.assertEquals(2, actions.size());
SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
return SynchronizationActionType.DELETE_ENTITY == action.getSyncAction();
}).findFirst().get();
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
Assert.assertEquals(1, items.size());
// Check state after sync
roleOne = roleService.get(roleOne.getId());
Assert.assertNull(roleOne);
// Delete log
syncLogService.delete(log);
}
Aggregations