use of eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationServiceTest method doStartSyncF_Unlinked_doLinkByEavAttribute.
@Test
public void doStartSyncF_Unlinked_doLinkByEavAttribute() {
// Prepare resource data
this.getBean().deleteAllResourceData();
this.getBean().initResourceData();
//
// call unlink
this.doStartSyncB_Linked_doUnLinked();
//
AbstractSysSyncConfigDto syncConfigCustom = setSyncConfigForEav(SYNC_CONFIG_NAME);
// Check state before sync
IdmIdentityDto identityOne = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE);
IdmIdentityDto identityTwo = identityService.getByUsername("x" + IDENTITY_USERNAME_TWO);
AccIdentityAccountFilter identityAccountFilterOne = new AccIdentityAccountFilter();
identityAccountFilterOne.setIdentityId(identityOne.getId());
Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements());
AccIdentityAccountFilter identityAccountFilterTwo = new AccIdentityAccountFilter();
identityAccountFilterTwo.setIdentityId(identityTwo.getId());
Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements());
// Start synchronization
synchornizationService.setSynchronizationConfigId(syncConfigCustom.getId());
synchornizationService.process();
//
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);
// log.getSyncActionLogs();
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.LINK == action.getSyncAction();
}).findFirst().get();
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
Assert.assertEquals(2, items.size());
// Check state after sync
Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements());
Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangeSingleAttribute.
@Test
public void doIdentityProvisioningChangeSingleAttribute() {
IdmIdentityDto identity = idmIdentityService.getByUsername(IDENTITY_USERNAME);
identity.setFirstName(IDENTITY_CHANGED_FIRST_NAME);
identity = idmIdentityService.save(identity);
Assert.assertEquals("Identity must have this first name!", IDENTITY_CHANGED_FIRST_NAME, identity.getFirstName());
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
filter.setSystemId(systemService.getByCode(SYSTEM_NAME).getId());
AccIdentityAccountDto accountIdentityOne = identityAccoutnService.find(filter, null).getContent().get(0);
AccAccountDto account = accountService.get(accountIdentityOne.getAccount());
SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system, SysSystemDto.class);
SysSystemEntityDto systemEntity = DtoUtils.getEmbedded(account, AccAccount_.systemEntity, SysSystemEntityDto.class);
SysSystemAttributeMappingFilter attributeFilter = new SysSystemAttributeMappingFilter();
attributeFilter.setSystemId(system.getId());
attributeFilter.setIdmPropertyName("firstName");
TestResource resourceAccount = entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME);
Assert.assertNotNull("Idenitity have to exists on target system (after account management)", resourceAccount);
Assert.assertEquals("Account on target system, must have same first name as Identity", IDENTITY_CHANGED_FIRST_NAME, resourceAccount.getFirstname());
provisioningService.doProvisioningForAttribute(systemEntity, systemAttributeMappingService.find(attributeFilter, null).getContent().get(0), IDENTITY_USERNAME, ProvisioningOperationType.UPDATE, identity);
resourceAccount = entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME);
Assert.assertNotNull("Idenitity have to exists on target system (after account management)", resourceAccount);
Assert.assertEquals("Account on target system, must have changed first name!", IDENTITY_USERNAME, resourceAccount.getFirstname());
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangePasswordUnsupportSystem.
@Test(expected = ProvisioningException.class)
public void doIdentityProvisioningChangePasswordUnsupportSystem() {
IdmIdentityDto identity = idmIdentityService.getByUsername(IDENTITY_USERNAME);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
AccIdentityAccountDto accountIdentityOne = identityAccoutnService.find(filter, null).getContent().get(0);
SysSystemDto system = systemService.get(accountService.get(accountIdentityOne.getAccount()).getSystem());
SysSystemDto clonedSystem = systemService.duplicate(system.getId());
clonedSystem.setReadonly(false);
clonedSystem.setDisabled(false);
clonedSystem = systemService.save(clonedSystem);
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemId(clonedSystem.getId());
SysSystemAttributeMappingDto passwordAttribute = systemAttributeMappingService.find(attributeMappingFilter, null).getContent().stream().filter(attribute -> {
return ProvisioningService.PASSWORD_SCHEMA_PROPERTY_NAME.equals(schemaAttributeService.get(attribute.getSchemaAttribute()).getName());
}).findFirst().orElse(null);
Assert.assertNotNull(passwordAttribute);
SysSystemAttributeMappingDto uidAttribute = systemAttributeMappingService.find(attributeMappingFilter, null).getContent().stream().filter(attribute -> {
return attribute.isUid();
}).findFirst().orElse(null);
Assert.assertNotNull(uidAttribute);
uidAttribute.setTransformToResourceScript("if(attributeValue){return \"y\"+ attributeValue;}");
uidAttribute = systemAttributeMappingService.save(uidAttribute);
SysSystemEntityDto sysEntity = new SysSystemEntityDto("y" + IDENTITY_USERNAME, SystemEntityType.IDENTITY);
sysEntity.setSystem(clonedSystem.getId());
sysEntity = systemEntityService.save(sysEntity);
AccAccountDto account = new AccAccountDto();
account.setSystem(clonedSystem.getId());
account.setUid("y" + IDENTITY_USERNAME);
account.setAccountType(AccountType.PERSONAL);
account.setEntityType(SystemEntityType.IDENTITY);
account.setSystemEntity(sysEntity.getId());
account = accountService.save(account);
AccIdentityAccountDto accountIdentity = new AccIdentityAccountDto();
accountIdentity.setIdentity(identity.getId());
accountIdentity.setOwnership(true);
accountIdentity.setAccount(account.getId());
accountIdentity = identityAccoutnService.save(accountIdentity);
provisioningService.doProvisioning(account);
TestResource createdAccount = entityManager.find(TestResource.class, accountService.get(accountIdentity.getAccount()).getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
String password = createdAccount.getPassword();
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setIdentityId(identity.getId());
accountFilter.setOwnership(Boolean.TRUE);
accountFilter.setSupportChangePassword(Boolean.TRUE);
// Two accounts supported change password expects
Assert.assertEquals(2, accountService.find(accountFilter, null).getContent().size());
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setNewPassword(new GuardedString("newPWD"));
passwordChange.getAccounts().add(account.getId().toString());
idmIdentityService.passwordChange(identity, passwordChange);
createdAccount = entityManager.find(TestResource.class, accountService.get(accountIdentity.getAccount()).getUid());
Assert.assertNotEquals(password, createdAccount.getPassword());
// After success password change, we delete password attribute.
systemAttributeMappingService.delete(passwordAttribute);
// One account supported change password expects
Assert.assertEquals(1, accountService.find(accountFilter, null).getContent().size());
// Change password .. must end with exception
passwordChange = new PasswordChangeDto();
passwordChange.setNewPassword(new GuardedString("newPWDUnsupported"));
passwordChange.getAccounts().add(account.getId().toString());
idmIdentityService.passwordChange(identity, passwordChange);
fail();
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangeAccountIdentifier.
/**
* Test for change account ID.
*/
@Test
public void doIdentityProvisioningChangeAccountIdentifier() {
IdmIdentityDto identity = idmIdentityService.getByUsername(IDENTITY_USERNAME_TWO);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
AccIdentityAccountDto accountIdentityOne = identityAccoutnService.find(filter, null).getContent().get(0);
AccAccountDto account = accountService.get(accountIdentityOne.getAccount());
identity.setUsername(IDENTITY_USERNAME_CHANGED);
identity = idmIdentityService.save(identity);
Assert.assertEquals("x" + IDENTITY_USERNAME_TWO, account.getUid());
provisioningService.doProvisioning(identity);
TestResource changedAccount = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertNotNull(changedAccount);
Assert.assertEquals(identity.getUsername(), changedAccount.getName().substring(1));
account = accountService.get(account.getId());
Assert.assertEquals("x" + IDENTITY_USERNAME_CHANGED, account.getUid());
Assert.assertEquals("x" + IDENTITY_USERNAME_CHANGED, account.getRealUid());
// Change username back
identity.setUsername(IDENTITY_USERNAME_TWO);
identity = idmIdentityService.save(identity);
account = accountService.get(account.getId());
Assert.assertEquals("x" + IDENTITY_USERNAME_TWO, account.getUid());
Assert.assertEquals("x" + IDENTITY_USERNAME_TWO, account.getRealUid());
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangeIdentityContract.
@Test
public void doIdentityProvisioningChangeIdentityContract() {
// change identity internally
IdmIdentityDto identity = idmIdentityService.getByUsername(IDENTITY_USERNAME);
identity.setFirstName("first-name-change");
identity = idmIdentityService.saveInternal(identity);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
IdmIdentityContractDto contract = identityContractService.getPrimeContract(identity.getId());
contract.setDescription("update");
identityContractService.save(contract);
AccIdentityAccountDto accountIdentityOne = identityAccoutnService.find(filter, null).getContent().get(0);
TestResource changedAccount = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertNotNull(changedAccount);
Assert.assertEquals(identity.getFirstName(), changedAccount.getFirstname());
identity.setFirstName(IDENTITY_CHANGED_FIRST_NAME);
identity = idmIdentityService.save(identity);
changedAccount = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertNotNull(changedAccount);
Assert.assertEquals(identity.getFirstName(), changedAccount.getFirstname());
}
Aggregations