use of eu.bcvsolutions.idm.ic.api.IcUidAttribute in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method internalExecute.
@Override
public IcUidAttribute internalExecute(VsRequestDto request) {
request.setState(VsRequestState.REALIZED);
Assert.notNull(request.getConfiguration(), "Request have to contains connector configuration!");
Assert.notNull(request.getConnectorKey(), "Request have to contains connector key!");
// Find connector by request
VsVirtualConnector virtualConnector = getVirtualConnector(request);
IcUidAttribute result = null;
// Save the request
this.save(request);
switch(request.getOperationType()) {
case CREATE:
{
result = virtualConnector.internalCreate(request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
break;
}
case UPDATE:
{
VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
if (account == null) {
throw new VsException(VsResultCode.VS_REQUEST_UPDATING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
}
result = virtualConnector.internalUpdate(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
break;
}
case DELETE:
{
VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
if (account == null) {
throw new VsException(VsResultCode.VS_REQUEST_DELETING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
}
virtualConnector.internalDelete(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass());
// All unresolved request created before this delete request will be
// canceled
VsRequestFilter filter = new VsRequestFilter();
filter.setCreatedBefore(request.getCreated());
filter.setUid(request.getUid());
filter.setSystemId(request.getSystem());
filter.setState(VsRequestState.IN_PROGRESS);
// Unresolved request created before this request
List<VsRequestDto> beforeRequests = this.find(filter, null).getContent();
beforeRequests.forEach(beforeRequest -> {
String reason = MessageFormat.format("Request [{0}] was canceled (by SYSTEM), because 'after' delete request [{1}] was realized!", beforeRequest.getId(), request.getId());
this.cancel(beforeRequest, reason);
LOG.info(reason);
});
break;
}
default:
throw new IcException(MessageFormat.format("Unsupported operation type [{0}]", request.getOperationType()));
}
return result;
}
use of eu.bcvsolutions.idm.ic.api.IcUidAttribute in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method realize.
@Override
@Transactional
public VsRequestDto realize(VsRequestDto request) {
LOG.info(MessageFormat.format("Start realize virtual system request [{0}].", request));
Assert.notNull(request, "VS request cannot be null!");
this.checkAccess(request, IdmBasePermission.UPDATE);
if (VsRequestState.IN_PROGRESS != request.getState()) {
throw new VsException(VsResultCode.VS_REQUEST_REALIZE_WRONG_STATE, ImmutableMap.of("state", VsRequestState.IN_PROGRESS.name(), "currentState", request.getState()));
}
request.setState(VsRequestState.REALIZED);
// Realize request ... propagate change to VS account.
IcUidAttribute uidAttribute = this.internalExecute(request);
// Save realized request
request = this.save(request);
LOG.info(MessageFormat.format("Virtual system request [{0}] was realized. Output UID attribute: [{1}]", request, uidAttribute));
return request;
}
use of eu.bcvsolutions.idm.ic.api.IcUidAttribute in project CzechIdMng by bcvsolutions.
the class PrepareConnectorObjectProcessor method process.
/**
* Prepare provisioning operation execution
*/
@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
SysProvisioningOperationDto provisioningOperation = event.getContent();
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
IcObjectClass objectClass = provisioningOperation.getProvisioningContext().getConnectorObject().getObjectClass();
SysSystemEntityDto systemEntity = provisioningOperationService.getByProvisioningOperation(provisioningOperation);
String uid = systemEntity.getUid();
boolean isWish = systemEntity.isWish();
LOG.debug("Start preparing attribubes for 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(system);
if (connectorConfig == null) {
throw new ProvisioningException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
//
try {
IcConnectorObject existsConnectorObject = null;
// call the connector and auto mapping is not allowed.
if (!(isWish && !provisioningConfiguration.isAllowedAutoMappingOnExistingAccount())) {
IcUidAttribute uidAttribute = new IcUidAttributeImpl(null, uid, null);
existsConnectorObject = connectorFacade.readObject(system.getConnectorInstance(), connectorConfig, objectClass, uidAttribute);
}
if (existsConnectorObject == null) {
processCreate(provisioningOperation);
} else {
processUpdate(provisioningOperation, connectorConfig, existsConnectorObject);
}
//
LOG.debug("Preparing attribubes for provisioning operation [{}] for object with uid [{}] and connector object [{}] is sucessfully completed", provisioningOperation.getOperationType(), uid, objectClass.getType());
// set back to event content
provisioningOperation = provisioningOperationService.save(provisioningOperation);
event.setContent(provisioningOperation);
return new DefaultEventResult<>(event, this);
} catch (Exception ex) {
ResultModel resultModel;
if (ex instanceof ResultCodeException) {
resultModel = ((ResultCodeException) ex).getError().getError();
} else {
resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_PREPARE_ACCOUNT_ATTRIBUTES_FAILED, ImmutableMap.of("name", uid, "system", system.getName(), "operationType", provisioningOperation.getOperationType(), "objectClass", objectClass.getType()));
}
LOG.error(resultModel.toString(), ex);
provisioningOperation.setResult(new OperationResult.Builder(OperationState.EXCEPTION).setModel(resultModel).setCause(ex).build());
//
provisioningOperation = provisioningOperationService.save(provisioningOperation);
//
notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
// set back to event content
event.setContent(provisioningOperation);
return new DefaultEventResult<>(event, this, true);
}
}
use of eu.bcvsolutions.idm.ic.api.IcUidAttribute in project CzechIdMng by bcvsolutions.
the class ProvisioningDeleteProcessor method processInternal.
@Override
public IcUidAttribute processInternal(SysProvisioningOperationDto provisioningOperation, IcConnectorConfiguration connectorConfig) {
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
IcConnectorInstance connectorInstance = systemService.getConnectorInstance(system);
String uid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
IcUidAttribute uidAttribute = new IcUidAttributeImpl(null, uid, null);
IcObjectClass objectClass = provisioningOperation.getProvisioningContext().getConnectorObject().getObjectClass();
//
IcConnectorObject connectorObject = connectorFacade.readObject(connectorInstance, connectorConfig, objectClass, uidAttribute);
if (connectorObject != null) {
connectorFacade.deleteObject(connectorInstance, connectorConfig, objectClass, uidAttribute);
}
return null;
}
use of eu.bcvsolutions.idm.ic.api.IcUidAttribute in project CzechIdMng by bcvsolutions.
the class ProvisioningUpdateProcessor method processInternal.
@Override
public IcUidAttribute processInternal(SysProvisioningOperationDto provisioningOperation, IcConnectorConfiguration connectorConfig) {
String uid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
IcUidAttribute uidAttribute = new IcUidAttributeImpl(null, uid, null);
IcConnectorObject connectorObject = provisioningOperation.getProvisioningContext().getConnectorObject();
if (!connectorObject.getAttributes().isEmpty()) {
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
return connectorFacade.updateObject(systemService.getConnectorInstance(system), connectorConfig, connectorObject.getObjectClass(), uidAttribute, connectorObject.getAttributes());
} else {
// TODO: appropriate message - provisioning is not executed - attributes don't change
// Operation was logged only. Provisioning was not executes, because attributes does'nt change.
}
return null;
}
Aggregations