Search in sources :

Example 81 with AccAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccAccountDto 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());
}
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 82 with AccAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccAccountDto 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();
}
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) 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) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) 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 83 with AccAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccAccountDto 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());
}
Also used : 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) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 84 with AccAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccAccountDto 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 identityAccoutnService.save(accountIdentityOne);
}
Also used : AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)

Example 85 with AccAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningServiceTest method initData.

private void initData() {
    IdmIdentityDto identity;
    AccAccountDto accountOne;
    AccIdentityAccountDto accountIdentityOne;
    // create test system
    SysSystemDto system = helper.createSystem(TestResource.TABLE_NAME, SYSTEM_NAME);
    // set default generate password policy for system
    IdmPasswordPolicyDto passwordPolicy = new IdmPasswordPolicyDto();
    passwordPolicy.setName(PASSWORD_POLICY);
    passwordPolicy.setType(IdmPasswordPolicyType.GENERATE);
    passwordPolicy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    passwordPolicy.setLowerCharBase("a");
    passwordPolicy.setMinPasswordLength(2);
    passwordPolicy.setMaxPasswordLength(2);
    passwordPolicy.setMinLowerChar(2);
    passwordPolicy = passwordPolicyService.save(passwordPolicy);
    system.setPasswordPolicyGenerate(passwordPolicy.getId());
    system = systemService.save(system);
    // generate schema for system
    List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
    // Create test identity for provisioning test
    identity = new IdmIdentityDto();
    identity.setUsername(IDENTITY_USERNAME);
    identity.setFirstName(IDENTITY_USERNAME);
    identity.setLastName(IDENTITY_USERNAME);
    identity = idmIdentityService.save(identity);
    accountOne = new AccAccountDto();
    accountOne.setSystem(system.getId());
    accountOne.setUid("x" + IDENTITY_USERNAME);
    accountOne.setAccountType(AccountType.PERSONAL);
    accountOne.setEntityType(SystemEntityType.IDENTITY);
    accountOne = accountService.save(accountOne);
    accountIdentityOne = new AccIdentityAccountDto();
    accountIdentityOne.setIdentity(identity.getId());
    accountIdentityOne.setOwnership(true);
    accountIdentityOne.setAccount(accountOne.getId());
    accountIdentityOne = identityAccoutnService.save(accountIdentityOne);
    IdmIdentityDto identityTwo = new IdmIdentityDto();
    identityTwo.setUsername(IDENTITY_USERNAME_TWO);
    identityTwo.setFirstName(IDENTITY_USERNAME_TWO);
    identityTwo.setLastName(IDENTITY_USERNAME_TWO);
    identityTwo = idmIdentityService.save(identityTwo);
    AccAccountDto accountTwo = new AccAccountDto();
    accountTwo.setSystem(system.getId());
    accountTwo.setUid("x" + IDENTITY_USERNAME_TWO);
    accountTwo.setAccountType(AccountType.PERSONAL);
    accountTwo.setEntityType(SystemEntityType.IDENTITY);
    accountTwo = accountService.save(accountTwo);
    AccIdentityAccountDto accountIdentityTwo = new AccIdentityAccountDto();
    accountIdentityTwo.setIdentity(identityTwo.getId());
    accountIdentityTwo.setOwnership(true);
    accountIdentityTwo.setAccount(accountTwo.getId());
    accountIdentityTwo = identityAccoutnService.save(accountIdentityTwo);
    SysSystemMappingDto systemMapping = new SysSystemMappingDto();
    systemMapping.setName("default_" + System.currentTimeMillis());
    systemMapping.setEntityType(SystemEntityType.IDENTITY);
    systemMapping.setOperationType(SystemOperationType.PROVISIONING);
    systemMapping.setObjectClass(objectClasses.get(0).getId());
    final SysSystemMappingDto entityHandlingResult = systemEntityHandlingService.save(systemMapping);
    SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
    schemaAttributeFilter.setSystemId(system.getId());
    Page<SysSchemaAttributeDto> schemaAttributesPage = schemaAttributeService.find(schemaAttributeFilter, null);
    schemaAttributesPage.forEach(schemaAttr -> {
        if ("__NAME__".equals(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setUid(true);
            attributeMapping.setEntityAttribute(true);
            attributeMapping.setIdmPropertyName(IdmIdentity_.username.getName());
            attributeMapping.setTransformToResourceScript("if(attributeValue){return \"x\"+ attributeValue;}");
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setSystemMapping(entityHandlingResult.getId());
            attributeMapping = systemAttributeMappingService.save(attributeMapping);
        } else if ("firstname".equalsIgnoreCase(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setIdmPropertyName(IdmIdentity_.firstName.getName());
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setTransformFromResourceScript("if(attributeValue){return attributeValue.substring(1);}");
            attributeMapping.setSystemMapping(entityHandlingResult.getId());
            attributeMapping = systemAttributeMappingService.save(attributeMapping);
        } else if ("lastname".equalsIgnoreCase(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setIdmPropertyName(IdmIdentity_.lastName.getName());
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setSystemMapping(entityHandlingResult.getId());
            attributeMapping = systemAttributeMappingService.save(attributeMapping);
        } else if (IcConnectorFacade.PASSWORD_ATTRIBUTE_NAME.equalsIgnoreCase(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setIdmPropertyName("password");
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setSystemMapping(entityHandlingResult.getId());
            attributeMapping = systemAttributeMappingService.save(attributeMapping);
        } else if ("email".equalsIgnoreCase(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setIdmPropertyName(IdmIdentity_.email.getName());
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setStrategyType(AttributeMappingStrategyType.CREATE);
            attributeMapping.setSystemMapping(entityHandlingResult.getId());
            attributeMapping.setTransformToResourceScript("return \"" + EMAIL_ONE + "\";");
            attributeMapping = systemAttributeMappingService.save(attributeMapping);
        }
    });
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Aggregations

AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)90 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)59 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)47 Test (org.junit.Test)45 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)44 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)33 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)29 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)25 AccAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter)19 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)18 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)18 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)16 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)16 ArrayList (java.util.ArrayList)16 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)15 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)14 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)14 UUID (java.util.UUID)14 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)13 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)13