use of eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping_ in project CzechIdMng by bcvsolutions.
the class PrepareConnectorObjectProcessor method processCreate.
/**
* Create object on target system
*
* @param provisioningOperation
*/
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);
List<SysSystemAttributeMappingDto> passwordAttributes = attributeMappingService.getAllPasswordAttributes(system.getId(), mapping.getId());
GuardedString generatedPassword = null;
// If exists at least one password attribute generate password and try set echos for current system
if (!passwordAttributes.isEmpty()) {
// Check if exists a uniform password for this entity. If yes, then use it.
if (provisioningOperation.getEntityIdentifier() != null && provisioningOperation.getEntityType() != null && provisioningOperation.getSystem() != null && provisioningOperation.getTransactionId() != null) {
if (uniformPasswordManager.isSystemInUniformPasswordAgenda(provisioningOperation.getSystem())) {
generatedPassword = uniformPasswordManager.generateUniformPassword(provisioningOperation.getEntityIdentifier(), provisioningOperation.getEntityType().getEntityType(), provisioningOperation.getTransactionId());
}
}
if (generatedPassword == null) {
generatedPassword = generatePassword(system);
}
} else {
generatedPassword = null;
}
// Found all given password from original provisioning context, these passwords will be skipped
List<ProvisioningAttributeDto> givenPasswords = provisioningContext.getAccountObject().keySet().stream().filter(provisioningAtt -> provisioningAtt.isPasswordAttribute()).collect(Collectors.toList());
// Iterate over all password attributes founded for system and mapping
for (SysSystemAttributeMappingDto passwordAttribute : passwordAttributes) {
// Password may be add by another process or execute existing provisioning operation, these password skip
SysSchemaAttributeDto schemaByPasswordAttribute = DtoUtils.getEmbedded(passwordAttribute, SysSystemAttributeMapping_.schemaAttribute, SysSchemaAttributeDto.class);
Optional<ProvisioningAttributeDto> findAnyPassword = //
givenPasswords.stream().filter(givenPassword -> givenPassword.getSchemaAttributeName().equals(//
schemaByPasswordAttribute.getName())).findAny();
if (findAnyPassword.isPresent()) {
continue;
}
// All non existing passwords in provisioning context will be added and
// transformed. Then will be set as new attribute into fullAccountObject
GuardedString transformPassword = transformPassword(provisioningOperation, system.getId(), passwordAttribute, generatedPassword);
SysSchemaAttributeDto schemaAttribute = //
schemaAttributes.stream().filter(//
schemaAtt -> schemaAtt.getId().equals(passwordAttribute.getSchemaAttribute())).findFirst().orElse(null);
ProvisioningAttributeDto passwordProvisiongAttributeDto = ProvisioningAttributeDto.createProvisioningAttributeKey(passwordAttribute, schemaAttribute.getName(), schemaAttribute.getClassType());
fullAccountObject.put(passwordProvisiongAttributeDto, transformPassword);
// Update previous account object (gui left side)
Map<ProvisioningAttributeDto, Object> accountObject = provisioningOperation.getProvisioningContext().getAccountObject();
// Is needed put password also into account object. Complete provisioning operation can be stored in
// queue and while retry the provisioning operation is value get from confidential storage.
// Confidential key is composed by account object.
String confidentialStrorageKey = provisioningOperationService.createAccountObjectPropertyKey(passwordProvisiongAttributeDto.getKey(), 0);
confidentialStorage.saveGuardedString(provisioningOperation, confidentialStrorageKey, transformPassword);
accountObject.put(passwordProvisiongAttributeDto, new ConfidentialString(confidentialStrorageKey));
}
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)) {
// is null
continue;
}
}
if (AttributeMappingStrategyType.CREATE == provisioningAttribute.getStrategyType() || AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
boolean existSetAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
//
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.SET == provisioningAttributeKey.getStrategyType();
});
boolean existIfResourceNulltAttribute = //
fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
//
return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.WRITE_IF_NULL == 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.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.entity.SysSystemAttributeMapping_ in project CzechIdMng by bcvsolutions.
the class AttributeControlledValuesRecalculationTaskExecutor method process.
@Override
public Boolean process() {
this.counter = 0L;
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(systemId, entityType);
Assert.notNull(mapping, "Provisioning mapping is mandatory!");
// Loading all attributes for recalculation (on given system)
SysSystemAttributeMappingFilter attributeFilter = new SysSystemAttributeMappingFilter();
attributeFilter.setSystemId(systemId);
attributeFilter.setSystemMappingId(mapping.getId());
List<SysSystemAttributeMappingDto> attributes = //
systemAttributeMappingService.find(attributeFilter, null).getContent().stream().filter(//
attribute -> AttributeMappingStrategyType.MERGE == attribute.getStrategyType()).filter(//
attribute -> !onlyEvicted ? true : attribute.isEvictControlledValuesCache()).collect(Collectors.toList());
// Total items
count = Long.valueOf(attributes.size());
for (SysSystemAttributeMappingDto attribute : attributes) {
counter++;
boolean canContinue = updateState();
if (!canContinue) {
break;
}
try {
SysSchemaAttributeDto schemaAttributeDto = DtoUtils.getEmbedded(attribute, SysSystemAttributeMapping_.schemaAttribute, SysSchemaAttributeDto.class);
// Recalculate controlled values
systemAttributeMappingService.recalculateAttributeControlledValues(systemId, entityType, schemaAttributeDto.getName(), attribute);
// Success
this.logItemProcessed(attribute, new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
this.logItemProcessed(attribute, new OperationResult.Builder(OperationState.EXCEPTION).setException(new ResultCodeException(AccResultCode.PROVISIONING_EX_ATTR_CONTROLED_VALUE_RECALC, ImmutableMap.of("attribute", attribute.getName(), "system", systemId), ex)).build());
}
}
;
LOG.info("End: Merge - attribute controlled values recalculation for system [{}]", systemId);
return Boolean.TRUE;
}
Aggregations