use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method getWishConnectorObject.
@Override
public VsConnectorObjectDto getWishConnectorObject(VsRequestDto request) {
LOG.info(MessageFormat.format("Start read wish connector object [{0}].", request));
Assert.notNull(request, "VS request cannot be null!");
List<VsAttributeDto> resultAttributes = new ArrayList<>();
IcConnectorObject realConnectorObject = this.getVsConnectorObject(request);
IcConnectorObject currentObject = realConnectorObject != null ? realConnectorObject : new IcConnectorObjectImpl();
IcConnectorObject changeObject = request.getConnectorObject() != null ? request.getConnectorObject() : new IcConnectorObjectImpl();
List<IcAttribute> currentAttributes = currentObject.getAttributes();
List<IcAttribute> changedAttributes = request.getConnectorObject().getAttributes();
// First add all new attributes
changedAttributes.forEach(changedAttribute -> {
if (currentObject.getAttributeByName(changedAttribute.getName()) == null) {
VsAttributeDto vsAttribute = new VsAttributeDto(changedAttribute.getName(), changedAttribute.isMultiValue(), true);
if (changedAttribute.isMultiValue()) {
if (changedAttribute.getValues() != null) {
changedAttribute.getValues().forEach(value -> {
vsAttribute.getValues().add(new VsAttributeValueDto(value, null, VsValueChangeType.ADDED));
});
}
} else {
vsAttribute.setValue(new VsAttributeValueDto(changedAttribute.getValue(), null, VsValueChangeType.ADDED));
}
resultAttributes.add(vsAttribute);
}
});
// Second add all already exists attributes
currentAttributes.forEach(currentAttribute -> {
VsAttributeDto vsAttribute;
// Attribute was changed
if (changeObject.getAttributeByName(currentAttribute.getName()) != null) {
vsAttribute = new VsAttributeDto(currentAttribute.getName(), currentAttribute.isMultiValue(), true);
IcAttribute changedAttribute = changeObject.getAttributeByName(currentAttribute.getName());
if (changedAttribute.isMultiValue()) {
if (changedAttribute.getValues() != null) {
changedAttribute.getValues().forEach(value -> {
if (currentAttribute.getValues() != null && currentAttribute.getValues().contains(value)) {
vsAttribute.getValues().add(new VsAttributeValueDto(value, value, null));
} else {
vsAttribute.getValues().add(new VsAttributeValueDto(value, null, VsValueChangeType.ADDED));
}
});
}
if (currentAttribute.getValues() != null) {
currentAttribute.getValues().forEach(value -> {
if (changedAttribute.getValues() == null || !changedAttribute.getValues().contains(value)) {
vsAttribute.getValues().add(new VsAttributeValueDto(value, value, VsValueChangeType.REMOVED));
}
});
}
} else {
Object changedValue = changedAttribute.getValue();
Object currentValue = currentAttribute.getValue();
if ((changedValue == null && currentValue == null) || (changedValue != null && changedValue.equals(currentObject)) || (currentValue != null && currentValue.equals(changedValue))) {
vsAttribute.setValue(new VsAttributeValueDto(changedValue, currentValue, null));
} else {
vsAttribute.setValue(new VsAttributeValueDto(changedValue, currentValue, VsValueChangeType.UPDATED));
}
}
} else {
// Attribute was not changed
vsAttribute = new VsAttributeDto(currentAttribute.getName(), currentAttribute.isMultiValue(), false);
if (currentAttribute.isMultiValue()) {
if (currentAttribute.getValues() != null) {
currentAttribute.getValues().forEach(value -> {
vsAttribute.getValues().add(new VsAttributeValueDto(value, value, null));
});
}
} else {
vsAttribute.setValue(new VsAttributeValueDto(currentAttribute.getValue(), currentAttribute.getValue(), null));
}
}
resultAttributes.add(vsAttribute);
});
BasicVirtualConfiguration configuration = getVirtualConnector(request).getVirtualConfiguration();
// result list
if (!configuration.isDisableSupported()) {
VsAttributeDto enableAttribute = resultAttributes.stream().filter(attribute -> attribute.getName().equals(IcAttributeInfo.ENABLE)).findFirst().orElse(null);
if (enableAttribute != null) {
resultAttributes.remove(enableAttribute);
}
}
VsConnectorObjectDto wishObject = new VsConnectorObjectDto();
wishObject.setUid(request.getUid());
wishObject.setAttributes(resultAttributes);
return wishObject;
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class VsReqeustServiceTest method systemAccountFilterTest.
@Test
public void systemAccountFilterTest() {
SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
this.assignRoleSystem(system, helper.createIdentity(USER_ONE_NAME), ROLE_ONE_NAME);
// Find created requests
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setUid(USER_ONE_NAME);
List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(1, requests.size());
VsRequestDto request = requests.get(0);
Assert.assertEquals(USER_ONE_NAME, request.getUid());
Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
VsAccountDto account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
Assert.assertNull("Account must be null, because request was not realized yet!", account);
// We try realize the request
super.logout();
loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
request = requestService.realize(request);
Assert.assertEquals(VsRequestState.REALIZED, request.getState());
account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
Assert.assertNotNull("Account cannot be null, because request was realized!", account);
IcConnectorConfiguration configuration = systemService.getConnectorConfiguration(system);
IcObjectClass objectClass = new IcObjectClassImpl("__ACCOUNT__");
List<String> uids = new ArrayList<>();
connectorFacade.search(system.getConnectorInstance(), configuration, objectClass, null, new IcResultsHandler() {
@Override
public boolean handle(IcConnectorObject connectorObject) {
uids.add(connectorObject.getUidValue());
return true;
}
});
Assert.assertEquals(1, uids.size());
Assert.assertEquals(USER_ONE_NAME, uids.get(0));
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject 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.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class PrepareConnectorObjectProcessor method updateAttribute.
/**
* Update attribute on resource by given handling attribute and mapped value
* in entity
*
* @param uid
* @param entity
* @param attributeMapping
* @param schemaAttribute
* @param connectorObject
*/
private IcAttribute updateAttribute(String uid, Object idmValue, SysSchemaAttributeDto schemaAttribute, IcConnectorObject existsConnectorObject, SysSystemDto system, ProvisioningAttributeDto provisioningAttributeDto) {
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();
}
return updateAttributeValue(uid, idmValue, schemaAttribute, icAttribute, icAttributes, system, provisioningAttributeDto.getTransformValueFromResourceScript(), provisioningAttributeDto.isSendAlways());
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject 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;
}
Aggregations