Search in sources :

Example 91 with SysSchemaObjectClassDto

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;
}
Also used : SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Example 92 with SysSchemaObjectClassDto

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);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SystemMappingEvent(eu.bcvsolutions.idm.acc.event.SystemMappingEvent) SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) SysSchemaObjectClassFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Example 93 with SysSchemaObjectClassDto

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));
    }
}
Also used : ConnectorTypeDto(eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto) ConnectorType(eu.bcvsolutions.idm.acc.service.api.ConnectorType) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 94 with SysSchemaObjectClassDto

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);
            }
        }
    }
}
Also used : SysSystemGroupSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupSystemFilter) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Example 95 with SysSchemaObjectClassDto

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!");
}
Also used : Serializable(java.io.Serializable) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ArrayList(java.util.ArrayList) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Aggregations

SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)156 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)125 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)114 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)65 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)63 Test (org.junit.Test)59 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)44 SysSchemaAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter)38 UUID (java.util.UUID)32 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)29 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)28 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)25 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)21 SysSystemMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter)21 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)21 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)20 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)19 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)19 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)18 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)17