use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationServiceTest method doStartSyncE_StrategyWriteIfNull_EAV.
@Test
public void doStartSyncE_StrategyWriteIfNull_EAV() {
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 eavAttribute = attributes.stream().filter(attribute -> {
return attribute.getName().equalsIgnoreCase(EAV_ATTRIBUTE);
}).findFirst().get();
eavAttribute.setStrategyType(AttributeMappingStrategyType.WRITE_IF_NULL);
schemaAttributeMappingService.save(eavAttribute);
//
// Set eav on identity ONE to null
IdmIdentityDto one = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE);
formService.saveValues(one.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName(), null);
IdmIdentityDto two = identityService.getByUsername("x" + IDENTITY_USERNAME_TWO);
formService.saveValues(two.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName(), ImmutableList.of(ATTRIBUTE_EMAIL));
// 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);
// 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
one = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE);
Assert.assertEquals(ATTRIBUTE_VALUE_CHANGED, formService.getValues(one.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName()).get(0).getStringValue());
two = identityService.getByUsername("x" + IDENTITY_USERNAME_TWO);
Assert.assertEquals(ATTRIBUTE_EMAIL, formService.getValues(two.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName()).get(0).getStringValue());
// Revert strategy
eavAttribute.setStrategyType(AttributeMappingStrategyType.SET);
schemaAttributeMappingService.save(eavAttribute);
// Set EAV value to default
formService.saveValues(one.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName(), ImmutableList.of("1"));
formService.saveValues(two.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName(), ImmutableList.of("2"));
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationServiceTest method doStartSyncE_StrategyCreate.
@Test
public void doStartSyncE_StrategyCreate() {
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));
// Delete all accounts in resource
this.getBean().deleteAllResourceData();
// Create new accounts
this.getBean().initResourceData();
// Find email attribute and change startegy on CREATE
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.CREATE);
schemaAttributeMappingService.save(emailAttribute);
//
// 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.assertNull(identityService.getByUsername("x" + IDENTITY_USERNAME_ONE));
Assert.assertNull(identityService.getByUsername("x" + IDENTITY_USERNAME_TWO));
// 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.CREATE_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_USERNAME_ONE, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getFirstName());
Assert.assertEquals(IDENTITY_USERNAME_TWO, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getLastName());
Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getEmail());
Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getEmail());
// Delete log
syncLogService.delete(log);
// Change data
this.getBean().changeResourceData();
// Start synchronization aging
synchornizationService.setSynchronizationConfigId(syncConfigCustom.getId());
synchornizationService.process();
//
logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
log = logs.get(0);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
actionLogFilter = new SysSyncActionLogFilter();
actionLogFilter.setSynchronizationLogId(log.getId());
actions = syncActionLogService.find(actionLogFilter, null).getContent();
Assert.assertEquals(1, actions.size());
actionLog = actions.stream().filter(action -> {
return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction();
}).findFirst().get();
itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
items = syncItemLogService.find(itemLogFilter, null).getContent();
Assert.assertEquals(2, items.size());
// Check state after sync
Assert.assertEquals(ATTRIBUTE_VALUE_CHANGED, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getFirstName());
Assert.assertEquals(ATTRIBUTE_VALUE_CHANGED, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getLastName());
Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getEmail());
Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getEmail());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationServiceTest method setSyncConfigForEav.
private AbstractSysSyncConfigDto setSyncConfigForEav(String configName) {
SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
configFilter.setName(configName);
List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
Assert.assertEquals(1, syncConfigs.size());
AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
SysSystemMappingDto systemMapping = systemMappingService.get(syncConfigCustom.getSystemMapping());
SysSystemDto system = systemService.get(schemaObjectClassService.get(systemMapping.getObjectClass()).getSystem());
SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
mappingFilter.setEntityType(SystemEntityType.IDENTITY);
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();
// Set sync config
SysSystemAttributeMappingDto eavAttribute = attributes.stream().filter(attribute -> {
return attribute.getName().equals(EAV_ATTRIBUTE);
}).findFirst().get();
Assert.assertNotNull(eavAttribute);
syncConfigCustom.setCorrelationAttribute(eavAttribute.getId());
syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK);
syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
syncConfigCustom.setReconciliation(true);
syncConfigService.save(syncConfigCustom);
return syncConfigCustom;
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto 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();
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method initOverloadedAttributes.
private void initOverloadedAttributes(List<SysRoleSystemAttributeDto> overloadingAttributes, List<AttributeMapping> defaultAttributes) {
SysSchemaAttributeDto attOne = new SysSchemaAttributeDto();
attOne.setName("attOne");
attOne.setObjectClass(objectClasses.get(0).getId());
attOne.setClassType(String.class.getName());
attOne = schemaAttributeService.save(attOne);
SysSchemaAttributeDto attTwo = new SysSchemaAttributeDto();
attTwo.setName("attTwo");
attTwo.setObjectClass(objectClasses.get(0).getId());
attTwo.setClassType(String.class.getName());
attTwo = schemaAttributeService.save(attTwo);
SysSystemAttributeMappingDto defOne = new SysSystemAttributeMappingDto();
defOne.setEntityAttribute(true);
defOne.setIdmPropertyName("one");
defOne.setName("defOne");
defOne.setDisabledAttribute(true);
defOne.setSchemaAttribute(attOne.getId());
defOne.setSystemMapping(systemMapping.getId());
defOne = systemAttributeMappingService.save(defOne);
defaultAttributes.add(defOne);
SysSystemAttributeMappingDto defTwo = new SysSystemAttributeMappingDto();
defTwo.setEntityAttribute(true);
defTwo.setIdmPropertyName("two");
defTwo.setName("defTwo");
defTwo.setSchemaAttribute(attTwo.getId());
defTwo.setSystemMapping(systemMapping.getId());
defTwo = systemAttributeMappingService.save(defTwo);
defaultAttributes.add(defTwo);
IdmRoleDto roleTwo = new IdmRoleDto();
roleTwo.setName("roleTwo");
roleTwo.setPriority(100);
roleTwo = roleService.save(roleTwo);
IdmRoleDto roleOne = new IdmRoleDto();
roleOne.setName("roleOne");
roleOne.setPriority(100);
roleOne = roleService.save(roleOne);
SysRoleSystemDto roleSystemTwo = new SysRoleSystemDto();
roleSystemTwo.setRole(roleTwo.getId());
roleSystemTwo.setSystem(system.getId());
roleSystemTwo.setSystemMapping(systemMapping.getId());
roleSystemTwo = roleSystemService.save(roleSystemTwo);
SysRoleSystemDto roleSystemOne = new SysRoleSystemDto();
roleSystemOne.setRole(roleOne.getId());
roleSystemOne.setSystem(system.getId());
roleSystemOne.setSystemMapping(systemMapping.getId());
roleSystemOne = roleSystemService.save(roleSystemOne);
SysRoleSystemAttributeDto overloadedRoleOne = new SysRoleSystemAttributeDto();
overloadedRoleOne.setSystemAttributeMapping(defOne.getId());
overloadedRoleOne.setEntityAttribute(true);
overloadedRoleOne.setIdmPropertyName("one");
overloadedRoleOne.setName("defOneOverloaded");
overloadedRoleOne.setDisabledDefaultAttribute(false);
overloadedRoleOne.setRoleSystem(roleSystemOne.getId());
overloadedRoleOne = roleSystemAttributeService.save(overloadedRoleOne);
overloadingAttributes.add(overloadedRoleOne);
SysRoleSystemAttributeDto overloadedRoleTwo = new SysRoleSystemAttributeDto();
overloadedRoleTwo.setSystemAttributeMapping(defOne.getId());
overloadedRoleTwo.setEntityAttribute(true);
overloadedRoleTwo.setIdmPropertyName("one");
overloadedRoleTwo.setName("defOneOverloadedRoleTwo");
overloadedRoleTwo.setDisabledDefaultAttribute(false);
overloadedRoleTwo.setRoleSystem(roleSystemTwo.getId());
overloadedRoleTwo = roleSystemAttributeService.save(overloadedRoleTwo);
overloadingAttributes.add(overloadedRoleTwo);
}
Aggregations