use of com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method retrieveResourceSchema.
private void retrieveResourceSchema(List<QName> generateObjectClasses, OperationResult parentResult) throws CommunicationException, ConfigurationException, GenericFrameworkException {
// Connector operation cannot create result for itself, so we need to
// create result for it
OperationResult icfResult = parentResult.createSubresult(ConnectorFacade.class.getName() + ".schema");
icfResult.addContext("connector", connIdConnectorFacade.getClass());
org.identityconnectors.framework.common.objects.Schema icfSchema = null;
try {
// Fetch the schema from the connector (which actually gets that
// from the resource).
InternalMonitor.recordConnectorOperation("schema");
// TODO have context present
//recordIcfOperationStart(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null);
icfSchema = connIdConnectorFacade.schema();
//recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null);
icfResult.recordSuccess();
} catch (UnsupportedOperationException ex) {
//recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null, ex);
// The connector does no support schema() operation.
icfResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, ex.getMessage());
resetResourceSchema();
return;
} catch (Throwable ex) {
//recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null, ex);
// conditions.
// Therefore this kind of heavy artillery is necessary.
// ICF interface does not specify exceptions or other error
// TODO maybe we can try to catch at least some specific exceptions
Throwable midpointEx = processIcfException(ex, this, icfResult);
// exception
if (midpointEx instanceof CommunicationException) {
icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof ConfigurationException) {
icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
throw (ConfigurationException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof RuntimeException) {
icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
throw (RuntimeException) midpointEx;
} else if (midpointEx instanceof Error) {
icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
throw (Error) midpointEx;
} else {
icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
}
}
if (icfSchema == null) {
icfResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Null schema returned");
resetResourceSchema();
return;
}
parseResourceSchema(icfSchema, generateObjectClasses);
}
use of com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method fetchObject.
@Override
public <T extends ShadowType> PrismObject<T> fetchObject(Class<T> type, ResourceObjectIdentification resourceObjectIdentification, AttributesToReturn attributesToReturn, StateReporter reporter, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException, SecurityViolationException, ConfigurationException {
Validate.notNull(resourceObjectIdentification, "Null primary identifiers");
ObjectClassComplexTypeDefinition objectClassDefinition = resourceObjectIdentification.getObjectClassDefinition();
// Result type for this operation
OperationResult result = parentResult.createMinorSubresult(ConnectorInstance.class.getName() + ".fetchObject");
result.addParam("resourceObjectDefinition", objectClassDefinition);
result.addParam("identification", resourceObjectIdentification);
result.addContext("connector", connectorType);
if (connIdConnectorFacade == null) {
result.recordFatalError("Attempt to use unconfigured connector");
throw new IllegalStateException("Attempt to use unconfigured connector " + ObjectTypeUtil.toShortString(connectorType) + " " + description);
}
// Get UID from the set of identifiers
Uid uid;
try {
uid = getUid(resourceObjectIdentification);
} catch (SchemaException e) {
result.recordFatalError(e);
throw e;
}
if (uid == null) {
result.recordFatalError("Required attribute UID not found in identification set while attempting to fetch object identified by " + resourceObjectIdentification + " from " + description);
throw new IllegalArgumentException("Required attribute UID not found in identification set while attempting to fetch object identified by " + resourceObjectIdentification + " from " + description);
}
ObjectClass icfObjectClass = connIdNameMapper.objectClassToIcf(objectClassDefinition, getSchemaNamespace(), connectorType, legacySchema);
if (icfObjectClass == null) {
result.recordFatalError("Unable to determine object class from QName " + objectClassDefinition.getTypeName() + " while attempting to fetch object identified by " + resourceObjectIdentification + " from " + description);
throw new IllegalArgumentException("Unable to determine object class from QName " + objectClassDefinition.getTypeName() + " while attempting to fetch object identified by " + resourceObjectIdentification + " from " + description);
}
OperationOptionsBuilder optionsBuilder = new OperationOptionsBuilder();
convertToIcfAttrsToGet(objectClassDefinition, attributesToReturn, optionsBuilder);
optionsBuilder.setAllowPartialResults(true);
OperationOptions options = optionsBuilder.build();
ConnectorObject co = null;
try {
// Invoke the ICF connector
co = fetchConnectorObject(reporter, objectClassDefinition, icfObjectClass, uid, options, result);
} catch (CommunicationException ex) {
result.recordFatalError(ex);
// exception.
throw ex;
} catch (GenericFrameworkException ex) {
result.recordFatalError(ex);
// exception.
throw ex;
} catch (ConfigurationException ex) {
result.recordFatalError(ex);
throw ex;
} catch (SecurityViolationException ex) {
result.recordFatalError(ex);
throw ex;
} catch (ObjectNotFoundException ex) {
result.recordFatalError("Object not found");
throw new ObjectNotFoundException("Object identified by " + resourceObjectIdentification + " (ConnId UID " + uid + "), objectClass " + objectClassDefinition.getTypeName() + " was not found in " + description);
} catch (SchemaException ex) {
result.recordFatalError(ex);
throw ex;
} catch (RuntimeException ex) {
result.recordFatalError(ex);
throw ex;
}
if (co == null) {
result.recordFatalError("Object not found");
throw new ObjectNotFoundException("Object identified by " + resourceObjectIdentification + " (ConnId UID " + uid + "), objectClass " + objectClassDefinition.getTypeName() + " was not in " + description);
}
PrismObjectDefinition<T> shadowDefinition = toShadowDefinition(objectClassDefinition);
PrismObject<T> shadow = connIdConvertor.convertToResourceObject(co, shadowDefinition, false, caseIgnoreAttributeNames, legacySchema);
result.recordSuccess();
return shadow;
}
use of com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method fetchCapabilities.
@Override
public Collection<Object> fetchCapabilities(OperationResult parentResult) throws CommunicationException, GenericFrameworkException, ConfigurationException {
// Result type for this operation
OperationResult result = parentResult.createMinorSubresult(ConnectorInstance.class.getName() + ".fetchCapabilities");
result.addContext("connector", connectorType);
try {
boolean supportsSchema = processOperationCapabilities(result);
if (supportsSchema) {
LOGGER.trace("Connector instance {} does not support schema, skipping", this);
// we need to get schema to figure out all the capabilities
retrieveResourceSchema(null, result);
}
} catch (CommunicationException ex) {
result.recordFatalError(ex);
throw ex;
} catch (ConfigurationException ex) {
result.recordFatalError(ex);
throw ex;
} catch (GenericFrameworkException ex) {
result.recordFatalError(ex);
throw ex;
}
result.recordSuccess();
return capabilities;
}
use of com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method search.
@Override
public <T extends ShadowType> SearchResultMetadata search(final ObjectClassComplexTypeDefinition objectClassDefinition, final ObjectQuery query, final ResultHandler<T> handler, AttributesToReturn attributesToReturn, PagedSearchCapabilityType pagedSearchCapabilityType, SearchHierarchyConstraints searchHierarchyConstraints, final StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SecurityViolationException, SchemaException, ObjectNotFoundException {
// Result type for this operation
final OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".search");
result.addParam("objectClass", objectClassDefinition);
result.addContext("connector", connectorType);
if (objectClassDefinition == null) {
result.recordFatalError("Object class not defined");
throw new IllegalArgumentException("objectClass not defined");
}
ObjectClass icfObjectClass = connIdNameMapper.objectClassToIcf(objectClassDefinition, getSchemaNamespace(), connectorType, legacySchema);
if (icfObjectClass == null) {
IllegalArgumentException ex = new IllegalArgumentException("Unable to determine object class from QName " + objectClassDefinition + " while attempting to search objects by " + ObjectTypeUtil.toShortString(connectorType));
result.recordFatalError("Unable to determine object class", ex);
throw ex;
}
final PrismObjectDefinition<T> objectDefinition = toShadowDefinition(objectClassDefinition);
if (pagedSearchCapabilityType == null) {
pagedSearchCapabilityType = getCapability(PagedSearchCapabilityType.class);
}
final boolean useConnectorPaging = pagedSearchCapabilityType != null;
if (!useConnectorPaging && query != null && query.getPaging() != null && (query.getPaging().getOffset() != null || query.getPaging().getMaxSize() != null)) {
InternalMonitor.recordConnectorSimulatedPagingSearchCount();
}
final Holder<Integer> countHolder = new Holder<>(0);
ResultsHandler icfHandler = new ResultsHandler() {
@Override
public boolean handle(ConnectorObject connectorObject) {
// Convert ICF-specific connector object to a generic
// ResourceObject
recordIcfOperationSuspend(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition);
int count = countHolder.getValue();
countHolder.setValue(count + 1);
if (!useConnectorPaging) {
if (query != null && query.getPaging() != null && query.getPaging().getOffset() != null && query.getPaging().getMaxSize() != null) {
if (count < query.getPaging().getOffset()) {
recordResume();
return true;
}
if (count == (query.getPaging().getOffset() + query.getPaging().getMaxSize())) {
recordResume();
return false;
}
}
}
PrismObject<T> resourceObject;
try {
resourceObject = connIdConvertor.convertToResourceObject(connectorObject, objectDefinition, false, caseIgnoreAttributeNames, legacySchema);
} catch (SchemaException e) {
recordResume();
throw new IntermediateException(e);
}
// .. and pass it to the handler
boolean cont = handler.handle(resourceObject);
if (!cont) {
result.recordWarning("Stopped on request from the handler");
}
recordResume();
return cont;
}
private void recordResume() {
recordIcfOperationResume(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition);
}
};
OperationOptionsBuilder optionsBuilder = new OperationOptionsBuilder();
try {
convertToIcfAttrsToGet(objectClassDefinition, attributesToReturn, optionsBuilder);
if (query != null && query.isAllowPartialResults()) {
optionsBuilder.setAllowPartialResults(query.isAllowPartialResults());
}
// preparing paging-related options
if (useConnectorPaging && query != null && query.getPaging() != null) {
ObjectPaging paging = query.getPaging();
if (paging.getOffset() != null) {
// ConnId API says the numbering starts at 1
optionsBuilder.setPagedResultsOffset(paging.getOffset() + 1);
}
if (paging.getMaxSize() != null) {
optionsBuilder.setPageSize(paging.getMaxSize());
}
QName orderByAttributeName;
boolean isAscending;
ItemPath orderByPath = paging.getOrderBy();
String desc;
if (orderByPath != null && !orderByPath.isEmpty()) {
orderByAttributeName = ShadowUtil.getAttributeName(orderByPath, "OrderBy path");
if (SchemaConstants.C_NAME.equals(orderByAttributeName)) {
orderByAttributeName = SchemaConstants.ICFS_NAME;
}
isAscending = paging.getDirection() != OrderDirection.DESCENDING;
desc = "(explicitly specified orderBy attribute)";
} else {
orderByAttributeName = pagedSearchCapabilityType.getDefaultSortField();
isAscending = pagedSearchCapabilityType.getDefaultSortDirection() != OrderDirectionType.DESCENDING;
desc = "(default orderBy attribute from capability definition)";
}
if (orderByAttributeName != null) {
String orderByIcfName = connIdNameMapper.convertAttributeNameToIcf(orderByAttributeName, objectClassDefinition, desc);
optionsBuilder.setSortKeys(new SortKey(orderByIcfName, isAscending));
}
}
if (searchHierarchyConstraints != null) {
ResourceObjectIdentification baseContextIdentification = searchHierarchyConstraints.getBaseContext();
// Only LDAP connector really supports base context. And this one will work better with
// DN. And DN is secondary identifier (__NAME__). This is ugly, but practical. It works around ConnId problems.
ResourceAttribute<?> secondaryIdentifier = baseContextIdentification.getSecondaryIdentifier();
if (secondaryIdentifier == null) {
SchemaException e = new SchemaException("No secondary identifier in base context identification " + baseContextIdentification);
result.recordFatalError(e);
throw e;
}
String secondaryIdentifierValue = secondaryIdentifier.getRealValue(String.class);
ObjectClass baseContextIcfObjectClass = connIdNameMapper.objectClassToIcf(baseContextIdentification.getObjectClassDefinition(), getSchemaNamespace(), connectorType, legacySchema);
QualifiedUid containerQualifiedUid = new QualifiedUid(baseContextIcfObjectClass, new Uid(secondaryIdentifierValue));
optionsBuilder.setContainer(containerQualifiedUid);
}
} catch (SchemaException e) {
result.recordFatalError(e);
throw e;
}
// Relax completeness requirements. This is a search, not get. So it is OK to
// return incomplete member lists and similar attributes.
optionsBuilder.setAllowPartialAttributeValues(true);
OperationOptions options = optionsBuilder.build();
Filter filter;
try {
filter = convertFilterToIcf(query, objectClassDefinition);
} catch (SchemaException | RuntimeException e) {
result.recordFatalError(e);
throw e;
}
// Connector operation cannot create result for itself, so we need to
// create result for it
OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + ".search");
icfResult.addArbitraryObjectAsParam("objectClass", icfObjectClass);
icfResult.addContext("connector", connIdConnectorFacade.getClass());
SearchResult icfSearchResult;
try {
InternalMonitor.recordConnectorOperation("search");
recordIcfOperationStart(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition);
icfSearchResult = connIdConnectorFacade.search(icfObjectClass, filter, icfHandler, options);
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition);
icfResult.recordSuccess();
} catch (IntermediateException inex) {
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition, inex);
SchemaException ex = (SchemaException) inex.getCause();
icfResult.recordFatalError(ex);
result.recordFatalError(ex);
throw ex;
} catch (Throwable ex) {
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SEARCH, objectClassDefinition, ex);
Throwable midpointEx = processIcfException(ex, this, icfResult);
result.computeStatus();
// exception
if (midpointEx instanceof CommunicationException) {
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof SchemaException) {
throw (SchemaException) midpointEx;
} else if (midpointEx instanceof SecurityViolationException) {
throw (SecurityViolationException) midpointEx;
} else if (midpointEx instanceof RuntimeException) {
throw (RuntimeException) midpointEx;
} else if (midpointEx instanceof Error) {
throw (Error) midpointEx;
} else {
throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
}
}
SearchResultMetadata metadata = null;
if (icfSearchResult != null) {
metadata = new SearchResultMetadata();
metadata.setPagingCookie(icfSearchResult.getPagedResultsCookie());
if (icfSearchResult.getRemainingPagedResults() >= 0) {
metadata.setApproxNumberOfAllResults(icfSearchResult.getRemainingPagedResults());
}
if (!icfSearchResult.isAllResultsReturned()) {
metadata.setPartialResults(true);
}
}
if (result.isUnknown()) {
result.recordSuccess();
}
return metadata;
}
use of com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException in project midpoint by Evolveum.
the class ConfigurationExceptionHandler method handleError.
@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException {
if (!doDiscovery) {
parentResult.recordFatalError(ex);
if (ex instanceof ConfigurationException) {
throw (ConfigurationException) ex;
} else {
throw new ConfigurationException(ex.getMessage(), ex);
}
}
ObjectDelta delta = null;
switch(op) {
case ADD:
delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
break;
case DELETE:
delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
break;
case MODIFY:
Collection<? extends ItemDelta> modifications = null;
if (shadow.getObjectChange() != null) {
ObjectDeltaType deltaType = shadow.getObjectChange();
modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
}
delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
break;
case GET:
OperationResult operationResult = parentResult.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ConfigurationExceptionHandler.handleError." + op.name());
operationResult.addParam("shadow", shadow);
operationResult.addParam("currentOperation", op);
operationResult.addParam("exception", ex.getMessage());
for (OperationResult subRes : parentResult.getSubresults()) {
subRes.muteError();
}
operationResult.recordPartialError("Could not get " + ObjectTypeUtil.toShortString(shadow) + " from the resource " + ObjectTypeUtil.toShortString(shadow.getResource()) + ", because of configuration error. Returning shadow from the repository");
shadow.setFetchResult(operationResult.createOperationResultType());
return shadow;
}
if (op != FailedOperation.GET) {
// Task task = taskManager.createTaskInstance();
ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
}
if (shadow.getOid() == null) {
throw new ConfigurationException("Configuration error: " + ex.getMessage(), ex);
}
Collection<ItemDelta> modification = createAttemptModification(shadow, null);
try {
ConstraintsChecker.onShadowModifyOperation(modification);
cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
} catch (Exception e) {
//this should not happen. But if it happens, we should return original exception
LOGGER.error("Unexpected error while modifying shadow {}: {}", shadow, e.getMessage(), e);
if (ex instanceof SchemaException) {
throw ((SchemaException) ex);
} else if (ex instanceof GenericFrameworkException) {
throw ((GenericFrameworkException) ex);
} else if (ex instanceof CommunicationException) {
throw ((CommunicationException) ex);
} else if (ex instanceof ObjectNotFoundException) {
throw ((ObjectNotFoundException) ex);
} else if (ex instanceof ObjectAlreadyExistsException) {
throw ((ObjectAlreadyExistsException) ex);
} else if (ex instanceof ConfigurationException) {
throw ((ConfigurationException) ex);
}
}
parentResult.recordFatalError("Configuration error: " + ex.getMessage(), ex);
throw new ConfigurationException("Configuration error: " + ex.getMessage(), ex);
}
Aggregations