Search in sources :

Example 86 with TestResource

use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangeSingleAttribute.

@Test
public void doIdentityProvisioningChangeSingleAttribute() {
    IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
    identity.setFirstName(IDENTITY_CHANGED_FIRST_NAME);
    identity = identityService.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 = identityAccountService.find(filter, null).getContent().get(0);
    AccAccountDto account = accountService.get(accountIdentityOne.getAccount());
    SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system);
    SysSystemEntityDto systemEntity = DtoUtils.getEmbedded(account, AccAccount_.systemEntity);
    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());
}
Also used : SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 87 with TestResource

use of eu.bcvsolutions.idm.acc.entity.TestResource 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());
}
Also used : AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 88 with TestResource

use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningServiceTest method testSendAttributeOnlyOnPasswordChange.

@Test
public void testSendAttributeOnlyOnPasswordChange() {
    Assert.assertTrue(provisioningConfiguration.isSendPasswordAttributesTogether());
    SysSystemDto system = helper.createTestResourceSystem(true);
    SysSystemMappingDto systemMapping = helper.getDefaultMapping(system);
    SysSystemAttributeMappingDto firstNameAttribute = systemAttributeMappingService.findBySystemMappingAndName(systemMapping.getId(), helper.getSchemaColumnName(TestHelper.ATTRIBUTE_MAPPING_FIRSTNAME));
    firstNameAttribute.setSendOnPasswordChange(Boolean.TRUE);
    systemAttributeMappingService.save(firstNameAttribute);
    IdmRoleDto role = helper.createRole();
    helper.createRoleSystem(role, system);
    IdmIdentityDto identity = helper.createIdentity();
    helper.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());
    // First name attribute is not set as "send only with password change" -> first name should be changed.
    String firstNameOne = getHelper().createName();
    identity.setFirstName(firstNameOne);
    identity = identityService.save(identity);
    TestResource resource = helper.findResource(account.getRealUid());
    Assert.assertNotNull(resource);
    Assert.assertEquals(firstNameOne, resource.getFirstname());
    // Set first name attribute as "send only with password change".
    firstNameAttribute.setSendOnlyOnPasswordChange(Boolean.TRUE);
    systemAttributeMappingService.save(firstNameAttribute);
    // First name attribute is set as "send only with password change" -> first name should be not changed.
    String firstNameTwo = getHelper().createName();
    identity.setFirstName(firstNameTwo);
    identity = identityService.save(identity);
    resource = helper.findResource(account.getRealUid());
    Assert.assertNotNull(resource);
    Assert.assertNotEquals(identity.getFirstName(), resource.getFirstname());
    Assert.assertEquals(firstNameOne, resource.getFirstname());
    // First name attribute should be send on password change.
    String newPassword = getHelper().createName();
    // Create new password one
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setAccounts(ImmutableList.of(account.getId().toString()));
    passwordChange.setNewPassword(new GuardedString(newPassword));
    passwordChange.setIdm(true);
    // Do change of password for selected accounts
    String firstNameChange = getHelper().createName();
    identity.setFirstName(firstNameChange);
    identityService.passwordChange(identity, passwordChange);
    // Check correct password One
    resource = helper.findResource(account.getRealUid());
    Assert.assertNotNull(resource);
    Assert.assertEquals(newPassword, resource.getPassword());
    Assert.assertEquals(firstNameChange, resource.getFirstname());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 89 with TestResource

use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangePasswordUnsupportSystem.

@Test
public void doIdentityProvisioningChangePasswordUnsupportSystem() {
    IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    AccIdentityAccountDto accountIdentityOne = identityAccountService.find(filter, null).getContent().get(0);
    SysSystemDto system = systemService.get(accountService.get(accountIdentityOne.getAccount()).getSystem());
    EntityEvent<SysSystemDto> event = new SystemEvent(SystemEventType.DUPLICATE, system);
    SysSystemDto clonedSystem = systemService.publish(event).getContent();
    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 = identityAccountService.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("newPWD12"));
    passwordChange.getAccounts().add(account.getId().toString());
    identityService.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 .. now this doesn't end with exception but with failed state
    passwordChange = new PasswordChangeDto();
    passwordChange.setNewPassword(new GuardedString("newPWDUnsupported"));
    passwordChange.getAccounts().add(account.getId().toString());
    List<OperationResult> results = identityService.passwordChange(identity, passwordChange);
    // for idm will be password changed executed with success state for system doesn't
    for (OperationResult result : results) {
        IdmAccountDto idmAccount = (IdmAccountDto) result.getModel().getParameters().get(IdmAccountDto.PARAMETER_NAME);
        String statusEnum = result.getModel().getStatusEnum();
        assertNotNull(statusEnum);
        assertNotNull(idmAccount);
        if (statusEnum.equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name())) {
            // idm
            assertNull(idmAccount.getSystemId());
            assertNull(idmAccount.getSystemName());
            continue;
        } else if (statusEnum.equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_FAILED.name())) {
            assertEquals(clonedSystem.getId(), idmAccount.getSystemId());
            assertEquals(clonedSystem.getName(), idmAccount.getSystemName());
            continue;
        }
        fail("Different result!");
    }
}
Also used : SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SystemEvent(eu.bcvsolutions.idm.acc.event.SystemEvent) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 90 with TestResource

use of eu.bcvsolutions.idm.acc.entity.TestResource 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());
}
Also used : SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)97 Test (org.junit.Test)83 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)81 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)69 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)51 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)50 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)36 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)32 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)32 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)30 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)27 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)26 ConfidentialString (eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString)19 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)17 SysSchemaAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter)12 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)12 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)12 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)11 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)10 Transactional (org.springframework.transaction.annotation.Transactional)10