use of eu.bcvsolutions.idm.acc.entity.TestResource 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());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method testUpdateWishIfSystemEntityExists.
@Test
public void testUpdateWishIfSystemEntityExists() {
String username = getHelper().createName();
SysSystemDto system = getHelper().createTestResourceSystem(true);
//
// prepare resource
IdmIdentityDto identity = getHelper().createIdentity(username, (GuardedString) null);
TestResource resource = new TestResource();
resource.setName(username);
resource.setFirstname(identity.getFirstName());
resource.setLastname(identity.getLastName());
// TODO: test constant
resource.setStatus("enabled");
resource = getHelper().saveResource(resource);
//
// prepare identity with account on target system with the same system entity as prepared
IdmRoleDto role = getHelper().createRole();
getHelper().createRoleSystem(role, system);
getHelper().createIdentityRole(identity, role);
//
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
AccIdentityAccountDto accountIdentityOne = identityAccountService.find(filter, null).getContent().get(0);
AccAccountDto account = accountService.get(accountIdentityOne.getAccount());
//
SysSystemEntityDto systemEntity = DtoUtils.getEmbedded(account, AccAccount_.systemEntity);
//
resource = helper.findResource(account.getRealUid());
//
Assert.assertFalse(systemEntity.isWish());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource 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.entity.TestResource in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningExtendedAttribute.
@Test
public void doIdentityProvisioningExtendedAttribute() {
IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
AccIdentityAccountDto accountIdentityOne = identityAccountService.find(filter, null).getContent().get(0);
// We will use firstName attribute (password attribute is not returned
// by default)
SysSystemAttributeMappingFilter filterSchemaAttr = new SysSystemAttributeMappingFilter();
filterSchemaAttr.setIdmPropertyName("firstName");
filterSchemaAttr.setSystemId(accountService.get(accountIdentityOne.getAccount()).getSystem());
SysSystemAttributeMappingDto attributeHandling = systemAttributeMappingService.find(filterSchemaAttr, null).getContent().get(0);
// Set attribute to extended attribute and modify idmPropety to
// extPassword
attributeHandling.setIdmPropertyName(IDENTITY_EXT_PASSWORD);
attributeHandling.setExtendedAttribute(true);
attributeHandling.setConfidentialAttribute(true);
attributeHandling.setEntityAttribute(false);
attributeHandling.setTransformToResourceScript("return attributeValue");
// Form attribute definition will be created during save attribute
// handling
attributeHandling = systemAttributeMappingService.save(attributeHandling);
// Create extended attribute value for password
IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
List<IdmFormValueDto> values = new ArrayList<>();
IdmFormValueDto phoneValue = new IdmFormValueDto();
phoneValue.setFormAttribute(formDefinition.getMappedAttributeByCode(IDENTITY_EXT_PASSWORD).getId());
phoneValue.setPersistentType(PersistentType.SHORTTEXT);
phoneValue.setValue(IDENTITY_PASSWORD_THREE);
values.add(phoneValue);
formService.saveValues(identity, formDefinition, values);
// save account
provisioningService.doProvisioning(identity);
TestResource resourceAccoutn = entityManager.find(TestResource.class, accountService.get(accountIdentityOne.getAccount()).getUid());
Assert.assertEquals(IDENTITY_PASSWORD_THREE, resourceAccoutn.getFirstname());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationServiceTest method addIdentityThreeToResourceData.
@Transactional
public void addIdentityThreeToResourceData() {
// Change data on resource
// Insert data to testResource table
TestResource resourceUser = new TestResource();
resourceUser.setName("x" + IDENTITY_USERNAME_THREE);
resourceUser.setFirstname(IDENTITY_USERNAME_THREE);
resourceUser.setLastname(IDENTITY_USERNAME_THREE);
resourceUser.setEmail(IDENTITY_EMAIL_CORRECT);
resourceUser.setEavAttribute("3");
entityManager.persist(resourceUser);
}
Aggregations