use of eu.bcvsolutions.idm.ic.api.IcConnectorObject 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.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 DefaultAccAccountService method getConnectorObject.
@Override
public IcConnectorObject getConnectorObject(AccAccountDto account, BasePermission... permissions) {
Assert.notNull(account, "Account cannot be null!");
this.checkAccess(account, permissions);
List<SysSchemaAttributeDto> schemaAttributes = this.getSchemaAttributes(account.getSystem(), null);
if (schemaAttributes == null) {
return null;
}
try {
// Find connector-type.
SysSystemDto systemDto = lookupService.lookupEmbeddedDto(account, AccAccount_.system);
ConnectorType connectorType = connectorManager.findConnectorTypeBySystem(systemDto);
// Find first mapping for entity type and system, from the account and return his object class.
IcObjectClass icObjectClass = schemaObjectClassService.findByAccount(account.getSystem(), account.getEntityType());
IcConnectorObject fullObject = this.systemService.readConnectorObject(account.getSystem(), account.getRealUid(), icObjectClass, connectorType);
return this.getConnectorObjectForSchema(fullObject, schemaAttributes);
} catch (Exception ex) {
SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system, SysSystemDto.class);
throw new ResultCodeException(AccResultCode.ACCOUNT_CANNOT_BE_READ_FROM_TARGET, ImmutableMap.of("account", account.getUid(), "system", system != null ? system.getName() : account.getSystem()), ex);
}
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningOperationService method getFullConnectorObject.
/**
* Returns fully loaded ConnectorObject with guarded strings.
*
* TODO: don't update connectorObject in provisioningOperation (needs attribute defensive clone)
*
* @param provisioningOperation
* @return
*/
@Override
public IcConnectorObject getFullConnectorObject(SysProvisioningOperationDto provisioningOperation) {
if (provisioningOperation == null || provisioningOperation.getProvisioningContext() == null || provisioningOperation.getProvisioningContext().getConnectorObject() == null) {
return null;
}
List<IcAttribute> attributes = new ArrayList<>();
//
IcConnectorObject connectorObject = provisioningOperation.getProvisioningContext().getConnectorObject();
connectorObject.getAttributes().forEach(attribute -> {
IcAttribute attributeCopy = null;
if (attribute.isMultiValue()) {
List<Object> values = (List<Object>) attribute.getValues();
attributeCopy = new IcAttributeImpl(attribute.getName(), values, true);
} else if (attribute instanceof IcPasswordAttribute && attribute.getValue() != null) {
attributeCopy = new IcPasswordAttributeImpl(attribute.getName(), confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) attribute.getValue()).getKey()));
} else if (attribute instanceof IcPasswordAttribute && attribute.getValue() == null) {
attributeCopy = new IcPasswordAttributeImpl(attribute.getName(), (GuardedString) null);
} else if (attribute.getValue() instanceof ConfidentialString) {
attributeCopy = new IcAttributeImpl(attribute.getName(), confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) attribute.getValue()).getKey()));
} else {
attributeCopy = new IcAttributeImpl(attribute.getName(), attribute.getValue());
}
attributes.add(attributeCopy);
});
IcConnectorObject newConnectorObject = new IcConnectorObjectImpl(connectorObject.getUidValue(), connectorObject.getObjectClass(), attributes);
return newConnectorObject;
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method handleIcObject.
/**
* Handle IC connector object
*
* @param itemContext
* @return
*/
protected boolean handleIcObject(SynchronizationContext itemContext) {
Assert.notNull(itemContext, "Item context is required.");
IcConnectorObject icObject = itemContext.getIcObject();
AbstractSysSyncConfigDto config = itemContext.getConfig();
SysSyncLogDto log = itemContext.getLog();
AttributeMapping tokenAttribute = itemContext.getTokenAttribute();
SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
// Synchronization by custom filter not supported DELETE
// event
IcSyncDeltaTypeEnum type = IcSyncDeltaTypeEnum.CREATE_OR_UPDATE;
itemContext.addLogItem(itemLog).addType(type);
// Find token by token attribute
// For Reconciliation can be token attribute null
Object tokenObj = null;
if (tokenAttribute != null) {
tokenObj = getValueByMappedAttribute(tokenAttribute, icObject.getAttributes(), itemContext);
}
// Token is saved in Sync as String, therefore we transform token (from
// IcObject) to String too.
String token = tokenObj != null ? tokenObj.toString() : null;
// grater token to config and log.
if (token != null && config.getToken() != null && token.compareTo(config.getToken()) <= -1) {
token = config.getToken();
}
// Save token
log.setToken(token);
if (!config.isReconciliation()) {
config.setToken(token);
}
boolean result = startItemSynchronization(itemContext);
// sync or LRT)
return updateAndCheckState(result, log);
}
Aggregations