use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class AdUserConnectorType method generateSchema.
/**
* Generate schema.
*/
protected SysSchemaObjectClassDto generateSchema(ConnectorTypeDto connectorType, SysSystemDto systemDto) {
// Generate schema
List<SysSchemaObjectClassDto> schemas = this.getSystemService().generateSchema(systemDto);
SysSchemaObjectClassDto schemaAccount = schemas.stream().filter(schema -> getSchemaType().equals(schema.getObjectClassName())).findFirst().orElse(null);
Assert.notNull(schemaAccount, MessageFormat.format("We cannot found schema for type [{0}]!", getSchemaType()));
connectorType.getMetadata().put(SCHEMA_ID_KEY, schemaAccount.getId().toString());
return schemaAccount;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class AbstractConnectorType method executeMappingStep.
/**
* Execute simple mapping step.
*
* @param connectorTypeDto
*/
private void executeMappingStep(ConnectorTypeDto connectorTypeDto) {
String schemaId = connectorTypeDto.getMetadata().get(SCHEMA_ID);
SysSchemaObjectClassDto schemaDto = null;
if (schemaId != null) {
schemaDto = schemaService.get(UUID.fromString(schemaId), IdmBasePermission.READ);
} else {
String systemId = connectorTypeDto.getMetadata().get(SYSTEM_DTO_KEY);
SysSchemaObjectClassFilter filter = new SysSchemaObjectClassFilter();
Assert.isTrue(Strings.isNotBlank(systemId), "System ID cannot be empty!");
filter.setSystemId(UUID.fromString(systemId));
List<SysSchemaObjectClassDto> schemas = schemaService.find(filter, null, IdmBasePermission.READ).getContent().stream().sorted(Comparator.comparing(SysSchemaObjectClassDto::getCreated)).collect(Collectors.toList());
if (!schemas.isEmpty()) {
schemaDto = schemas.get(0);
}
}
Assert.notNull(schemaDto, "System schema must exists!");
String entityType = connectorTypeDto.getMetadata().get(ENTITY_TYPE);
SystemEntityType systemEntityType = SystemEntityType.valueOf(entityType);
Assert.notNull(systemEntityType, "Entity type cannot be null!");
// For tree type have to be filled tree type ID too.
IdmTreeTypeDto treeTypeDto = null;
if (SystemEntityType.TREE == systemEntityType) {
String treeTypeId = connectorTypeDto.getMetadata().get(TREE_TYPE_ID);
Assert.notNull(treeTypeId, "Tree type ID cannot be null for TREE entity type!");
treeTypeDto = treeTypeService.get(UUID.fromString(treeTypeId));
Assert.notNull(treeTypeDto, "Tree type DTO cannot be null for TREE entity type!");
}
String operationType = connectorTypeDto.getMetadata().get(OPERATION_TYPE);
SystemOperationType systemOperationType = SystemOperationType.valueOf(operationType);
Assert.notNull(systemOperationType, "Operation type cannot be null!");
// Load existing mapping or create new one.
String mappingId = connectorTypeDto.getMetadata().get(MAPPING_ID);
SysSystemMappingDto mappingDto = new SysSystemMappingDto();
mappingDto.setName("Mapping");
boolean isNew = true;
if (mappingId != null) {
SysSystemMappingDto mappingExisted = systemMappingService.get(mappingId, IdmBasePermission.READ);
if (mappingExisted != null) {
isNew = false;
mappingDto = mappingExisted;
}
}
// For tree type have to be filled tree type ID too.
if (SystemEntityType.TREE == systemEntityType) {
mappingDto.setTreeType(treeTypeDto.getId());
}
mappingDto.setEntityType(systemEntityType);
mappingDto.setOperationType(systemOperationType);
mappingDto.setObjectClass(schemaDto.getId());
// Save mapping. Event must be publish with property for enable automatic mapping.
mappingDto = systemMappingService.publish(new SystemMappingEvent(isNew ? SystemMappingEvent.SystemMappingEventType.CREATE : SystemMappingEvent.SystemMappingEventType.UPDATE, mappingDto, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, Boolean.TRUE)), isNew ? IdmBasePermission.CREATE : IdmBasePermission.UPDATE).getContent();
connectorTypeDto.getEmbedded().put(MAPPING_DTO_KEY, mappingDto);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto 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.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class AdUserConnectorType method addUpdatedAttribute.
@Override
public void addUpdatedAttribute(SysSchemaAttributeDto schemaAttribute, IcAttribute updatedAttribute, IcConnectorObject updateConnectorObject, IcConnectorObject existsConnectorObject) {
if (updatedAttribute != null) {
updateConnectorObject.getAttributes().add(updatedAttribute);
// This is optimization for WinRM connector where is needed to be decided what of groups were added and removed.
if (existsConnectorObject != null) {
// Find if the system is in a group with cross-domain type and for given schema attribute.
SysSchemaObjectClassDto schemaObjectClassDto = DtoUtils.getEmbedded(schemaAttribute, SysSchemaAttribute_.objectClass, SysSchemaObjectClassDto.class);
Assert.notNull(schemaObjectClassDto, "Schema class cannot be null!");
SysSystemGroupSystemFilter systemGroupSystemFilter = new SysSystemGroupSystemFilter();
systemGroupSystemFilter.setGroupType(SystemGroupType.CROSS_DOMAIN);
systemGroupSystemFilter.setDisabled(Boolean.FALSE);
systemGroupSystemFilter.setSystemId(schemaObjectClassDto.getSystem());
systemGroupSystemFilter.setMergeAttributeCode(schemaAttribute.getName());
if (systemGroupSystemService.count(systemGroupSystemFilter) == 0) {
// Attribute is not in the cross-domain group.
return;
}
IcAttribute attributeInExists = existsConnectorObject.getAttributeByName(schemaAttribute.getName());
if (attributeInExists != null) {
IcAttributeImpl attributeWithGroupsOld = new IcAttributeImpl();
attributeWithGroupsOld.setName(MessageFormat.format(OLD_ATTRIBUTE_PATTERN, schemaAttribute.getName()));
attributeWithGroupsOld.setMultiValue(true);
attributeWithGroupsOld.setValues(attributeInExists.getValues());
updateConnectorObject.getAttributes().add(attributeWithGroupsOld);
existsConnectorObject.getAttributes().add(attributeWithGroupsOld);
}
}
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class CsvConnectorType method executeStepTwo.
/**
* Execute second step of CSV wizard.
*
* @param connectorType
*/
private void executeStepTwo(ConnectorTypeDto connectorType) {
String schemaAttributeId = connectorType.getMetadata().get(PRIMARY_SCHEMA_ATTRIBUTE);
Assert.notNull(schemaAttributeId, "Schema attribute ID cannot be null!");
SysSchemaAttributeDto schemaAttributeDto = schemaAttributeService.get(UUID.fromString(schemaAttributeId), IdmBasePermission.READ);
Assert.notNull(schemaAttributeDto, "Schema attribute cannot be null!");
String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
Assert.notNull(systemId, "System ID cannot be null!");
SysSystemDto systemDto = getSystemService().get(UUID.fromString(systemId), IdmBasePermission.READ);
Assert.notNull(systemDto, "System cannot be null!");
// Find and update attribute defines UID attribute.
IdmFormDefinitionDto connectorFormDef = getSystemService().getConnectorFormDefinition(systemDto);
IdmFormAttributeDto uidAttribute = connectorFormDef.getMappedAttributeByCode(CONNECTOR_UID);
List<Serializable> uidValue = new ArrayList<>();
uidValue.add(schemaAttributeDto.getName());
formService.saveValues(systemDto, uidAttribute, uidValue);
// Generate schema - again, for create primary attribute __NAME__.
List<SysSchemaObjectClassDto> schemas = getSystemService().generateSchema(systemDto);
SysSchemaObjectClassDto schemaAccount = schemas.stream().filter(schema -> IcObjectClassInfo.ACCOUNT.equals(schema.getObjectClassName())).findFirst().orElse(null);
Assert.notNull(schemaAccount, "We cannot found schema for ACCOUNT!");
}
Aggregations