Search in sources :

Example 1 with SysSystemDto

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

the class DefaultSynchronizationServiceTest method doStartSyncD_Missing_Account_doCreateAccount.

@Test
public void doStartSyncD_Missing_Account_doCreateAccount() {
    SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
    configFilter.setName(SYNC_CONFIG_NAME);
    List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
    Assert.assertEquals(1, syncConfigs.size());
    AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
    Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
    // Create new identity THREE, with account
    IdmIdentityDto identity = new IdmIdentityDto();
    identity.setUsername("x" + IDENTITY_USERNAME_THREE);
    identity.setFirstName(IDENTITY_USERNAME_THREE);
    identity.setLastName(IDENTITY_USERNAME_THREE);
    identity = identityService.save(identity);
    AccAccountDto accountOne = new AccAccountDto();
    SysSystemMappingDto systemMapping = systemMappingService.get(syncConfigCustom.getSystemMapping());
    SysSystemDto system = systemService.get(schemaObjectClassService.get(systemMapping.getObjectClass()).getSystem());
    accountOne.setSystem(system.getId());
    accountOne.setUid("x" + IDENTITY_USERNAME_THREE);
    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());
    accountIdentityOne = identityAccoutnService.save(accountIdentityOne);
    // Set sync config
    syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
    syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
    syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
    syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.CREATE_ACCOUNT);
    syncConfigCustom.setReconciliation(true);
    syncConfigService.save(syncConfigCustom);
    // Check state before sync
    Assert.assertNull(entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_THREE));
    // Start synchronization
    synchornizationService.setSynchronizationConfigId(syncConfigCustom.getId());
    synchornizationService.process();
    // 
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
    List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
    Assert.assertEquals(1, logs.size());
    SysSyncLogDto log = logs.get(0);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
    actionLogFilter.setSynchronizationLogId(log.getId());
    List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
    Assert.assertEquals(2, actions.size());
    SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
        return SynchronizationActionType.CREATE_ACCOUNT == action.getSyncAction();
    }).findFirst().get();
    SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
    itemLogFilter.setSyncActionLogId(actionLog.getId());
    List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
    Assert.assertEquals(1, items.size());
    // Check state after sync
    Assert.assertNotNull(entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_THREE));
    // Delete log
    syncLogService.delete(log);
}
Also used : SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSyncItemLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with SysSystemDto

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

the class DefaultSynchronizationServiceTest method doStartSyncE_StrategyWriteIfNull.

@Test
public void doStartSyncE_StrategyWriteIfNull() {
    SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
    configFilter.setName(SYNC_CONFIG_NAME);
    List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
    Assert.assertEquals(1, syncConfigs.size());
    AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
    Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
    // Find email attribute and change strategy on WRITE_IF_NULL
    SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
    mappingFilter.setEntityType(SystemEntityType.IDENTITY);
    SysSystemMappingDto systemMapping = systemMappingService.get(syncConfigCustom.getSystemMapping());
    SysSystemDto system = systemService.get(schemaObjectClassService.get(systemMapping.getObjectClass()).getSystem());
    mappingFilter.setSystemId(system.getId());
    mappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION);
    List<SysSystemMappingDto> mappings = systemMappingService.find(mappingFilter, null).getContent();
    Assert.assertEquals(1, mappings.size());
    SysSystemMappingDto mapping = mappings.get(0);
    SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
    attributeMappingFilter.setSystemMappingId(mapping.getId());
    List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null).getContent();
    SysSystemAttributeMappingDto emailAttribute = attributes.stream().filter(attribute -> {
        return attribute.getName().equalsIgnoreCase(ATTRIBUTE_EMAIL);
    }).findFirst().get();
    emailAttribute.setStrategyType(AttributeMappingStrategyType.WRITE_IF_NULL);
    schemaAttributeMappingService.save(emailAttribute);
    // 
    // Set email on identity ONE to null
    IdmIdentityDto one = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE);
    one.setEmail(null);
    identityService.save(one);
    // Prepare resource data
    this.getBean().deleteAllResourceData();
    this.getBean().initResourceData();
    this.getBean().changeResourceData();
    // Set sync config
    syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY);
    syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
    syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.CREATE_ENTITY);
    syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
    syncConfigCustom.setReconciliation(true);
    syncConfigService.save(syncConfigCustom);
    // Check state before sync
    Assert.assertEquals(null, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getEmail());
    Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getEmail());
    // Start synchronization
    synchornizationService.setSynchronizationConfigId(syncConfigCustom.getId());
    synchornizationService.process();
    // 
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
    List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
    Assert.assertEquals(1, logs.size());
    SysSyncLogDto log = logs.get(0);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
    actionLogFilter.setSynchronizationLogId(log.getId());
    List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
    Assert.assertEquals(1, actions.size());
    SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
        return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction();
    }).findFirst().get();
    SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
    itemLogFilter.setSyncActionLogId(actionLog.getId());
    List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
    Assert.assertEquals(2, items.size());
    // Check state after sync
    Assert.assertEquals(IDENTITY_EMAIL_CORRECT_CHANGED, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getEmail());
    Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getEmail());
    // Delete log
    syncLogService.delete(log);
}
Also used : SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSyncItemLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with SysSystemDto

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

