use of eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningProcessor method process.
/**
* Prepare provisioning operation execution
*/
@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
SysProvisioningOperationDto provisioningOperation = event.getContent();
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
IcConnectorObject connectorObject = provisioningOperation.getProvisioningContext().getConnectorObject();
IcObjectClass objectClass = connectorObject.getObjectClass();
String uid = systemEntityService.getByProvisioningOperation(provisioningOperation).getUid();
LOG.debug("Start provisioning operation [{}] for object with uid [{}] and connector object [{}]", provisioningOperation.getOperationType(), uid, objectClass.getType());
// Find connector identification persisted in system
if (system.getConnectorKey() == null) {
throw new ProvisioningException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// load connector configuration
IcConnectorConfiguration connectorConfig = systemService.getConnectorConfiguration(systemService.get(provisioningOperation.getSystem()));
if (connectorConfig == null) {
throw new ProvisioningException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
//
try {
provisioningOperation = provisioningOperationService.save(provisioningOperation);
// convert confidential string to guarded strings before provisioning realization
connectorObject = provisioningOperationService.getFullConnectorObject(provisioningOperation);
provisioningOperation.getProvisioningContext().setConnectorObject(connectorObject);
//
IcUidAttribute resultUid = processInternal(provisioningOperation, connectorConfig);
// update system entity, when identifier on target system differs
if (resultUid != null && resultUid.getUidValue() != null) {
SysSystemEntityDto systemEntity = systemEntityService.getByProvisioningOperation(provisioningOperation);
// If system entity was not found, we try found system entity by returned UID
if (systemEntity == null) {
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, provisioningOperation.getEntityType(), resultUid.getUidValue());
}
Asserts.notNull(systemEntity, "Systeme entity cannot be null!");
if (!systemEntity.getUid().equals(resultUid.getUidValue()) || systemEntity.isWish()) {
systemEntity.setUid(resultUid.getUidValue());
systemEntity.setWish(false);
systemEntity = systemEntityService.save(systemEntity);
LOG.info("UID was changed. System entity with uid [{}] was updated", systemEntity.getUid());
}
}
provisioningOperationService.handleSuccessful(provisioningOperation);
} catch (Exception ex) {
provisioningOperationService.handleFailed(provisioningOperation, ex);
}
// set operation back to content
event.setContent(provisioningOperation);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto in project CzechIdMng by bcvsolutions.
the class DisabledSystemProcessor method process.
@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
SysProvisioningOperationDto provisioningOperation = event.getContent();
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
String uid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
boolean closed = false;
if (system.isDisabled()) {
ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_SYSTEM_DISABLED, ImmutableMap.of("name", uid, "system", system.getName()));
provisioningOperation.setResult(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(resultModel).build());
//
provisioningOperation = provisioningOperationService.save(provisioningOperation);
//
LOG.info(resultModel.toString());
notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
//
closed = true;
}
// set back to event content
event.setContent(provisioningOperation);
return new DefaultEventResult<>(event, this, closed);
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto in project CzechIdMng by bcvsolutions.
the class PrepareConnectorObjectProcessor method processCreate.
/**
* Create object on target system
*
* @param provisioningOperation
* @param connectorConfig
*/
private void processCreate(SysProvisioningOperationDto provisioningOperation) {
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
ProvisioningContext provisioningContext = provisioningOperation.getProvisioningContext();
IcConnectorObject connectorObject = provisioningContext.getConnectorObject();
//
// prepare provisioning attributes from account attributes
Map<ProvisioningAttributeDto, Object> fullAccountObject = provisioningOperationService.getFullAccountObject(provisioningOperation);
if (fullAccountObject != null) {
connectorObject.getAttributes().clear();
SysSystemMappingDto mapping = getMapping(system, provisioningOperation.getEntityType());
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
List<SysSchemaAttributeDto> schemaAttributes = findSchemaAttributes(system, schemaObjectClassDto);
for (Entry<ProvisioningAttributeDto, Object> entry : fullAccountObject.entrySet()) {
ProvisioningAttributeDto provisioningAttribute = entry.getKey();
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()));
}
Object idmValue = fullAccountObject.get(provisioningAttribute);
SysSchemaAttributeDto schemaAttribute = schemaAttributeOptional.get();
if (provisioningAttribute.isSendOnlyIfNotNull()) {
if (this.isValueEmpty(idmValue)) {
// Skip this attribute (marked with flag sendOnlyIfNotNull), because IdM value is null
continue;
}
}
if (AttributeMappingStrategyType.CREATE == provisioningAttribute.getStrategyType() || AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
boolean existSetAttribute = fullAccountObject.keySet().stream().filter(provisioningAttributeKey -> {
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.SET == provisioningAttributeKey.getStrategyType();
}).findFirst().isPresent();
boolean existIfResourceNulltAttribute = fullAccountObject.keySet().stream().filter(provisioningAttributeKey -> {
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttributeKey.getStrategyType();
}).findFirst().isPresent();
boolean existMergeAttribute = fullAccountObject.keySet().stream().filter(provisioningAttributeKey -> {
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.MERGE == provisioningAttributeKey.getStrategyType();
}).findFirst().isPresent();
boolean existAuthMergeAttribute = fullAccountObject.keySet().stream().filter(provisioningAttributeKey -> {
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.AUTHORITATIVE_MERGE == provisioningAttributeKey.getStrategyType();
}).findFirst().isPresent();
if (AttributeMappingStrategyType.CREATE == provisioningAttribute.getStrategyType()) {
if (existIfResourceNulltAttribute || existSetAttribute || existAuthMergeAttribute || existMergeAttribute) {
// (this strategies has higher priority)
continue;
}
}
if (AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
if (existSetAttribute || existAuthMergeAttribute || existMergeAttribute) {
// (this strategies has higher priority)
continue;
}
}
}
IcAttribute createdAttribute = createAttribute(schemaAttribute, fullAccountObject.get(provisioningAttribute));
if (createdAttribute != null) {
connectorObject.getAttributes().add(createdAttribute);
}
}
provisioningContext.setConnectorObject(connectorObject);
}
provisioningOperation.setOperationType(ProvisioningEventType.CREATE);
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto in project CzechIdMng by bcvsolutions.
the class PrepareConnectorObjectProcessor method processUpdate.
@SuppressWarnings("unchecked")
private void processUpdate(SysProvisioningOperationDto provisioningOperation, IcConnectorConfiguration connectorConfig, IcConnectorObject existsConnectorObject) {
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
String systemEntityUid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
ProvisioningContext provisioningContext = provisioningOperation.getProvisioningContext();
IcConnectorObject connectorObject = provisioningContext.getConnectorObject();
IcObjectClass objectClass = connectorObject.getObjectClass();
//
IcConnectorObject updateConnectorObject;
if (provisioningContext.getAccountObject() == null) {
updateConnectorObject = connectorObject;
} else {
Map<ProvisioningAttributeDto, Object> fullAccountObject = provisioningOperationService.getFullAccountObject(provisioningOperation);
updateConnectorObject = new IcConnectorObjectImpl(systemEntityUid, objectClass, null);
SysSystemMappingDto mapping = getMapping(system, provisioningOperation.getEntityType());
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
List<SysSchemaAttributeDto> schemaAttributes = findSchemaAttributes(system, schemaObjectClassDto);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setEntityIdentifier(provisioningOperation.getEntityIdentifier());
filter.setEntityType(provisioningOperation.getEntityType());
filter.setResultState(OperationState.EXECUTED);
SysProvisioningArchiveDto lastSuccessEntity = null;
for (Entry<ProvisioningAttributeDto, Object> entry : fullAccountObject.entrySet()) {
ProvisioningAttributeDto provisioningAttribute = entry.getKey();
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()) {
if (schemaAttribute.isReturnedByDefault()) {
Object idmValue = fullAccountObject.get(provisioningAttribute);
IcAttribute attribute = existsConnectorObject.getAttributeByName(schemaAttribute.getName());
Object connectorValue = attribute != null ? (attribute.isMultiValue() ? attribute.getValues() : attribute.getValue()) : null;
Object resultValue = idmValue;
if (AttributeMappingStrategyType.CREATE == provisioningAttribute.getStrategyType()) {
// We do update, attributes with create strategy will be skipped
continue;
}
if (provisioningAttribute.isSendOnlyIfNotNull()) {
if (this.isValueEmpty(idmValue)) {
// Skip this attribute (marked with flag sendOnlyIfNotNull), because idm value is null
continue;
}
}
if (AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
boolean existSetAttribute = fullAccountObject.keySet().stream().filter(provisioningAttributeKey -> {
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.SET == provisioningAttributeKey.getStrategyType();
}).findFirst().isPresent();
boolean existMergeAttribute = fullAccountObject.keySet().stream().filter(provisioningAttributeKey -> {
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.MERGE == provisioningAttributeKey.getStrategyType();
}).findFirst().isPresent();
boolean existAuthMergeAttribute = fullAccountObject.keySet().stream().filter(provisioningAttributeKey -> {
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.AUTHORITATIVE_MERGE == provisioningAttributeKey.getStrategyType();
}).findFirst().isPresent();
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) {
// or exists same attribute with SET/MERGE/AUTH_MERGE strategy (this strategies has higher priority)
continue;
}
}
}
if (AttributeMappingStrategyType.MERGE == provisioningAttribute.getStrategyType()) {
// Load last provisioning history
if (lastSuccessEntity == null) {
List<SysProvisioningArchiveDto> lastSuccessEntities = provisioningArchiveService.find(filter, new PageRequest(0, 1, new Sort(Direction.DESC, MODIFIED_FIELD_NAME))).getContent();
if (!lastSuccessEntities.isEmpty()) {
lastSuccessEntity = lastSuccessEntities.get(0);
}
}
// Merge IdM values with connector values
if (connectorValue instanceof List) {
List<Object> connectorValues = new ArrayList<>((List<Object>) connectorValue);
List<Object> idmValues = null;
if (idmValue instanceof List) {
idmValues = (List<Object>) idmValue;
}
if (idmValues != null) {
idmValues.stream().forEach(value -> {
if (!connectorValues.contains(value)) {
connectorValues.add(value);
}
});
}
resultValue = connectorValues;
}
// Delete missing values by last provisioning history
if (lastSuccessEntity != null && lastSuccessEntity.getProvisioningContext() != null && lastSuccessEntity.getProvisioningContext().getAccountObject() != null && lastSuccessEntity.getProvisioningContext().getAccountObject().containsKey(provisioningAttribute)) {
Object oldValue = lastSuccessEntity.getProvisioningContext().getAccountObject().get(provisioningAttribute);
if (oldValue instanceof List) {
if (!oldValue.equals(idmValue)) {
// Search all deleted values (managed by IdM) by founded last provisioning values
List<?> deletedValues = ((List<?>) oldValue).stream().filter(value -> {
List<?> idmValues = null;
if (idmValue instanceof List) {
idmValues = (List<?>) idmValue;
}
if (idmValues != null && idmValues.contains(value)) {
return false;
}
return true;
}).collect(Collectors.toList());
if (resultValue instanceof List) {
List<?> resultValues = new ArrayList<>((List<Object>) resultValue);
// Remove all deleted values (managed by IdM)
resultValues.removeAll(deletedValues);
resultValue = resultValues;
}
}
}
}
}
// Update attribute on resource by given mapping
// attribute and mapped value in entity
IcAttribute updatedAttribute = updateAttribute(systemEntityUid, resultValue, schemaAttribute, existsConnectorObject, system, provisioningAttribute);
if (updatedAttribute != null) {
updateConnectorObject.getAttributes().add(updatedAttribute);
}
} else {
// filled values only
if (fullAccountObject.get(provisioningAttribute) != null) {
IcAttribute createdAttribute = createAttribute(schemaAttribute, fullAccountObject.get(provisioningAttribute));
if (createdAttribute != null) {
updateConnectorObject.getAttributes().add(createdAttribute);
}
}
}
}
}
}
//
provisioningOperation.getProvisioningContext().setConnectorObject(updateConnectorObject);
provisioningOperation.setOperationType(ProvisioningEventType.UPDATE);
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessor method process.
@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
try {
SysProvisioningOperationDto provisioningOperation = event.getContent();
ProvisioningEventType operationType = provisioningOperation.getOperationType();
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
// system may be blocked
boolean blocked = isSystemBlockedOperation(operationType, system);
//
if (blocked) {
// system is already blocked
provisioningOperation = blockOperation(provisioningOperation, system);
event.setContent(provisioningOperation);
return new DefaultEventResult<>(event, this, blocked);
}
//
// try found provisioning break configuration
SysProvisioningBreakConfigDto breakConfig = breakConfigService.getConfig(operationType, system.getId());
if (breakConfig == null) {
LOG.debug("Provisioning break configuration for system name: [{}] and operation: [{}] not found. Global configuration will be used.", system.getCode(), operationType.toString());
breakConfig = breakConfigService.getGlobalBreakConfiguration(operationType);
}
//
if (breakConfig == null) {
LOG.debug("Global configuration for provisioning break isn't found.");
return new DefaultEventResult<>(event, this, blocked);
}
//
if (breakConfig.isDisabled()) {
LOG.debug("Provisioning break configuration id: [{}] for system name: [{}] and operation: [{}] is disabled.", breakConfig.getId(), system.getCode(), operationType.toString());
// break configuration is disable continue
return new DefaultEventResult<>(event, this, blocked);
}
Long currentTimeMillis = System.currentTimeMillis();
//
// get cache for system
SysProvisioningBreakItems cache = breakConfigService.getCacheProcessedItems(system.getId());
// calculate timestamp without period
Long timestampWithoutPeriod = currentTimeMillis - breakConfig.getPeriod(TimeUnit.MILLISECONDS);
// remove older records
cache.removeOlderRecordsThan(operationType, timestampWithoutPeriod);
// get actual count - processed items from timestampWithoutPeriod
int actualCount = cache.getSizeRecordsNewerThan(operationType, timestampWithoutPeriod);
// operation count is sum all previous operation except this operation
if (breakConfig.getWarningLimit() != null && breakConfig.getWarningLimit().equals(actualCount)) {
// disabled may be null
if (breakConfig.getDisableLimit() == null) {
LOG.warn("Block for the system id [{}] and operation [{}] is not set. Operation counter [{}].", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), actualCount);
} else {
LOG.warn("To block the system id [{}] for operation [{}] remains [{}] operations + send message.", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), breakConfig.getDisableLimit() - actualCount);
}
IdmNotificationTemplateDto template = null;
if (breakConfig.getWarningTemplate() == null) {
LOG.debug("Warning template for provisioning break id [{}] missing.", breakConfig.getId());
} else {
template = DtoUtils.getEmbedded(breakConfig, SysProvisioningBreakConfig_.warningTemplate, IdmNotificationTemplateDto.class);
}
//
sendMessage(AccModuleDescriptor.TOPIC_PROVISIONING_BREAK_WARNING, system, actualCount, template, breakConfig, operationType, cache.getDiffBetweenActualAndLast(operationType, currentTimeMillis));
} else if (breakConfig.getDisableLimit() != null && actualCount >= breakConfig.getDisableLimit()) {
// check count is higher than disable limit
// block system for operation
blockSystemForOperation(operationType, system);
//
IdmNotificationTemplateDto template = null;
if (breakConfig.getWarningTemplate() == null) {
LOG.debug("Warning template for provisioning break id [{}] missing.", breakConfig.getId());
} else {
template = DtoUtils.getEmbedded(breakConfig, SysProvisioningBreakConfig_.disableTemplate, IdmNotificationTemplateDto.class);
}
//
sendMessage(AccModuleDescriptor.TOPIC_PROVISIONING_BREAK_DISABLE, system, actualCount, template, breakConfig, operationType, cache.getDiffBetweenActualAndLast(operationType, currentTimeMillis));
//
LOG.warn("System id: [{}] will be blocked for operation: [{}].", provisioningOperation.getSystem(), operationType.toString());
provisioningOperation = blockOperation(provisioningOperation, system);
blocked = true;
} else if (breakConfig.getWarningLimit() != null && actualCount > breakConfig.getWarningLimit()) {
// after overrun warning limit, isn't send any another notification - add at least log
if (breakConfig.getDisableLimit() == null) {
LOG.warn("Block for the system id [{}] and operation [{}] is not set. Operation counter [{}].", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), actualCount);
} else {
LOG.warn("To block the system id [{}] for operation [{}] remains [{}] operations.", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), breakConfig.getDisableLimit() - actualCount);
}
}
// remove all unless items in cache
cache.addItem(operationType, currentTimeMillis);
breakConfigService.saveCacheProcessedItems(provisioningOperation.getSystem(), cache);
//
event.setContent(provisioningOperation);
return new DefaultEventResult<>(event, this, blocked);
} catch (Exception ex) {
LOG.error("Unexpect error while evaluate provisioning break.", ex);
throw new ProvisioningException(AccResultCode.PROVISIONING_FAILED, ex);
}
}
Aggregations