use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method prepareAccount.
private AccIdentityAccountDto prepareAccount(IdmIdentityDto identity) {
AccAccountDto accountOne = new AccAccountDto();
accountOne.setSystem(getSystem().getId());
accountOne.setUid("x" + identity.getUsername());
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());
//
return identityAccountService.save(accountIdentityOne);
}
use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangeManagersContract.
/**
* Call provisioning for subordinates, after managers's contract changes - filled managers could be provisioned
*/
@Test
public void doIdentityProvisioningChangeManagersContract() {
IdmIdentityDto managerOne = createIdentity();
IdmIdentityDto subordinateOne = createIdentity();
IdmTreeNodeDto managerOnePosition = createTreeNode(null);
IdmIdentityContractDto managersContract = createIdentityContact(managerOne, managerOnePosition);
IdmTreeNodeDto subordinateOnePositionOne = createTreeNode(managerOnePosition);
createIdentityContact(subordinateOne, subordinateOnePositionOne);
AccIdentityAccountDto subordinateAccount = prepareAccount(subordinateOne);
//
provisioningService.doProvisioning(DtoUtils.getEmbedded(subordinateAccount, AccIdentityAccount_.identity, IdmIdentityDto.class));
//
TestResource account = entityManager.find(TestResource.class, accountService.get(subordinateAccount.getAccount()).getUid());
Assert.assertNotNull(account);
Assert.assertEquals(subordinateOne.getFirstName(), account.getFirstname());
//
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setSubordinatesFor(managerOne.getId());
List<IdmIdentityDto> subordinates = identityService.find(filter, null).getContent();
Assert.assertEquals(1, subordinates.size());
Assert.assertEquals(subordinateOne.getId(), subordinates.get(0).getId());
//
// change subordinate
subordinateOne.setFirstName("first-name-change-one");
subordinateOne = identityService.saveInternal(subordinateOne);
//
// change managers contract
managersContract.setWorkPosition(null);
managersContract = identityContractService.save(managersContract);
//
account = entityManager.find(TestResource.class, accountService.get(subordinateAccount.getAccount()).getUid());
Assert.assertNotNull(account);
Assert.assertEquals(subordinateOne.getFirstName(), account.getFirstname());
subordinates = identityService.find(filter, null).getContent();
Assert.assertEquals(0, subordinates.size());
//
// change subordinate again
subordinateOne.setFirstName("first-name-change-two");
subordinateOne = identityService.saveInternal(subordinateOne);
//
managersContract.setWorkPosition(managerOnePosition.getId());
managersContract = identityContractService.save(managersContract);
//
account = entityManager.find(TestResource.class, accountService.get(subordinateAccount.getAccount()).getUid());
Assert.assertNotNull(account);
Assert.assertEquals(subordinateOne.getFirstName(), account.getFirstname());
subordinates = identityService.find(filter, null).getContent();
Assert.assertEquals(1, subordinates.size());
Assert.assertEquals(subordinateOne.getId(), subordinates.get(0).getId());
}
use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningStrategyIfNull.
@Test
public void doIdentityProvisioningStrategyIfNull() {
IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
AccIdentityAccountDto accountIdentityOne = identityAccountService.find(filter, null).getContent().get(0);
// Default email strategy is CREATE, we check value
TestResource resourceAccoutn = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertEquals(EMAIL_ONE, resourceAccoutn.getEmail());
SysSystemAttributeMappingFilter filterSchemaAttr = new SysSystemAttributeMappingFilter();
filterSchemaAttr.setIdmPropertyName("email");
filterSchemaAttr.setSystemId(accountService.get(accountIdentityOne.getAccount()).getSystem());
SysSystemAttributeMappingDto attributeHandling = systemAttributeMappingService.find(filterSchemaAttr, null).getContent().get(0);
attributeHandling.setEntityAttribute(true);
attributeHandling.setStrategyType(AttributeMappingStrategyType.WRITE_IF_NULL);
attributeHandling.setTransformToResourceScript("return \"" + EMAIL_TWO + "\";");
systemAttributeMappingService.save(attributeHandling);
// Do provisioning
provisioningService.doProvisioning(identity);
// Email strategy is WRITE_IF_NULL ... email in account must not have new value
resourceAccoutn = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertNotEquals(EMAIL_TWO, resourceAccoutn.getEmail());
attributeHandling.setEntityAttribute(true);
attributeHandling.setStrategyType(AttributeMappingStrategyType.SET);
attributeHandling.setTransformToResourceScript("return \"" + EMAIL_TWO + "\";");
systemAttributeMappingService.save(attributeHandling);
// Do provisioning
provisioningService.doProvisioning(identity);
// Email strategy is SET ... email in account must have new value
resourceAccoutn = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertEquals(EMAIL_TWO, resourceAccoutn.getEmail());
}
use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangeIdentityContract.
@Test
public void doIdentityProvisioningChangeIdentityContract() {
// change identity internally
IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
identity.setFirstName("first-name-change");
identity = identityService.saveInternal(identity);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
IdmIdentityContractDto contract = identityContractService.getPrimeContract(identity.getId());
contract.setDescription("update");
identityContractService.save(contract);
AccIdentityAccountDto accountIdentityOne = identityAccountService.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 = identityService.save(identity);
changedAccount = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertNotNull(changedAccount);
Assert.assertEquals(identity.getFirstName(), changedAccount.getFirstname());
}
use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangeAccountIdentifier.
/**
* Test for change account ID.
*/
@Test
public void doIdentityProvisioningChangeAccountIdentifier() {
IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME_TWO);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
AccIdentityAccountDto accountIdentityOne = identityAccountService.find(filter, null).getContent().get(0);
AccAccountDto account = accountService.get(accountIdentityOne.getAccount());
identity.setUsername(IDENTITY_USERNAME_CHANGED);
identity = identityService.save(identity);
Assert.assertEquals("x" + IDENTITY_USERNAME_TWO, account.getUid());
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 = identityService.save(identity);
account = accountService.get(account.getId());
Assert.assertEquals("x" + IDENTITY_USERNAME_TWO, account.getUid());
Assert.assertEquals("x" + IDENTITY_USERNAME_TWO, account.getRealUid());
}
Aggregations