use of eu.bcvsolutions.idm.acc.event.SystemMappingEvent in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemMappingServiceIntegrationTest method testAutomaticGenerateOfMappedAttributes.
@Test
public void testAutomaticGenerateOfMappedAttributes() {
SysSystemDto system = testHelper.createSystem(testHelper.createName());
SysSchemaObjectClassDto schema = this.createObjectClass(system);
createSchemaAttribute("__NAME__", schema);
createSchemaAttribute("first_name", schema);
// redundant to lastname
createSchemaAttribute("surname", schema);
createSchemaAttribute("lastname", schema);
// redundant to __NAME__
createSchemaAttribute("__UID__", schema);
createSchemaAttribute("email", schema);
createSchemaAttribute("titleBefore", schema);
createSchemaAttribute("title_after", schema);
createSchemaAttribute("not_exist", schema);
createPasswordSchemaAttribute("__PASSWORD__", schema);
SysSystemMappingDto mappingDto = new SysSystemMappingDto();
mappingDto.setName(testHelper.createName());
mappingDto.setEntityType(SystemEntityType.IDENTITY);
mappingDto.setObjectClass(schema.getId());
mappingDto.setOperationType(SystemOperationType.PROVISIONING);
mappingDto = mappingService.publish(new SystemMappingEvent(SystemMappingEvent.SystemMappingEventType.CREATE, mappingDto, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, true))).getContent();
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(mappingDto.getId());
List<SysSystemAttributeMappingDto> mappingAttributes = mappingAttributeService.find(attributeMappingFilter, null).getContent();
// Automatic attribute generating is enabled.
assertEquals(7, mappingAttributes.size());
SysSystemAttributeMappingDto usernameAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("__NAME__")).findFirst().orElse(null);
assertNotNull(usernameAttribute);
assertTrue(usernameAttribute.isUid());
assertEquals(IdmIdentity_.username.getName(), usernameAttribute.getIdmPropertyName());
SysSystemAttributeMappingDto lastnameAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("lastname")).findFirst().orElse(null);
assertNotNull(lastnameAttribute);
assertFalse(lastnameAttribute.isUid());
assertEquals(IdmIdentity_.lastName.getName(), lastnameAttribute.getIdmPropertyName());
SysSystemAttributeMappingDto firstNameAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("first_name")).findFirst().orElse(null);
assertNotNull(firstNameAttribute);
assertFalse(firstNameAttribute.isUid());
assertEquals(IdmIdentity_.firstName.getName(), firstNameAttribute.getIdmPropertyName());
SysSystemAttributeMappingDto titleBeforeAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("titleBefore")).findFirst().orElse(null);
assertNotNull(titleBeforeAttribute);
assertFalse(titleBeforeAttribute.isUid());
assertEquals(IdmIdentity_.titleBefore.getName(), titleBeforeAttribute.getIdmPropertyName());
SysSystemAttributeMappingDto titleAfterAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("title_after")).findFirst().orElse(null);
assertNotNull(titleAfterAttribute);
assertFalse(titleAfterAttribute.isUid());
assertEquals(IdmIdentity_.titleAfter.getName(), titleAfterAttribute.getIdmPropertyName());
SysSystemAttributeMappingDto emailAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("email")).findFirst().orElse(null);
assertNotNull(emailAttribute);
assertFalse(emailAttribute.isUid());
assertEquals(IdmIdentity_.email.getName(), emailAttribute.getIdmPropertyName());
SysSystemAttributeMappingDto passwordAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("__PASSWORD__")).findFirst().orElse(null);
assertNotNull(passwordAttribute);
assertFalse(passwordAttribute.isUid());
assertTrue(passwordAttribute.isPasswordAttribute());
}
use of eu.bcvsolutions.idm.acc.event.SystemMappingEvent in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemMappingServiceIntegrationTest method testAutomaticGenerateOfMappedAttributesRoleCatalogue.
@Test
public void testAutomaticGenerateOfMappedAttributesRoleCatalogue() {
SysSystemDto system = testHelper.createSystem(testHelper.createName());
SysSchemaObjectClassDto schema = this.createObjectClass(system);
createSchemaAttribute("__NAME__", schema);
createSchemaAttribute("parent", schema);
createSchemaAttribute("name", schema);
// redundant to __NAME__
createSchemaAttribute("code", schema);
createSchemaAttribute("description", schema);
createSchemaAttribute("not_exist", schema);
SysSystemMappingDto mappingDto = new SysSystemMappingDto();
mappingDto.setName(testHelper.createName());
mappingDto.setEntityType(SystemEntityType.ROLE_CATALOGUE);
mappingDto.setObjectClass(schema.getId());
mappingDto.setOperationType(SystemOperationType.PROVISIONING);
mappingDto = mappingService.publish(new SystemMappingEvent(SystemMappingEvent.SystemMappingEventType.CREATE, mappingDto, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, true))).getContent();
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(mappingDto.getId());
List<SysSystemAttributeMappingDto> mappingAttributes = mappingAttributeService.find(attributeMappingFilter, null).getContent();
// Automatic attribute generating is enabled.
assertEquals(4, mappingAttributes.size());
SysSystemAttributeMappingDto primaryAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("__NAME__")).findFirst().orElse(null);
assertNotNull(primaryAttribute);
assertTrue(primaryAttribute.isUid());
assertEquals(IdmRoleCatalogue_.code.getName(), primaryAttribute.getIdmPropertyName());
SysSystemAttributeMappingDto nameAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("name")).findFirst().orElse(null);
assertNotNull(nameAttribute);
assertFalse(nameAttribute.isUid());
assertEquals(IdmRoleCatalogue_.name.getName(), nameAttribute.getIdmPropertyName());
SysSystemAttributeMappingDto parentAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("parent")).findFirst().orElse(null);
assertNotNull(parentAttribute);
assertFalse(parentAttribute.isUid());
assertEquals(IdmRoleCatalogue_.parent.getName(), parentAttribute.getIdmPropertyName());
SysSystemAttributeMappingDto descriptionAttribute = mappingAttributes.stream().filter(attribute -> attribute.getName().equals("description")).findFirst().orElse(null);
assertNotNull(descriptionAttribute);
assertFalse(descriptionAttribute.isUid());
assertEquals(IdmRoleCatalogue_.description.getName(), descriptionAttribute.getIdmPropertyName());
}
use of eu.bcvsolutions.idm.acc.event.SystemMappingEvent in project CzechIdMng by bcvsolutions.
the class AdGroupConnectorType method executeStepFour.
/**
* Step for filling additional information as connector (OU) DNs. Add pairing sync.
*/
private void executeStepFour(ConnectorTypeDto connectorType) {
String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
// connectorType.getMetadata().get(GROUP_SYNC_ID);
Assert.notNull(systemId, "System ID cannot be null!");
SysSystemDto systemDto = this.getSystemService().get(systemId);
connectorType.getEmbedded().put(SYSTEM_DTO_KEY, systemDto);
IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
String port = getValueFromConnectorInstance(PORT, systemDto, connectorFormDef);
String host = getValueFromConnectorInstance(HOST, systemDto, connectorFormDef);
String user = getValueFromConnectorInstance(PRINCIPAL, systemDto, connectorFormDef);
boolean ssl = Boolean.parseBoolean(getValueFromConnectorInstance(SSL, systemDto, connectorFormDef));
String password = getConfidentialValueFromConnectorInstance(CREDENTIALS, systemDto, connectorFormDef);
String groupContainersStr = connectorType.getMetadata().get(GROUP_CONTAINER_KEY);
Assert.notNull(groupContainersStr, "Container with groups cannot be null!");
List<String> groupContainers = stringToContainers(groupContainersStr);
Assert.notEmpty(groupContainers, "Container with groups cannot be empty!");
groupContainers.forEach(groupContainer -> {
String groupContainerAD = this.findDn(MessageFormat.format("(&(distinguishedName={0})(|(objectClass=container)(objectClass=organizationalUnit)))", groupContainer), port, host, user, password, ssl);
if (Strings.isBlank(groupContainerAD)) {
throw new ResultCodeException(AccResultCode.WIZARD_AD_CONTAINER_NOT_FOUND, ImmutableMap.of("dn", groupContainer));
}
});
// Base context for search groups.
// We need to searching in all containers. So group container will be use in the base context.
List<Serializable> values = Lists.newArrayList(groupContainers);
this.setValueToConnectorInstance(BASE_CONTEXT_GROUP_KEY, values, systemDto, connectorFormDef);
// Set root suffixes and generate a schema.
SysSchemaObjectClassDto schemaDto = generateSchema(connectorType, systemDto, connectorFormDef, groupContainers.get(0), values);
// Find 'Member' schema attribute.
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setObjectClassId(schemaDto.getId());
schemaAttributeFilter.setSystemId(systemDto.getId());
schemaAttributeFilter.setName(MsAdSyncMappingRoleAutoAttributesProcessor.MEMBER_ATTR_CODE);
SysSchemaAttributeDto memberAttribute = getSchemaAttributeService().find(schemaAttributeFilter, null).stream().findFirst().orElse(null);
if (memberAttribute == null) {
// Attribute missing -> create it now.
createSchemaAttribute(schemaDto, MsAdSyncMappingRoleAutoAttributesProcessor.MEMBER_ATTR_CODE, String.class.getName(), true, false, true);
}
String mappingSyncId = connectorType.getMetadata().get(MAPPING_SYNC_ID);
if (mappingSyncId == null) {
// Create role mapping for sync.
SysSystemMappingDto mappingDto = new SysSystemMappingDto();
mappingDto.setObjectClass(schemaDto.getId());
mappingDto.setOperationType(SystemOperationType.SYNCHRONIZATION);
mappingDto.setEntityType(SystemEntityType.ROLE);
mappingDto.setName("AD role sync mapping.");
mappingDto = getSystemMappingService().publish(new SystemMappingEvent(SystemMappingEvent.SystemMappingEventType.CREATE, mappingDto, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, Boolean.TRUE))).getContent();
mappingDto = getSystemMappingService().save(mappingDto);
connectorType.getEmbedded().put(DefaultConnectorType.MAPPING_DTO_KEY, mappingDto);
connectorType.getMetadata().put(MAPPING_SYNC_ID, mappingDto.getId().toString());
} else {
SysSystemMappingDto mappingDto = getSystemMappingService().get(UUID.fromString(mappingSyncId));
connectorType.getEmbedded().put(DefaultConnectorType.MAPPING_DTO_KEY, mappingDto);
}
// Create/update role sync.
createSync(connectorType);
// Update group base contexts on the system with members.
// Will add group container to the system with members. Without that system with member will not see groups.
String memberSystemMappingId = connectorType.getMetadata().get(MEMBER_SYSTEM_MAPPING);
SysSystemMappingDto systemMappingDto = null;
if (memberSystemMappingId != null) {
systemMappingDto = getSystemMappingService().get(UUID.fromString(memberSystemMappingId), IdmBasePermission.READ);
if (systemMappingDto != null) {
SysSchemaObjectClassDto objectClassDto = DtoUtils.getEmbedded(systemMappingDto, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
Assert.notNull(objectClassDto, "Schema DTO cannot be null!");
SysSystemDto memberSystemDto = DtoUtils.getEmbedded(objectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
Assert.notNull(memberSystemDto, "Member system DTO cannot be null!");
// Find attribute with group base contexts.
IdmFormDefinitionDto memberConnectorFormDef = this.getSystemService().getConnectorFormDefinition(memberSystemDto);
IdmFormAttributeDto groupContextBaseAttribute = memberConnectorFormDef.getMappedAttributeByCode(BASE_CONTEXT_GROUP_KEY);
if (groupContextBaseAttribute != null) {
groupContainers.forEach(groupContainer -> {
List<IdmFormValueDto> groupContextBaseValues = getFormService().getValues(memberSystemDto, groupContextBaseAttribute, IdmBasePermission.READ);
if (groupContextBaseValues != null) {
boolean groupContainerSet = groupContextBaseValues.stream().anyMatch(value -> groupContainer.equals(value.getValue()));
if (!groupContainerSet) {
List<String> currentRootSuffixes = groupContextBaseValues.stream().map(IdmFormValueDto::getStringValue).collect(Collectors.toList());
List<Serializable> newRootSuffixes = Lists.newArrayList(currentRootSuffixes);
newRootSuffixes.add(groupContainer);
// Save new root suffixes to the system with members.
getFormService().saveValues(memberSystemDto, groupContextBaseAttribute, newRootSuffixes, IdmBasePermission.UPDATE);
}
}
});
}
}
}
}
use of eu.bcvsolutions.idm.acc.event.SystemMappingEvent in project CzechIdMng by bcvsolutions.
the class DefaultConnectorManagerTest method testAutoProvisioningMappingOutsideWizard.
@Test
public void testAutoProvisioningMappingOutsideWizard() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
ConnectorType connectorType = connectorManager.findConnectorTypeBySystem(systemDto);
Assert.assertEquals(DefaultConnectorType.NAME, connectorType.getConnectorName());
SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
mappingFilter.setSystemId(systemDto.getId());
SysSystemMappingDto sysSystemMappingDto = mappingService.find(mappingFilter, null).getContent().stream().findFirst().orElse(null);
Assert.assertNotNull(sysSystemMappingDto);
ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
connectorTypeDto.getMetadata().put(AbstractConnectorType.SCHEMA_ID, (sysSystemMappingDto).getObjectClass().toString());
// Delete a created mapping.
mappingService.delete(sysSystemMappingDto);
SysSystemMappingDto mappingDto = new SysSystemMappingDto();
mappingDto.setObjectClass(sysSystemMappingDto.getObjectClass());
mappingDto.setName("Mapping");
mappingDto.setEntityType(SystemEntityType.IDENTITY);
mappingDto.setOperationType(SystemOperationType.PROVISIONING);
mappingDto = mappingService.publish(new SystemMappingEvent(SystemMappingEvent.SystemMappingEventType.CREATE, mappingDto, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, true))).getContent();
// Attributes had to be created.
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(mappingDto.getId());
List<SysSystemAttributeMappingDto> attributeMappingDtos = attributeMappingService.find(attributeMappingFilter, null).getContent();
Assert.assertEquals(7, attributeMappingDtos.size());
}
use of eu.bcvsolutions.idm.acc.event.SystemMappingEvent in project CzechIdMng by bcvsolutions.
the class DefaultConnectorManagerTest method testAutoSyncMappingOutsideWizard.
@Test
public void testAutoSyncMappingOutsideWizard() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
ConnectorType connectorType = connectorManager.findConnectorTypeBySystem(systemDto);
Assert.assertEquals(DefaultConnectorType.NAME, connectorType.getConnectorName());
SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
mappingFilter.setSystemId(systemDto.getId());
SysSystemMappingDto sysSystemMappingDto = mappingService.find(mappingFilter, null).getContent().stream().findFirst().orElse(null);
Assert.assertNotNull(sysSystemMappingDto);
ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
connectorTypeDto.getMetadata().put(AbstractConnectorType.SCHEMA_ID, (sysSystemMappingDto).getObjectClass().toString());
// Delete a created mapping.
mappingService.delete(sysSystemMappingDto);
SysSystemMappingDto syncMapping = new SysSystemMappingDto();
syncMapping.setObjectClass(sysSystemMappingDto.getObjectClass());
syncMapping.setName("Mapping");
syncMapping.setEntityType(SystemEntityType.IDENTITY);
syncMapping.setOperationType(SystemOperationType.SYNCHRONIZATION);
syncMapping = mappingService.publish(new SystemMappingEvent(SystemMappingEvent.SystemMappingEventType.CREATE, syncMapping, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, true))).getContent();
// Attributes had to be created.
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(syncMapping.getId());
List<SysSystemAttributeMappingDto> attributeMappingDtos = attributeMappingService.find(attributeMappingFilter, null).getContent();
Assert.assertEquals(7, attributeMappingDtos.size());
}
Aggregations