use of eu.bcvsolutions.idm.acc.service.api.ConnectorType in project CzechIdMng by bcvsolutions.
the class DefaultConnectorManagerTest method testAutoProvisioningMappingInWizard.
@Test
public void testAutoProvisioningMappingInWizard() {
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);
connectorTypeDto.getEmbedded().put(AbstractConnectorType.SYSTEM_DTO_KEY, systemDto);
connectorTypeDto.setReopened(true);
connectorTypeDto = connectorManager.load(connectorTypeDto);
// Execute mapping step.
connectorTypeDto.setReopened(false);
connectorTypeDto.setWizardStepName(AbstractConnectorType.STEP_MAPPING);
connectorTypeDto.getMetadata().put(AbstractConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
connectorTypeDto.getMetadata().put(AbstractConnectorType.OPERATION_TYPE, SystemOperationType.PROVISIONING.name());
connectorTypeDto.getMetadata().put(AbstractConnectorType.ENTITY_TYPE, SystemEntityType.IDENTITY.name());
systemController.executeConnectorType(connectorTypeDto);
ConnectorTypeDto connectorTypeDtoAfterMappingStep = connectorManager.convertTypeToDto(connectorType);
connectorTypeDtoAfterMappingStep.getEmbedded().put(AbstractConnectorType.SYSTEM_DTO_KEY, systemDto);
connectorTypeDtoAfterMappingStep.setReopened(true);
connectorTypeDtoAfterMappingStep = connectorManager.load(connectorTypeDtoAfterMappingStep);
// Sync mapping must exist.
BaseDto mapping = connectorTypeDtoAfterMappingStep.getEmbedded().get(AbstractConnectorType.MAPPING_DTO_KEY);
Assert.assertTrue(mapping instanceof SysSystemMappingDto);
SysSystemMappingDto syncMapping = (SysSystemMappingDto) mapping;
Assert.assertSame(SystemOperationType.PROVISIONING, syncMapping.getOperationType());
// 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());
}
use of eu.bcvsolutions.idm.acc.service.api.ConnectorType 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.service.api.ConnectorType 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());
}
use of eu.bcvsolutions.idm.acc.service.api.ConnectorType in project CzechIdMng by bcvsolutions.
the class AdGroupConnectorType method executeStepOne.
/**
* Execute first step of AD wizard.
*/
protected void executeStepOne(ConnectorTypeDto connectorType) {
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!");
ConnectorType memberConnectorType = getConnectorManager().findConnectorTypeBySystem(memberSystemDto);
if (!(memberConnectorType instanceof AdUserConnectorType)) {
throw new ResultCodeException(AccResultCode.WIZARD_AD_GROUP_WRONG_MEMBER_CONNECTOR_TYPE, ImmutableMap.of("connectorType", memberConnectorType == null ? "none" : memberConnectorType.toString()));
}
ConnectorTypeDto adUserSystemMockConnectorType = new ConnectorTypeDto();
adUserSystemMockConnectorType.setReopened(true);
adUserSystemMockConnectorType.getEmbedded().put(SYSTEM_DTO_KEY, memberSystemDto);
adUserSystemMockConnectorType.getMetadata().put(SYSTEM_DTO_KEY, memberSystemDto.getId().toString());
adUserSystemMockConnectorType = super.load(adUserSystemMockConnectorType);
Map<String, String> metadata = connectorType.getMetadata();
// Find attribute with port.
metadata.put(PORT, adUserSystemMockConnectorType.getMetadata().get(PORT));
// Find attribute with host.
metadata.put(HOST, adUserSystemMockConnectorType.getMetadata().get(HOST));
// Find attribute with user.
metadata.put(USER, adUserSystemMockConnectorType.getMetadata().get(USER));
// Find attribute with ssl switch.
metadata.put(SSL_SWITCH, adUserSystemMockConnectorType.getMetadata().get(SSL_SWITCH));
// Load password.
IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(memberSystemDto);
metadata.put(PASSWORD, this.getConfidentialValueFromConnectorInstance(CREDENTIALS, memberSystemDto, connectorFormDef));
}
super.executeStepOne(connectorType);
String mappingSyncId = connectorType.getMetadata().get(MAPPING_SYNC_ID);
if (mappingSyncId == null) {
// This attributes will be updated only if system doesn't have mapping.
// Checking by existing mapping and not by reopen flag solves a problem with reopen wizard for to early closed wizard.
// For example in the certificate step.
String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
Assert.notNull(systemId, "System ID cannot be null!");
SysSystemDto systemDto = this.getSystemService().get(systemId);
initDefaultConnectorSettings(systemDto, this.getSystemService().getConnectorFormDefinition(systemDto));
}
// Get test group and find parent group container. Will be used as default group container.
if (connectorType.getMetadata().get(GROUP_CONTAINER_KEY) == null) {
String testGroup = connectorType.getMetadata().get(TEST_GROUP_KEY);
connectorType.getMetadata().put(GROUP_CONTAINER_KEY, getParent(testGroup));
}
}
use of eu.bcvsolutions.idm.acc.service.api.ConnectorType in project CzechIdMng by bcvsolutions.
the class PrepareConnectorObjectProcessor method processUpdateByAttribute.
/**
* Resolve update for given attribute
*
* @param provisioningAttribute
* @param provisioningOperation
* @param existsConnectorObject
* @param system
* @param systemEntityUid
* @param updateConnectorObject
* @param fullAccountObject
* @param schemaAttributes
*/
private void processUpdateByAttribute(ProvisioningAttributeDto provisioningAttribute, SysProvisioningOperationDto provisioningOperation, IcConnectorObject existsConnectorObject, SysSystemDto system, String systemEntityUid, IcConnectorObject updateConnectorObject, Map<ProvisioningAttributeDto, Object> fullAccountObject, List<SysSchemaAttributeDto> schemaAttributes, ConnectorType connectorType) {
Optional<SysSchemaAttributeDto> schemaAttributeOptional = //
schemaAttributes.stream().filter(schemaAttribute -> {
//
return provisioningAttribute.getSchemaAttributeName().equals(schemaAttribute.getName());
}).findFirst();
if (!schemaAttributeOptional.isPresent()) {
throw new ProvisioningException(AccResultCode.PROVISIONING_SCHEMA_ATTRIBUTE_IS_FOUND, ImmutableMap.of("attribute", provisioningAttribute.getSchemaAttributeName()));
}
SysSchemaAttributeDto schemaAttribute = schemaAttributeOptional.get();
if (schemaAttribute.isUpdateable()) {
Object idmValue = fullAccountObject.get(provisioningAttribute);
if (AttributeMappingStrategyType.CREATE == provisioningAttribute.getStrategyType()) {
return;
}
if (provisioningAttribute.isSendOnlyIfNotNull()) {
if (this.isValueEmpty(idmValue)) {
return;
}
}
if (schemaAttribute.isReturnedByDefault()) {
if (AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
boolean existSetAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
//
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.SET == provisioningAttributeKey.getStrategyType();
});
boolean existMergeAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
//
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.MERGE == provisioningAttributeKey.getStrategyType();
});
boolean existAuthMergeAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
//
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.AUTHORITATIVE_MERGE == provisioningAttributeKey.getStrategyType();
});
if (AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
List<IcAttribute> icAttributes = existsConnectorObject.getAttributes();
//
Optional<IcAttribute> icAttributeOptional = icAttributes.stream().filter(ica -> {
return schemaAttribute.getName().equals(ica.getName());
}).findFirst();
IcAttribute icAttribute = null;
if (icAttributeOptional.isPresent()) {
icAttribute = icAttributeOptional.get();
}
// We need do transform from resource first
Object transformedConnectorValue = this.transformValueFromResource(provisioningAttribute.getTransformValueFromResourceScript(), schemaAttribute, icAttribute, icAttributes, system);
if (transformedConnectorValue != null || existSetAttribute || existAuthMergeAttribute || existMergeAttribute) {
return;
}
}
}
Object resultValue = idmValue;
if (AttributeMappingStrategyType.MERGE == provisioningAttribute.getStrategyType()) {
List<Object> allConnectorValues = this.getAllConnectorValues(provisioningAttribute, existsConnectorObject);
resultValue = resolveMergeValues(provisioningAttribute, idmValue, allConnectorValues, provisioningOperation);
}
// Update attribute on resource by given mapping
// attribute and mapped value in entity
IcAttribute updatedAttribute = updateAttribute(systemEntityUid, resultValue, schemaAttribute, existsConnectorObject, system, provisioningAttribute);
// Add updated attribute to updateConnectorObject.
connectorType.addUpdatedAttribute(schemaAttribute, updatedAttribute, updateConnectorObject, existsConnectorObject);
} else {
// filled values only
if (fullAccountObject.get(provisioningAttribute) != null) {
IcAttribute createdAttribute = createAttribute(schemaAttribute, fullAccountObject.get(provisioningAttribute));
if (createdAttribute != null) {
updateConnectorObject.getAttributes().add(createdAttribute);
}
}
}
}
}
Aggregations