use of eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testEnableAutomaticRoleDuringSynchronization.
@Test
public void testEnableAutomaticRoleDuringSynchronization() {
// default initialization of system and all necessary things
SysSystemDto system = initData();
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
// we want start recalculation after synchronization
config.setStartAutoRoleRec(true);
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
this.getBean().deleteAllResourceData();
String testLastName = "test-last-name-same-" + System.currentTimeMillis();
String testFirstName = "test-first-name";
String user1 = "test-1-" + System.currentTimeMillis();
this.getBean().setTestData(user1, testFirstName, testLastName);
String user2 = "test-2-" + System.currentTimeMillis();
this.getBean().setTestData(user2, testFirstName, testLastName);
String user3 = "test-3-" + System.currentTimeMillis();
this.getBean().setTestData(user3, testFirstName, testLastName);
IdmRoleDto role1 = helper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = helper.createAutomaticRole(role1.getId());
helper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, user1);
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3, OperationResultType.WARNING);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityDto identity1 = identityService.getByUsername(user1);
IdmIdentityDto identity2 = identityService.getByUsername(user2);
IdmIdentityDto identity3 = identityService.getByUsername(user3);
// we must change username, after create contract is also save identity (change state)
identity1.setUsername(user1 + System.currentTimeMillis());
identity1 = identityService.save(identity1);
helper.createIdentityContact(identity1);
helper.createIdentityContact(identity2);
helper.createIdentityContact(identity3);
List<IdmIdentityRoleDto> identityRoles1 = identityRoleService.findAllByIdentity(identity1.getId());
List<IdmIdentityRoleDto> identityRoles2 = identityRoleService.findAllByIdentity(identity2.getId());
List<IdmIdentityRoleDto> identityRoles3 = identityRoleService.findAllByIdentity(identity3.getId());
assertEquals(0, identityRoles1.size());
assertEquals(0, identityRoles2.size());
assertEquals(0, identityRoles3.size());
// enable test processor
testIdentityProcessor.enable();
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
identityRoles1 = identityRoleService.findAllByIdentity(identity1.getId());
identityRoles2 = identityRoleService.findAllByIdentity(identity2.getId());
identityRoles3 = identityRoleService.findAllByIdentity(identity3.getId());
assertEquals(1, identityRoles1.size());
assertEquals(0, identityRoles2.size());
assertEquals(0, identityRoles3.size());
IdmIdentityRoleDto foundIdentityRole = identityRoles1.get(0);
assertEquals(automaticRole.getId(), foundIdentityRole.getRoleTreeNode());
// synchronization immediately recalculate is disabled
int size = testIdentityProcessor.getRolesByUsername(user1).size();
assertEquals(0, size);
size = testIdentityProcessor.getRolesByUsername(user2).size();
assertEquals(0, size);
size = testIdentityProcessor.getRolesByUsername(user3).size();
assertEquals(0, size);
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method deleteDefaulRoleIntegrityTest.
@Test
public void deleteDefaulRoleIntegrityTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
Assert.assertNotNull(config.getDefaultRole());
// Delete default role
roleService.delete(defaultRole);
config = (SysSyncIdentityConfigDto) syncConfigService.get(config.getId());
Assert.assertNull(config.getDefaultRole());
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto in project CzechIdMng by bcvsolutions.
the class IdentitySynchronizationExecutor method createEntityAccount.
@Override
protected EntityAccountDto createEntityAccount(AccAccountDto account, IdmIdentityDto entity, SynchronizationContext context) {
Assert.notNull(account);
Assert.notNull(entity);
EntityAccountDto entityAccount = super.createEntityAccount(account, entity, context);
Assert.isInstanceOf(AccIdentityAccountDto.class, entityAccount, "For identity sync must be entity-account relation instance of AccIdentityAccountDto!");
AccIdentityAccountDto identityAccount = (AccIdentityAccountDto) entityAccount;
SysSyncIdentityConfigDto config = this.getConfig(context);
UUID defaultRoleId = config.getDefaultRole();
if (defaultRoleId == null) {
return identityAccount;
}
// Default role is defines
IdmRoleDto defaultRole = DtoUtils.getEmbedded(config, SysSyncIdentityConfig_.defaultRole, IdmRoleDto.class);
context.getLogItem().addToLog(MessageFormat.format("Default role [{1}] is defines and will be assigned to the identity [{0}].", entity.getCode(), defaultRole.getCode()));
Assert.notNull(defaultRole, "Default role must be found for this sync configuration!");
IdmIdentityContractDto primeContract = identityContractService.getPrimeValidContract(entity.getId());
if (primeContract == null) {
context.getLogItem().addToLog("Warning! - Default role is set, but could not be assigned to identity, because was not found any valid identity contract!");
this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
return identityAccount;
}
// Create role request for default role and primary contract
IdmRoleRequestDto roleRequest = roleRequestService.createRequest(primeContract, defaultRole);
roleRequest = roleRequestService.startRequestInternal(roleRequest.getId(), false);
// Load concept (can be only one)
IdmConceptRoleRequestFilter conceptFilter = new IdmConceptRoleRequestFilter();
conceptFilter.setRoleRequestId(roleRequest.getId());
UUID identityRoleId = conceptRoleRequestService.find(conceptFilter, null).getContent().get(0).getIdentityRole();
Assert.notNull(identityRoleId, "Identity role relation had to been created!");
identityAccount.setIdentityRole(identityRoleId);
AccIdentityAccountDto duplicate = this.findDuplicate(identityAccount);
if (duplicate != null) {
// This IdentityAccount is new and duplicated, we do not want create duplicated
// relation.
// Same IdentityAccount had to be created by assigned default role!
context.getLogItem().addToLog(MessageFormat.format("This identity-account (identity-role id: {2}) is new and duplicated, " + "we do not want create duplicated relation! " + "We will reusing already persisted identity-account [{3}]. " + "Probable reason: Same identity-account had to be created by assigned default role!", identityAccount.getAccount(), identityAccount.getIdentity(), identityAccount.getIdentityRole(), duplicate.getId()));
// Reusing duplicate
return duplicate;
}
return identityAccount;
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemServiceTest method duplicateSystemWithSynchronization.
@Test
public void duplicateSystemWithSynchronization() {
String syncName = "test-sync-config";
// create test system
SysSystemDto system = helper.createTestResourceSystem(true);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
// Number of schema attributes on original system
int numberOfSchemaAttributesOrig = schemaAttributeService.find(schemaAttributeFilter, null).getContent().size();
SysSystemMappingDto mappingOrig = helper.getDefaultMapping(system);
// Number of mapping attributes on original system
int numberOfMappingAttributesOrig = systemAttributeMappingService.findBySystemMapping(mappingOrig).size();
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(mappingOrig.getId());
List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null).getContent();
SysSystemAttributeMappingDto nameAttribute = attributes.stream().filter(attribute -> {
return attribute.getName().equals(TestHelper.ATTRIBUTE_MAPPING_NAME);
}).findFirst().get();
SysSystemAttributeMappingDto firstNameAttribute = attributes.stream().filter(attribute -> {
return attribute.getName().equals(TestHelper.ATTRIBUTE_MAPPING_FIRSTNAME);
}).findFirst().get();
SysSystemAttributeMappingDto emailAttribute = attributes.stream().filter(attribute -> {
return attribute.getName().equals(TestHelper.ATTRIBUTE_MAPPING_EMAIL);
}).findFirst().get();
// create synchronization config
AbstractSysSyncConfigDto syncConfigDuplicate = new SysSyncIdentityConfigDto();
syncConfigDuplicate.setCustomFilter(true);
syncConfigDuplicate.setSystemMapping(mappingOrig.getId());
syncConfigDuplicate.setCorrelationAttribute(nameAttribute.getId());
syncConfigDuplicate.setTokenAttribute(firstNameAttribute.getId());
syncConfigDuplicate.setFilterAttribute(emailAttribute.getId());
syncConfigDuplicate.setReconciliation(true);
syncConfigDuplicate.setName(syncName);
syncConfigDuplicate.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
syncConfigDuplicate.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
syncConfigDuplicate.setMissingEntityAction(SynchronizationMissingEntityActionType.CREATE_ENTITY);
syncConfigDuplicate.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
syncConfigDuplicate = syncConfigService.save(syncConfigDuplicate);
SysSystemDto duplicatedSystem = systemService.duplicate(system.getId());
// check duplicate
systemService.checkSystem(duplicatedSystem);
Assert.assertNotEquals(system.getId(), duplicatedSystem.getId());
schemaAttributeFilter.setSystemId(duplicatedSystem.getId());
// Number of schema attributes on duplicated system
int numberOfSchemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent().size();
Assert.assertEquals(numberOfSchemaAttributesOrig, numberOfSchemaAttributes);
SysSystemMappingDto mapping = helper.getDefaultMapping(duplicatedSystem);
// Number of mapping attributes on duplicated system
int numberOfMappingAttributes = systemAttributeMappingService.findBySystemMapping(mapping).size();
Assert.assertEquals(numberOfMappingAttributesOrig, numberOfMappingAttributes);
// check synchronization config
SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
syncFilter.setSystemId(duplicatedSystem.getId());
List<AbstractSysSyncConfigDto> configs = syncConfigService.find(syncFilter, null).getContent();
Assert.assertEquals(1, configs.size());
Assert.assertEquals(1, configs.size());
AbstractSysSyncConfigDto configNew = configs.get(0);
Assert.assertFalse(configNew.isEnabled());
Assert.assertTrue(configNew.isReconciliation());
Assert.assertEquals(syncName, configNew.getName());
Assert.assertTrue(configNew.isCustomFilter());
Assert.assertEquals(syncConfigDuplicate.getLinkedAction(), configNew.getLinkedAction());
Assert.assertEquals(syncConfigDuplicate.getUnlinkedAction(), configNew.getUnlinkedAction());
Assert.assertEquals(syncConfigDuplicate.getMissingEntityAction(), configNew.getMissingEntityAction());
Assert.assertEquals(syncConfigDuplicate.getMissingAccountAction(), configNew.getMissingAccountAction());
SysSystemAttributeMappingDto correlationAtt = schemaAttributeMappingService.get(configNew.getCorrelationAttribute());
SysSystemAttributeMappingDto tokenAtt = schemaAttributeMappingService.get(configNew.getTokenAttribute());
SysSystemAttributeMappingDto filterAtt = schemaAttributeMappingService.get(configNew.getFilterAttribute());
Assert.assertEquals(nameAttribute.getName(), correlationAtt.getName());
Assert.assertEquals(nameAttribute.getIdmPropertyName(), correlationAtt.getIdmPropertyName());
Assert.assertEquals(firstNameAttribute.getName(), tokenAtt.getName());
Assert.assertEquals(firstNameAttribute.getIdmPropertyName(), tokenAtt.getIdmPropertyName());
Assert.assertEquals(emailAttribute.getName(), filterAtt.getName());
Assert.assertEquals(emailAttribute.getIdmPropertyName(), filterAtt.getIdmPropertyName());
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testSynchronizationCache.
@Test
public void testSynchronizationCache() {
SysSystemDto system = initData();
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
this.getBean().deleteAllResourceData();
String testLastName = "test-last-name-same-" + System.currentTimeMillis();
String testFirstName = "test-first-name";
String userOne = "test-1-" + System.currentTimeMillis();
this.getBean().setTestData(userOne, testFirstName, testLastName);
String userTwo = "test-2-" + System.currentTimeMillis();
this.getBean().setTestData(userTwo, testFirstName, testLastName);
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 defaultMapping = mappings.get(0);
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(defaultMapping.getId());
List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null).getContent();
SysSystemAttributeMappingDto firstNameAttribute = attributes.stream().filter(attribute -> {
return attribute.getIdmPropertyName().equals(IdmIdentity_.firstName.getName());
}).findFirst().orElse(null);
Assert.assertNotNull(firstNameAttribute);
StringBuilder scriptGenerateUuid = new StringBuilder();
scriptGenerateUuid.append("import java.util.UUID;");
scriptGenerateUuid.append(System.lineSeparator());
scriptGenerateUuid.append("return UUID.randomUUID();");
String scriptName = "generateUuid";
IdmScriptDto scriptUuid = new IdmScriptDto();
scriptUuid.setCategory(IdmScriptCategory.TRANSFORM_FROM);
scriptUuid.setCode(scriptName);
scriptUuid.setName(scriptName);
scriptUuid.setScript(scriptGenerateUuid.toString());
scriptUuid = scriptService.save(scriptUuid);
IdmScriptAuthorityDto scriptAuth = new IdmScriptAuthorityDto();
scriptAuth.setClassName("java.util.UUID");
scriptAuth.setType(ScriptAuthorityType.CLASS_NAME);
scriptAuth.setScript(scriptUuid.getId());
scriptAuth = scriptAuthrotityService.save(scriptAuth);
// we must call script
StringBuilder transformationScript = new StringBuilder();
transformationScript.append("return scriptEvaluator.evaluate(");
transformationScript.append(System.lineSeparator());
transformationScript.append("scriptEvaluator.newBuilder()");
transformationScript.append(System.lineSeparator());
transformationScript.append(".setScriptCode('" + scriptName + "')");
transformationScript.append(System.lineSeparator());
transformationScript.append(".build());");
transformationScript.append(System.lineSeparator());
firstNameAttribute.setTransformFromResourceScript(transformationScript.toString());
firstNameAttribute.setCached(true);
firstNameAttribute = schemaAttributeMappingService.save(firstNameAttribute);
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2, OperationResultType.WARNING);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setLastName(testLastName);
List<IdmIdentityDto> identities = identityService.find(filter, null).getContent();
assertEquals(2, identities.size());
//
IdmIdentityDto identityOne = identities.get(0);
IdmIdentityDto identityTwo = identities.get(1);
//
assertNotEquals(identityOne.getFirstName(), identityTwo.getFirstName());
}
Aggregations