Search in sources :

Example 46 with SysSystemEntityDto

use of eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto 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 47 with SysSystemEntityDto

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

the class DefaultSysSystemEntityServiceFilterTest method testSystemId.

@Test
public void testSystemId() {
    SysSystemDto system1 = helper.createTestResourceSystem(false);
    SysSystemDto system2 = helper.createTestResourceSystem(false);
    createEntitySystem("test1-" + System.currentTimeMillis(), SystemEntityType.CONTRACT, system1.getId(), UUID.randomUUID());
    SysSystemEntityDto entity2 = createEntitySystem("test2-" + System.currentTimeMillis(), SystemEntityType.CONTRACT, system2.getId(), UUID.randomUUID());
    createEntitySystem("test3-" + System.currentTimeMillis(), SystemEntityType.CONTRACT, system2.getId(), UUID.randomUUID());
    // 
    SysSystemEntityFilter testFilter = new SysSystemEntityFilter();
    testFilter.setSystemId(system2.getId());
    Page<SysSystemEntityDto> pages = entityService.find(testFilter, null);
    assertEquals(2, pages.getTotalElements());
    SysSystemEntityDto foundedSystem = pages.getContent().stream().filter(sys -> sys.getId().equals(entity2.getId())).findAny().get();
    assertNotNull(foundedSystem);
}
Also used : SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 48 with SysSystemEntityDto

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

the class DefaultSysSystemEntityServiceFilterTest method testEntityType.

@Test
public void testEntityType() {
    SysSystemDto system = helper.createTestResourceSystem(false);
    createEntitySystem("test1-" + System.currentTimeMillis(), SystemEntityType.ROLE, system.getId(), UUID.randomUUID());
    SysSystemEntityDto entity2 = createEntitySystem("test2-" + System.currentTimeMillis(), SystemEntityType.TREE, system.getId(), UUID.randomUUID());
    createEntitySystem("tes3t-" + System.currentTimeMillis(), SystemEntityType.IDENTITY, system.getId(), UUID.randomUUID());
    // 
    SysSystemEntityFilter testFilter = new SysSystemEntityFilter();
    testFilter.setEntityType(entity2.getEntityType());
    testFilter.setUid(entity2.getUid());
    Page<SysSystemEntityDto> pages = entityService.find(testFilter, null);
    assertEquals(1, pages.getTotalElements());
    assertEquals(entity2.getId(), pages.getContent().get(0).getId());
}
Also used : SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 49 with SysSystemEntityDto

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

the class DefaultSysSystemEntityServiceFilterTest method testId.

/**
 * Id in {@link SysSystemEntityFilter} not currently implemented. Use get by id.
 */
@Test
public void testId() {
    SysSystemDto system = helper.createTestResourceSystem(false);
    createEntitySystem("test1-" + System.currentTimeMillis(), SystemEntityType.CONTRACT, system.getId(), UUID.randomUUID());
    createEntitySystem("test2-" + System.currentTimeMillis(), SystemEntityType.CONTRACT, system.getId(), UUID.randomUUID());
    SysSystemEntityDto entity3 = createEntitySystem("test3-" + System.currentTimeMillis(), SystemEntityType.CONTRACT, system.getId(), UUID.randomUUID());
    // 
    SysSystemEntityDto foundedEntity = entityService.get(entity3.getId());
    assertEquals(entity3.getId(), foundedEntity.getId());
}
Also used : SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 50 with SysSystemEntityDto

use of eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto 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)

Aggregations

SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)69 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)49 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)36 Test (org.junit.Test)36 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)25 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)22 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)19 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)15 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)14 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)14 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)13 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)12 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)12 SysProvisioningBatchDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto)11 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)10 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)10 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)10 IcObjectClassImpl (eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl)10 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)8 SysSystemEntityFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter)8