the class DefaultSysProvisioningArchiveServiceTest method createRoleSystem.

private SysSystemDto createRoleSystem() {
    SysSystemDto system = new SysSystemDto();
    system.setName("system_" + UUID.randomUUID());
    return systemService.save(system);
}
Also used : SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 4 with SysSystemDto

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

the class DefaultSysProvisioningArchiveServiceTest method operationTypeFilterTest.

@Test
public void operationTypeFilterTest() {
    IdmBasePermission permission = IdmBasePermission.ADMIN;
    SystemEntityType entityType = SystemEntityType.IDENTITY;
    SysSystemDto system = createRoleSystem();
    SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system);
    SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system);
    provisioningArchive2.setOperationType(ProvisioningEventType.UPDATE);
    archiveService.save(provisioningArchive2);
    SysProvisioningArchiveDto provisioningArchive3 = createProvisioningArchive(entityType, system);
    provisioningArchive3.setOperationType(ProvisioningEventType.UPDATE);
    archiveService.save(provisioningArchive3);
    SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
    filter.setOperationType(ProvisioningEventType.UPDATE);
    filter.setSystemId(system.getId());
    Page<SysProvisioningArchiveDto> result = archiveService.find(filter, null, permission);
    assertEquals(2, result.getTotalElements());
    assertFalse(result.getContent().contains(provisioningArchive1));
    assertTrue(result.getContent().contains(provisioningArchive2));
    assertTrue(result.getContent().contains(provisioningArchive3));
}
Also used : SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 5 with SysSystemDto

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

the class DefaultSysProvisioningArchiveServiceTest method systemIdFilterTest.

@Test
public void systemIdFilterTest() {
    IdmBasePermission permission = IdmBasePermission.ADMIN;
    SystemEntityType entityType = SystemEntityType.IDENTITY;
    SysSystemDto system1 = createRoleSystem();
    SysSystemDto system2 = createRoleSystem();
    SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system1);
    SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system1);
    SysProvisioningArchiveDto provisioningArchive3 = createProvisioningArchive(entityType, system2);
    SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
    filter.setSystemId(system1.getId());
    Page<SysProvisioningArchiveDto> result = archiveService.find(filter, null, permission);
    assertEquals(2, result.getTotalElements());
    assertTrue(result.getContent().contains(provisioningArchive1));
    assertTrue(result.getContent().contains(provisioningArchive2));
    assertFalse(result.getContent().contains(provisioningArchive3));
}
Also used : SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)256 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)167 Test (org.junit.Test)167 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)98 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)82 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)56 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)52 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)50 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)45 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)42 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)42 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)32 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)32 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)30 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)29 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)29 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)29 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)28 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)27 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)27