use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class DefaultRoleSynchronizationExecutorTest method initData.
private SysSystemDto initData() {
// create test system
SysSystemDto system = helper.createSystem("test_role_resource");
// generate schema for system
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
// Create synchronization mapping
SysSystemMappingDto syncSystemMapping = new SysSystemMappingDto();
syncSystemMapping.setName(getHelper().createName());
syncSystemMapping.setEntityType(SystemEntityType.ROLE);
syncSystemMapping.setOperationType(SystemOperationType.SYNCHRONIZATION);
syncSystemMapping.setObjectClass(objectClasses.get(0).getId());
final SysSystemMappingDto syncMapping = systemMappingService.save(syncSystemMapping);
createMapping(system, syncMapping);
getBean().initRoleData();
syncConfigService.find(null).getContent().forEach(config -> {
syncConfigService.delete(config);
});
return system;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class DefaultRoleSynchronizationExecutorTest method testSyncDeleteRolesMembership.
@Test
public void testSyncDeleteRolesMembership() {
AbstractSysSyncConfigDto syncConfigCustom = createSyncConfig();
SysSystemDto userSystem = helper.createTestResourceSystem(true);
List<SysSystemMappingDto> userSystemMappings = systemMappingService.findBySystem(userSystem, SystemOperationType.PROVISIONING, SystemEntityType.IDENTITY);
Assert.assertNotNull(userSystemMappings);
Assert.assertEquals(1, userSystemMappings.size());
SysSystemMappingDto userMappingDto = userSystemMappings.get(0);
// Switch to the sync.
userMappingDto.setOperationType(SystemOperationType.SYNCHRONIZATION);
userMappingDto = systemMappingService.save(userMappingDto);
List<SysSystemAttributeMappingDto> attributeMappingDtos = schemaAttributeMappingService.findBySystemMapping(userMappingDto);
SysSystemAttributeMappingDto userEmailAttribute = attributeMappingDtos.stream().filter(attribute -> attribute.getName().equalsIgnoreCase(TestHelper.ATTRIBUTE_MAPPING_EMAIL)).findFirst().orElse(null);
Assert.assertNotNull(userEmailAttribute);
Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
Assert.assertTrue(syncConfigCustom instanceof SysSyncRoleConfigDto);
SysSyncRoleConfigDto roleConfigDto = (SysSyncRoleConfigDto) syncConfigCustom;
SysSystemMappingDto systemMappingDto = DtoUtils.getEmbedded(syncConfigCustom, SysSyncConfig_.systemMapping, SysSystemMappingDto.class);
SysSchemaObjectClassDto schemaObjectClassDto = DtoUtils.getEmbedded(systemMappingDto, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
UUID roleSystemId = schemaObjectClassDto.getSystem();
Assert.assertNotNull(roleSystemId);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(roleSystemId);
schemaAttributeFilter.setObjectClassId(schemaObjectClassDto.getId());
SysSchemaAttributeDto schemaAttributeDto = schemaAttributeService.find(schemaAttributeFilter, null).getContent().stream().filter(attribute -> attribute.getName().equalsIgnoreCase("name")).findFirst().orElse(null);
Assert.assertNotNull(schemaAttributeDto);
SysSystemDto roleSystemDto = new SysSystemDto();
roleSystemDto.setId(roleSystemId);
List<SysSystemMappingDto> roleSystemMappings = systemMappingService.findBySystem(roleSystemDto, SystemOperationType.SYNCHRONIZATION, SystemEntityType.ROLE);
Assert.assertNotNull(roleSystemMappings);
Assert.assertEquals(1, roleSystemMappings.size());
SysSystemMappingDto roleMappingDto = roleSystemMappings.get(0);
// Create mapping attribute for get ID of role.
SysSystemAttributeMappingDto roleIdAttribute = new SysSystemAttributeMappingDto();
roleIdAttribute.setEntityAttribute(true);
roleIdAttribute.setUid(false);
roleIdAttribute.setSystemMapping(roleMappingDto.getId());
roleIdAttribute.setExtendedAttribute(false);
roleIdAttribute.setIdmPropertyName(RoleSynchronizationExecutor.ROLE_MEMBERSHIP_ID_FIELD);
roleIdAttribute.setSchemaAttribute(schemaAttributeDto.getId());
roleIdAttribute.setName(helper.createName());
roleIdAttribute = attributeMappingService.save(roleIdAttribute);
// Enable membership and use the user system.
roleConfigDto.setMembershipSwitch(true);
roleConfigDto.setMemberSystemMapping(userMappingDto.getId());
roleConfigDto.setMemberOfAttribute(userEmailAttribute.getId());
syncConfigCustom = syncConfigService.save(roleConfigDto);
//
helper.startSynchronization(syncConfigCustom);
//
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());
helper.checkSyncLog(syncConfigCustom, SynchronizationActionType.CREATE_ENTITY, 5, OperationResultType.SUCCESS);
AccRoleAccountFilter roleAccountFilter = new AccRoleAccountFilter();
roleAccountFilter.setSystemId(roleSystemId);
List<AccRoleAccountDto> roleAccountDtos = roleAccountService.find(roleAccountFilter, null).getContent();
Assert.assertEquals(5, roleAccountDtos.size());
// Delete a log.
syncLogService.delete(log);
// Transformation will return the null -> memberships should be deleted.
roleIdAttribute.setTransformFromResourceScript("return null;");
attributeMappingService.save(roleIdAttribute);
// Start sync again - for update.
helper.startSynchronization(syncConfigCustom);
//
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());
helper.checkSyncLog(syncConfigCustom, SynchronizationActionType.UPDATE_ENTITY, 5, OperationResultType.SUCCESS);
roleAccountFilter = new AccRoleAccountFilter();
roleAccountFilter.setSystemId(roleSystemId);
roleAccountDtos = roleAccountService.find(roleAccountFilter, null).getContent();
Assert.assertEquals(5, roleAccountDtos.size());
roleAccountDtos.forEach(roleAccountDto -> {
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setRoleId(roleAccountDto.getRole());
List<SysRoleSystemDto> roleSystemDtos = roleSystemService.find(roleSystemFilter, null).getContent();
Assert.assertEquals(0, roleSystemDtos.size());
});
cleanAfterTest(syncConfigCustom, roleSystemId, log, roleAccountDtos);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationServiceTest method initData.
private void initData() {
// create test system
system = helper.createSystem("test_resource");
// generate schema for system
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
// Create provisioning mapping
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 provisioningMapping = systemMappingService.save(systemMapping);
createMapping(system, provisioningMapping);
// Create synchronization mapping
SysSystemMappingDto syncSystemMapping = new SysSystemMappingDto();
syncSystemMapping.setName("default_" + System.currentTimeMillis());
syncSystemMapping.setEntityType(SystemEntityType.IDENTITY);
syncSystemMapping.setOperationType(SystemOperationType.SYNCHRONIZATION);
syncSystemMapping.setObjectClass(objectClasses.get(0).getId());
final SysSystemMappingDto syncMapping = systemMappingService.save(syncSystemMapping);
createMapping(system, syncMapping);
initResourceData();
syncConfigService.find(null).getContent().forEach(config -> {
syncConfigService.delete(config);
});
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class DefaultLdapTestHelper method createTestResourceSystem.
@Override
public SysSystemDto createTestResourceSystem(boolean withMapping, String systemName) {
SysSystemDto system = this.createSystem(systemName);
if (!withMapping) {
return system;
}
//
// generate schema for system
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
// TODO use constatn
SysSchemaObjectClassDto objectClass = objectClasses.stream().filter(oc -> oc.getObjectClassName().equals("__ACCOUNT__")).findFirst().orElse(null);
assertNotNull(objectClass);
//
SysSystemMappingDto systemMapping = new SysSystemMappingDto();
systemMapping.setName("default_" + System.currentTimeMillis());
systemMapping.setEntityType(SystemEntityType.IDENTITY);
systemMapping.setOperationType(SystemOperationType.PROVISIONING);
systemMapping.setObjectClass(objectClass.getId());
systemMapping = systemMappingService.save(systemMapping);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
SysSchemaAttributeDto memberOf = new SysSchemaAttributeDto();
memberOf.setClassType("java.lang.String");
memberOf.setCreateable(true);
memberOf.setMultivalued(true);
memberOf.setUpdateable(true);
memberOf.setReturnedByDefault(true);
memberOf.setReadable(true);
memberOf.setObjectClass(objectClass.getId());
memberOf.setNativeName(ATTRIBUTE_MAPPING_MEMBER_OF);
memberOf.setName(ATTRIBUTE_MAPPING_MEMBER_OF);
memberOf = schemaAttributeService.save(memberOf);
// From some reason contains schema object class for account two __NAME__ just skip second
Page<SysSchemaAttributeDto> schemaAttributesPage = schemaAttributeService.find(schemaAttributeFilter, null);
for (SysSchemaAttributeDto schemaAttr : schemaAttributesPage) {
// Test ldap has some duplicates attributes for example __NAME__ and cn
SysSystemAttributeMappingDto founded = systemAttributeMappingService.findBySystemMappingAndName(systemMapping.getId(), schemaAttr.getName());
if (founded != null) {
continue;
}
if (ATTRIBUTE_MAPPING_NAME.equals(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setUid(true);
attributeMapping.setEntityAttribute(true);
attributeMapping.setIdmPropertyName(IdmIdentity_.username.getName());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(systemMapping.getId());
systemAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_MAPPING_PASSWORD.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName("password");
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSystemMapping(systemMapping.getId());
attributeMapping.setPasswordAttribute(true);
systemAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_MAPPING_FIRSTNAME.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName(IdmIdentity_.firstName.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSystemMapping(systemMapping.getId());
systemAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_MAPPING_CN.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
// TODO: map as script (combination last and first name)
attributeMapping.setIdmPropertyName(IdmIdentity_.description.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSystemMapping(systemMapping.getId());
attributeMapping.setTransformToResourceScript("" + System.lineSeparator() + "if (attributeValue) {" + System.lineSeparator() + " return attributeValue;" + System.lineSeparator() + "}" + System.lineSeparator() + "return entity.getFirstName() + ' ' + entity.getLastName();" + // we must compose cn
System.lineSeparator());
systemAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_MAPPING_LASTNAME.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName(IdmIdentity_.lastName.getName());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(systemMapping.getId());
systemAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_MAPPING_EMAIL.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName(IdmIdentity_.email.getName());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(systemMapping.getId());
systemAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_MAPPING_MEMBER_OF.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setStrategyType(AttributeMappingStrategyType.MERGE);
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(systemMapping.getId());
attributeMapping.setEntityAttribute(false);
attributeMapping.setExtendedAttribute(false);
systemAttributeMappingService.save(attributeMapping);
}
}
return system;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class DefaultAccTestHelper method createMapping.
@Override
public SysSystemMappingDto createMapping(SysSystemDto system) {
//
// generate schema for system
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
//
SysSystemMappingDto systemMapping = new SysSystemMappingDto();
systemMapping.setName("default_" + System.currentTimeMillis());
systemMapping.setEntityType(SystemEntityType.IDENTITY);
systemMapping.setOperationType(SystemOperationType.PROVISIONING);
systemMapping.setObjectClass(objectClasses.get(0).getId());
systemMapping = systemMappingService.save(systemMapping);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
Page<SysSchemaAttributeDto> schemaAttributesPage = schemaAttributeService.find(schemaAttributeFilter, null);
for (SysSchemaAttributeDto schemaAttr : schemaAttributesPage) {
if (ATTRIBUTE_MAPPING_NAME.equals(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setUid(true);
attributeMapping.setEntityAttribute(true);
attributeMapping.setIdmPropertyName(IdmIdentity_.username.getName());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(systemMapping.getId());
systemAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_MAPPING_ENABLE.equals(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setUid(false);
attributeMapping.setEntityAttribute(true);
attributeMapping.setIdmPropertyName("disabled");
attributeMapping.setTransformToResourceScript("return String.valueOf(!attributeValue);");
attributeMapping.setTransformFromResourceScript("return String.valueOf(attributeValue);");
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(systemMapping.getId());
systemAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_MAPPING_PASSWORD.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName("password");
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setPasswordAttribute(true);
attributeMapping.setSystemMapping(systemMapping.getId());
systemAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_MAPPING_FIRSTNAME.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName(IdmIdentity_.firstName.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSystemMapping(systemMapping.getId());
systemAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_MAPPING_LASTNAME.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName(IdmIdentity_.lastName.getName());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(systemMapping.getId());
systemAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_MAPPING_EMAIL.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName(IdmIdentity_.email.getName());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(systemMapping.getId());
systemAttributeMappingService.save(attributeMapping);
}
}
return systemMapping;
}
Aggregations