use of eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method prepareProvisioning.
private SysProvisioningOperationDto prepareProvisioning(SysSystemEntityDto systemEntity, DTO dto, UUID entityId, ProvisioningOperationType operationType, List<? extends AttributeMapping> attributes) {
Assert.notNull(systemEntity);
Assert.notNull(systemEntity.getUid());
Assert.notNull(systemEntity.getEntityType());
SysSystemDto system = DtoUtils.getEmbedded(systemEntity, SysSystemEntity_.system, SysSystemDto.class);
Assert.notNull(system);
// If are input attributes null, then we load default mapped attributes
if (attributes == null) {
attributes = findAttributeMappings(system, systemEntity.getEntityType());
}
if (attributes == null || attributes.isEmpty()) {
return null;
}
// Find connector identification persisted in system
IcConnectorKey connectorKey = system.getConnectorKey();
if (connectorKey == null) {
throw new ProvisioningException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Find connector configuration persisted in system
IcConnectorConfiguration connectorConfig = systemService.getConnectorConfiguration(system);
if (connectorConfig == null) {
throw new ProvisioningException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// One IDM object can be mapped to one connector object (= one connector
// class).
SysSystemMappingDto mapping = getMapping(system, systemEntity.getEntityType());
if (mapping == null) {
// TODO: delete operation?
return null;
}
//
Map<ProvisioningAttributeDto, Object> accountAttributes = prepareMappedAttributesValues(dto, operationType, systemEntity, attributes);
// public provisioning event
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
IcConnectorObject connectorObject = new IcConnectorObjectImpl(systemEntity.getUid(), new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName()), null);
SysProvisioningOperationDto.Builder operationBuilder = new SysProvisioningOperationDto.Builder().setOperationType(operationType).setSystemEntity(systemEntity).setEntityIdentifier(entityId).setProvisioningContext(new ProvisioningContext(accountAttributes, connectorObject));
//
return operationBuilder.build();
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto in project CzechIdMng by bcvsolutions.
the class DefaultProvisioningExecutor method execute.
@Override
public OperationResult execute(SysProvisioningBatchDto batch) {
Assert.notNull(batch);
batch = batchService.get(batch.getId());
//
OperationResult result = null;
for (SysProvisioningOperationDto provisioningOperation : provisioningOperationService.getByTimelineAndBatchId(batch.getId())) {
// It not possible to get operation from embedded, because missing request
// not run in transaction
SysProvisioningOperationDto operation = executeInternal(provisioningOperation);
result = operation.getResult();
if (OperationState.EXECUTED != result.getState()) {
// stop processing next requests
return result;
}
}
// last processed request state (previous requests will be OperationState.EXECUTED)
return result;
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningOperationService method getFullAccountObject.
/**
* Returns fully loaded AccountObject with guarded strings.
*
* @param provisioningOperation
* @return
*/
@Override
public Map<ProvisioningAttributeDto, Object> getFullAccountObject(SysProvisioningOperationDto provisioningOperation) {
if (provisioningOperation == null || provisioningOperation.getProvisioningContext() == null || provisioningOperation.getProvisioningContext().getAccountObject() == null) {
return null;
}
//
Map<ProvisioningAttributeDto, Object> fullAccountObject = new HashMap<>();
Map<ProvisioningAttributeDto, Object> accountObject = provisioningOperation.getProvisioningContext().getAccountObject();
for (Entry<ProvisioningAttributeDto, Object> entry : accountObject.entrySet()) {
if (entry.getValue() == null) {
fullAccountObject.put(entry.getKey(), entry.getValue());
continue;
}
Object idmValue = entry.getValue();
// single value
if (idmValue instanceof ConfidentialString) {
fullAccountObject.put(entry.getKey(), confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) idmValue).getKey()));
continue;
}
// array
if (idmValue.getClass().isArray()) {
if (!idmValue.getClass().getComponentType().isPrimitive()) {
// objects only, we dont want pto proces byte, boolean etc.
Object[] idmValues = (Object[]) idmValue;
List<GuardedString> processedValues = new ArrayList<>();
for (int j = 0; j < idmValues.length; j++) {
Object singleValue = idmValues[j];
if (singleValue instanceof ConfidentialString) {
processedValues.add(confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) singleValue).getKey()));
}
}
if (!processedValues.isEmpty()) {
fullAccountObject.put(entry.getKey(), processedValues.toArray(new GuardedString[processedValues.size()]));
continue;
}
}
} else // collection
if (idmValue instanceof Collection) {
Collection<?> idmValues = (Collection<?>) idmValue;
List<GuardedString> processedValues = new ArrayList<>();
idmValues.forEach(singleValue -> {
if (singleValue instanceof ConfidentialString) {
processedValues.add(confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) singleValue).getKey()));
}
});
if (!processedValues.isEmpty()) {
fullAccountObject.put(entry.getKey(), processedValues);
continue;
}
}
// copy value
fullAccountObject.put(entry.getKey(), entry.getValue());
}
return fullAccountObject;
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningOperationService method handleFailed.
@Override
@Transactional
public SysProvisioningOperationDto handleFailed(SysProvisioningOperationDto operation, Exception ex) {
SysSystemDto system = systemService.get(operation.getSystem());
String uid = this.getByProvisioningOperation(operation).getUid();
ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_FAILED, ImmutableMap.of("name", uid, "system", system.getName(), "operationType", operation.getOperationType(), "objectClass", operation.getProvisioningContext().getConnectorObject().getObjectClass().getType()));
LOG.error(resultModel.toString(), ex);
//
operation.increaseAttempt();
// TODO: from configuration
operation.setMaxAttempts(6);
operation.setResult(new OperationResult.Builder(OperationState.EXCEPTION).setCode(resultModel.getStatusEnum()).setModel(resultModel).setCause(ex).build());
//
operation = save(operation);
//
// calculate next attempt
SysProvisioningOperationDto firstOperation = getFirstOperationByBatchId(operation.getBatch());
if (firstOperation.equals(operation)) {
SysProvisioningBatchDto batch = batchService.get(operation.getBatch());
batch.setNextAttempt(batchService.calculateNextAttempt(operation));
batch = batchService.save(batch);
}
//
if (securityService.getCurrentId() != null) {
// TODO: check account owner
notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
}
return operation;
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemServiceTest method testReferentialIntegrityProvisioningOperationExists.
@Test(expected = ResultCodeException.class)
public void testReferentialIntegrityProvisioningOperationExists() {
SysSystemDto system = new SysSystemDto();
String systemName = "t_s_" + System.currentTimeMillis();
system.setName(systemName);
system = systemService.save(system);
// system entity
SysSystemEntityDto systemEntity = new SysSystemEntityDto();
systemEntity.setUid("test");
systemEntity.setSystem(system.getId());
systemEntity.setEntityType(SystemEntityType.IDENTITY);
systemEntity = systemEntityService.save(systemEntity);
SysProvisioningOperationDto provisioningOperation = new SysProvisioningOperationDto();
provisioningOperation.setSystem(system.getId());
provisioningOperation.setEntityType(SystemEntityType.IDENTITY);
provisioningOperation.setOperationType(ProvisioningEventType.CREATE);
provisioningOperation.setSystemEntity(systemEntity.getId());
provisioningOperation.setEntityIdentifier(UUID.randomUUID());
provisioningOperation.setProvisioningContext(new ProvisioningContext());
provisioningOperation.setResult(new OperationResult());
provisioningOperationService.save(provisioningOperation);
//
systemService.delete(system);
}
Aggregations