use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationServiceTest method doStartSyncD_Missing_Account_doCreateAccount.
@Test
public void doStartSyncD_Missing_Account_doCreateAccount() {
SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
configFilter.setName(SYNC_CONFIG_NAME);
List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
Assert.assertEquals(1, syncConfigs.size());
AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
// Create new identity THREE, with account
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername("x" + IDENTITY_USERNAME_THREE);
identity.setFirstName(IDENTITY_USERNAME_THREE);
identity.setLastName(IDENTITY_USERNAME_THREE);
identity = identityService.save(identity);
AccAccountDto accountOne = new AccAccountDto();
SysSystemMappingDto systemMapping = systemMappingService.get(syncConfigCustom.getSystemMapping());
SysSystemDto system = systemService.get(schemaObjectClassService.get(systemMapping.getObjectClass()).getSystem());
accountOne.setSystem(system.getId());
accountOne.setUid("x" + IDENTITY_USERNAME_THREE);
accountOne.setAccountType(AccountType.PERSONAL);
accountOne.setEntityType(SystemEntityType.IDENTITY);
accountOne = accountService.save(accountOne);
AccIdentityAccountDto accountIdentityOne = new AccIdentityAccountDto();
accountIdentityOne.setIdentity(identity.getId());
accountIdentityOne.setOwnership(true);
accountIdentityOne.setAccount(accountOne.getId());
accountIdentityOne = identityAccoutnService.save(accountIdentityOne);
// Set sync config
syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.CREATE_ACCOUNT);
syncConfigCustom.setReconciliation(true);
syncConfigService.save(syncConfigCustom);
// Check state before sync
Assert.assertNull(entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_THREE));
// Start synchronization
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.CREATE_ACCOUNT == 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
Assert.assertNotNull(entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_THREE));
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultAccTestHelper method createIdentityAccount.
@Override
public AccIdentityAccountDto createIdentityAccount(SysSystemDto system, IdmIdentityDto identity) {
AccAccountDto account = new AccAccountDto();
account.setSystem(system.getId());
account.setUid(identity.getUsername());
account.setAccountType(AccountType.PERSONAL);
account.setEntityType(SystemEntityType.IDENTITY);
account = accountService.save(account);
AccIdentityAccountDto accountIdentity = new AccIdentityAccountDto();
accountIdentity.setIdentity(identity.getId());
accountIdentity.setOwnership(true);
accountIdentity.setAccount(account.getId());
return identityAccountService.save(accountIdentity);
}
use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountManagementService method createAccountByRoleSystem.
/**
* Create Account by given roleSystem
*
* @param identity
* @param roleSystem
* @param identityAccountsToCreate
* @return
*/
private UUID createAccountByRoleSystem(IdmIdentityDto identity, SysRoleSystemDto roleSystem, List<AccIdentityAccountDto> identityAccountsToCreate) {
String uid = generateUID(identity, roleSystem);
// We try find account for same uid on same system
// First we try search same account in list for create new accounts
Optional<AccIdentityAccountDto> sameAccountOptional = identityAccountsToCreate.stream().filter(ia -> {
AccAccountDto account = accountService.get(ia.getAccount());
return account.getUid().equals(uid) && roleSystem.getId().equals(ia.getRoleSystem());
}).findFirst();
if (sameAccountOptional.isPresent()) {
return sameAccountOptional.get().getAccount();
}
UUID accountId = null;
// If account is not in the list accounts to create, then we will search in
// database
// Account management - can be the account created? - execute the script on the
// system mapping
SysSystemDto system = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.system, SysSystemDto.class);
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
if (mapping == null) {
return null;
}
if (!this.canBeAccountCreated(uid, identity, mapping, system)) {
LOG.info(MessageFormat.format("For entity [{0}] and entity type [{1}] cannot be created the account (on system [{2}])," + " because script \"Can be account created\" on the mapping returned \"false\"!", identity.getCode(), SystemEntityType.IDENTITY, system.getName()));
return null;
}
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setUid(uid);
accountFilter.setSystemId(roleSystem.getSystem());
List<AccAccountDto> sameAccounts = accountService.find(accountFilter, null).getContent();
if (CollectionUtils.isEmpty(sameAccounts)) {
// Create and persist new account
accountId = createAccount(uid, roleSystem);
} else {
// We use existed account
accountId = sameAccounts.get(0).getId();
}
return accountId;
}
use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountManagementService method resolveIdentityAccountForCreate.
/**
* Resolve Identity account - to create
*
* @param identity
* @param identityAccountList
* @param identityRoles
* @param identityAccountsToCreate
* @param identityAccountsToDelete
* @param resolvedRolesForCreate
*/
private void resolveIdentityAccountForCreate(IdmIdentityDto identity, List<AccIdentityAccountDto> identityAccountList, List<IdmIdentityRole> identityRoles, List<AccIdentityAccountDto> identityAccountsToCreate, List<AccIdentityAccountDto> identityAccountsToDelete) {
// Is role valid in this moment
identityRoles.stream().filter(identityRole -> {
return identityRole.isValid();
}).forEach(identityRole -> {
IdmRole role = identityRole.getRole();
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setRoleId(role.getId());
List<SysRoleSystemDto> roleSystems = roleSystemService.find(roleSystemFilter, null).getContent();
roleSystems.stream().filter(roleSystem -> {
// Filter out identity-accounts for same role-system, account (by UID)
return !identityAccountList.stream().filter(identityAccount -> {
if (roleSystem.getId().equals(identityAccount.getRoleSystem())) {
// Has identity account same uid as account?
String uid = generateUID(identity, roleSystem);
AccAccountDto account = AccIdentityAccountService.getEmbeddedAccount(identityAccount);
if (!uid.equals(account.getUid())) {
// We found identityAccount for same identity and roleSystem, but this
// identityAccount
// is link to Account with different UID. It's probably means definition of UID
// (transformation)\
// on roleSystem was changed. We have to delete this identityAccount.
identityAccountsToDelete.add(identityAccount);
}
}
return false;
}).findFirst().isPresent();
}).forEach(roleSystem -> {
// For this system we have to create new account
UUID accountId = createAccountByRoleSystem(identity, roleSystem, identityAccountsToCreate);
if (accountId == null) {
return;
}
// TODO: find the better place for this check
if (identityAccountList.stream().filter(identityAccount -> {
return identityAccount.getAccount().equals(accountId) && identityRole.getId().equals(identityAccount.getIdentityRole()) && roleSystem.getId().equals(identityAccount.getRoleSystem());
}).count() == 0) {
AccIdentityAccountDto identityAccount = new AccIdentityAccountDto();
identityAccount.setAccount(accountId);
identityAccount.setIdentity(identity.getId());
identityAccount.setIdentityRole(identityRole.getId());
identityAccount.setRoleSystem(roleSystem.getId());
// TODO: Add flag ownership to SystemRole and set here.
identityAccount.setOwnership(true);
identityAccountsToCreate.add(identityAccount);
}
});
});
}
use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultTestHelper method createIdentityAccount.
@Override
public AccIdentityAccountDto createIdentityAccount(SysSystemDto system, IdmIdentityDto identity) {
AccAccountDto account = new AccAccountDto();
account.setSystem(system.getId());
account.setUid(identity.getUsername());
account.setAccountType(AccountType.PERSONAL);
account = accountService.save(account);
AccIdentityAccountDto accountIdentity = new AccIdentityAccountDto();
accountIdentity.setIdentity(identity.getId());
accountIdentity.setOwnership(true);
accountIdentity.setAccount(account.getId());
return identityAccountService.save(accountIdentity);
}
Aggregations