use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class RoleCatalogueSyncTest method initData.
private void initData(String suffix) {
// create test system
system = helper.createSystem("role_catalogue_resource");
system.setName(helper.createName());
system = systemService.save(system);
// key to EAV
IdmFormDefinitionDto formDefinition = systemService.getConnectorFormDefinition(system);
formService.saveValues(system, formDefinition, "keyColumn", ImmutableList.of("ID"));
// generate schema for system
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
// Create synchronization mapping
SysSystemMappingDto syncSystemMapping = new SysSystemMappingDto();
syncSystemMapping.setName("default_" + System.currentTimeMillis());
syncSystemMapping.setEntityType(SystemEntityType.ROLE_CATALOGUE);
syncSystemMapping.setOperationType(SystemOperationType.SYNCHRONIZATION);
syncSystemMapping.setObjectClass(objectClasses.get(0).getId());
final SysSystemMappingDto syncMapping = systemMappingService.save(syncSystemMapping);
createMapping(system, syncMapping);
initTreeData(suffix);
syncConfigService.find(null).getContent().forEach(config -> {
syncConfigService.delete(config);
});
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class SystemMappingDeleteProcessor method process.
@Override
public EventResult<SysSystemMappingDto> process(EntityEvent<SysSystemMappingDto> event) {
SysSystemMappingDto systemMapping = event.getContent();
UUID systemMappingId = systemMapping.getId();
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
//
List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.findRoleConfigBySystemMapping(systemMappingId);
if (!forceDelete) {
if (syncConfigService.countBySystemMapping(systemMapping) > 0) {
SysSchemaObjectClassDto objectClassDto = DtoUtils.getEmbedded(systemMapping, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
SysSystemDto systemDto = DtoUtils.getEmbedded(objectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
throw new ResultCodeException(AccResultCode.SYSTEM_MAPPING_DELETE_FAILED_USED_IN_SYNC, ImmutableMap.of("mapping", systemMapping.getName(), "system", systemDto.getName()));
}
if (syncConfigs.size() > 0) {
SysSystemMappingDto systemMappingDto = DtoUtils.getEmbedded(syncConfigs.get(0), SysSyncRoleConfig_.systemMapping, SysSystemMappingDto.class);
SysSchemaObjectClassDto objectClassDto = DtoUtils.getEmbedded(systemMappingDto, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
SysSystemDto systemDto = DtoUtils.getEmbedded(objectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
throw new ResultCodeException(AccResultCode.SYSTEM_MAPPING_DELETE_FAILED_USED_IN_SYNC, ImmutableMap.of("mapping", systemMapping.getName(), "system", systemDto.getName()));
}
} else {
SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
syncFilter.setSystemMappingId(systemMappingId);
syncConfigService.find(syncFilter, null).forEach(syncConfig -> {
SyncConfigEvent syncConfigEvent = new SyncConfigEvent(SyncConfigEventType.DELETE, syncConfig);
//
syncConfigService.publish(syncConfigEvent, event);
});
//
syncConfigs.forEach(syncConfig -> {
SyncConfigEvent syncConfigEvent = new SyncConfigEvent(SyncConfigEventType.DELETE, syncConfig);
//
syncConfigService.publish(syncConfigEvent, event);
});
}
//
// remove all handled attributes
SysSystemAttributeMappingFilter filter = new SysSystemAttributeMappingFilter();
filter.setSystemMappingId(systemMapping.getId());
systemAttributeMappingService.find(filter, null).forEach(systemAttributeMapping -> {
systemAttributeMappingService.delete(systemAttributeMapping);
});
//
// delete mapped roles
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setSystemMappingId(systemMapping.getId());
roleSystemService.find(roleSystemFilter, null).forEach(roleSystem -> {
roleSystemService.delete(roleSystem);
});
//
systemMappingService.deleteInternal(systemMapping);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class MsAdMappingIdentityAutoAttributesProcessor method conditional.
@Override
public boolean conditional(EntityEvent<SysSystemMappingDto> event) {
boolean conditional = super.conditional(event);
if (!conditional) {
return false;
}
SysSystemMappingDto systemMappingDto = event.getContent();
// Attributes will be generated only for __ACCOUNT__ schema.
SysSchemaObjectClassDto objectClassDto = lookupService.lookupEmbeddedDto(systemMappingDto, SysSystemMapping_.objectClass);
if (objectClassDto != null && objectClassDto.getSystem() != null) {
SysSystemDto systemDto = lookupService.lookupEmbeddedDto(objectClassDto, SysSchemaObjectClass_.system);
ConnectorType connectorType = connectorManager.findConnectorTypeBySystem(systemDto);
if (connectorType != null) {
// Only for AD user and AD+WinRM user wizards.
return connectorType instanceof AdUserConnectorType;
}
}
return false;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto 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.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class CsvConnectorType method executeStepOne.
/**
* Execute first step of CSV wizard.
*
* @param connectorType
*/
private void executeStepOne(ConnectorTypeDto connectorType) {
// Validations:
String csvPath = connectorType.getMetadata().get(FILE_PATH);
if (Strings.isBlank(csvPath)) {
throw new ResultCodeException(AccResultCode.WIZARD_CSV_CONNECTOR_CSV_FILE_NOT_FOUND, ImmutableMap.of("path", "-"));
}
Path csvFilePath = Paths.get(csvPath);
if (!csvFilePath.toFile().exists()) {
throw new ResultCodeException(AccResultCode.WIZARD_CSV_CONNECTOR_CSV_FILE_NOT_FOUND, ImmutableMap.of("path", csvPath));
}
String lastPart = csvFilePath.getFileName().toString();
if (lastPart == null || !lastPart.contains(".")) {
// Last part isn't file!
throw new ResultCodeException(AccResultCode.WIZARD_CSV_CONNECTOR_CSV_FILE_NOT_FOUND, ImmutableMap.of("path", csvPath));
}
String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
SysSystemDto systemDto;
if (systemId != null) {
// System already exists.
systemDto = getSystemService().get(UUID.fromString(systemId), IdmBasePermission.READ);
} else {
// Create new system.
systemDto = new SysSystemDto();
}
systemDto.setName(connectorType.getMetadata().get(SYSTEM_NAME));
// Resolve remote system.
systemDto.setRemoteServer(connectorType.getRemoteServer());
// Find connector key and set it to the system.
IcConnectorKey connectorKey = connectorManager.findConnectorKey(connectorType);
Assert.notNull(connectorKey, "Connector key was not found!");
systemDto.setConnectorKey(new SysConnectorKeyDto(connectorKey));
systemDto = getSystemService().save(systemDto, IdmBasePermission.CREATE);
// Put new system to the connector type (will be returned to FE).
connectorType.getEmbedded().put(SYSTEM_DTO_KEY, systemDto);
// Find and update attribute with CSV file path.
IdmFormDefinitionDto connectorFormDef = getSystemService().getConnectorFormDefinition(systemDto);
IdmFormAttributeDto csvFilePathAttribute = connectorFormDef.getMappedAttributeByCode(CONNECTOR_SOURCE_PATH);
List<Serializable> csvFileValue = new ArrayList<>();
csvFileValue.add(csvFilePath.toString());
formService.saveValues(systemDto, csvFilePathAttribute, csvFileValue);
// Find and update attribute contains separator.
IdmFormAttributeDto separatorAttribute = connectorFormDef.getMappedAttributeByCode(CONNECTOR_SEPARATOR);
List<Serializable> separatorValue = new ArrayList<>();
separatorValue.add(connectorType.getMetadata().get(SEPARATOR));
formService.saveValues(systemDto, separatorAttribute, separatorValue);
// Find and update attribute defines if headers are included in the file.
IdmFormAttributeDto includeHeaderAttribute = connectorFormDef.getMappedAttributeByCode(CONNECTOR_INCLUDES_HEADERS);
List<Serializable> includesHeaderValue = new ArrayList<>();
includesHeaderValue.add(Boolean.TRUE);
formService.saveValues(systemDto, includeHeaderAttribute, includesHeaderValue);
// This is skipped for reopen case.
if (!connectorType.isReopened()) {
// Find and update attribute defines UID attribute.
// UID attribute have to be filled before schema generating, but I don't know it (I need list of column first).
// So UID attribute will be set to random value, and modified in next step.
IdmFormAttributeDto uidAttribute = connectorFormDef.getMappedAttributeByCode(CONNECTOR_UID);
List<Serializable> uidValue = new ArrayList<>();
uidValue.add("...random...");
formService.saveValues(systemDto, uidAttribute, uidValue);
// Load existing sync from system and delete them (because this wizard step could be repeated).
SysSyncConfigFilter syncConfigFilter = new SysSyncConfigFilter();
syncConfigFilter.setSystemId(systemDto.getId());
syncConfigService.find(syncConfigFilter, null).getContent().forEach(syncConfigDto -> syncConfigService.delete(syncConfigDto));
// Load existing object class from system and delete them (because this wizard step could be repeated).
SysSchemaObjectClassFilter objectClassFilter = new SysSchemaObjectClassFilter();
objectClassFilter.setSystemId(systemDto.getId());
objectClassService.find(objectClassFilter, null).getContent().forEach(sysSchemaObjectClassDto -> objectClassService.delete(sysSchemaObjectClassDto));
// Generate schema
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!");
// Attribute __NAME__ is generate for random value. We need delete him now (will be generated in next wizard step).
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
Assert.notNull(schemaAccount.getId(), "Schema ID cannot be null!");
schemaAttributeFilter.setObjectClassId(schemaAccount.getId());
schemaAttributeFilter.setName(IcAttributeInfo.NAME);
schemaAttributeService.find(schemaAttributeFilter, null).getContent().forEach(nameAttribute -> schemaAttributeService.delete(nameAttribute));
connectorType.getMetadata().put(SCHEMA_ID_KEY, schemaAccount.getId().toString());
} else {
// Generate schema
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!");
connectorType.getMetadata().put(SCHEMA_ID_KEY, schemaAccount.getId().toString());
}
}
Aggregations