use of com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method fetchChanges.
@Override
public List<Change> fetchChanges(ObjectClassComplexTypeDefinition objectClass, PrismProperty<?> lastToken, AttributesToReturn attrsToReturn, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, ConfigurationException {
OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".fetchChanges");
result.addContext("objectClass", objectClass);
result.addParam("lastToken", lastToken);
// create sync token from the property last token
SyncToken syncToken = null;
try {
syncToken = getSyncToken(lastToken);
LOGGER.trace("Sync token created from the property last token: {}", syncToken == null ? null : syncToken.getValue());
} catch (SchemaException ex) {
result.recordFatalError(ex.getMessage(), ex);
throw new SchemaException(ex.getMessage(), ex);
}
final List<SyncDelta> syncDeltas = new ArrayList<SyncDelta>();
// get icf object class
ObjectClass icfObjectClass;
if (objectClass == null) {
icfObjectClass = ObjectClass.ALL;
} else {
icfObjectClass = connIdNameMapper.objectClassToIcf(objectClass, getSchemaNamespace(), connectorType, legacySchema);
}
OperationOptionsBuilder optionsBuilder = new OperationOptionsBuilder();
if (objectClass != null) {
convertToIcfAttrsToGet(objectClass, attrsToReturn, optionsBuilder);
}
OperationOptions options = optionsBuilder.build();
SyncResultsHandler syncHandler = new SyncResultsHandler() {
@Override
public boolean handle(SyncDelta delta) {
LOGGER.trace("Detected sync delta: {}", delta);
return syncDeltas.add(delta);
}
};
OperationResult connIdResult = result.createSubresult(ConnectorFacade.class.getName() + ".sync");
connIdResult.addContext("connector", connIdConnectorFacade.getClass());
connIdResult.addArbitraryObjectAsParam("connIdObjectClass", icfObjectClass);
connIdResult.addArbitraryObjectAsParam("syncToken", syncToken);
connIdResult.addArbitraryObjectAsParam("syncHandler", syncHandler);
SyncToken lastReceivedToken;
try {
InternalMonitor.recordConnectorOperation("sync");
recordIcfOperationStart(reporter, ProvisioningOperation.ICF_SYNC, objectClass);
lastReceivedToken = connIdConnectorFacade.sync(icfObjectClass, syncToken, syncHandler, options);
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SYNC, objectClass);
connIdResult.recordSuccess();
connIdResult.addReturn(OperationResult.RETURN_COUNT, syncDeltas.size());
} catch (Throwable ex) {
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SYNC, objectClass, ex);
Throwable midpointEx = processIcfException(ex, this, connIdResult);
result.computeStatus();
// exception
if (midpointEx instanceof CommunicationException) {
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof SchemaException) {
throw (SchemaException) 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);
}
}
// convert changes from icf to midpoint Change
List<Change> changeList;
try {
changeList = getChangesFromSyncDeltas(icfObjectClass, syncDeltas, resourceSchema, result);
} catch (SchemaException ex) {
result.recordFatalError(ex.getMessage(), ex);
throw new SchemaException(ex.getMessage(), ex);
}
if (lastReceivedToken != null) {
Change lastChange = new Change((ObjectDelta) null, getToken(lastReceivedToken));
LOGGER.trace("Adding last change: {}", lastChange);
changeList.add(lastChange);
}
result.recordSuccess();
result.addReturn(OperationResult.RETURN_COUNT, changeList == null ? 0 : changeList.size());
return changeList;
}
use of com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method configure.
@Override
public void configure(PrismContainerValue<?> configuration, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, ConfigurationException {
OperationResult result = parentResult.createSubresult(ConnectorInstance.OPERATION_CONFIGURE);
result.addParam("configuration", configuration);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Configuring connector {}, provided configuration:\n{}", connectorType, configuration.debugDump(1));
}
try {
// Get default configuration for the connector. This is important,
// as it contains types of connector configuration properties.
// Make sure that the proper configuration schema is applied. This
// will cause that all the "raw" elements are parsed
boolean immutable = configuration.isImmutable();
try {
if (immutable) {
configuration.setImmutable(false);
}
configuration.applyDefinition(getConfigurationContainerDefinition());
} finally {
if (immutable) {
configuration.setImmutable(true);
}
}
ConnIdConfigurationTransformer configTransformer = new ConnIdConfigurationTransformer(connectorType, cinfo, protector);
// Transform XML configuration from the resource to the ICF connector configuration
try {
apiConfig = configTransformer.transformConnectorConfiguration(configuration);
} catch (SchemaException e) {
result.recordFatalError(e.getMessage(), e);
throw e;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Configuring connector {}, transformed configuration:", connectorType);
for (String propName : apiConfig.getConfigurationProperties().getPropertyNames()) {
LOGGER.trace("P: {} = {}", propName, apiConfig.getConfigurationProperties().getProperty(propName).getValue());
}
}
// Create new connector instance using the transformed configuration
connIdConnectorFacade = ConnectorFacadeFactory.getInstance().newInstance(apiConfig);
result.recordSuccess();
} catch (Throwable ex) {
Throwable midpointEx = processIcfException(ex, this, result);
result.computeStatus("Removing attribute values failed");
// exception
if (midpointEx instanceof CommunicationException) {
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof SchemaException) {
throw (SchemaException) midpointEx;
} else if (midpointEx instanceof ConfigurationException) {
throw (ConfigurationException) 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);
}
}
PrismProperty<Boolean> legacySchemaConfigProperty = configuration.findProperty(new QName(SchemaConstants.NS_ICF_CONFIGURATION, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_LEGACY_SCHEMA_XML_ELEMENT_NAME));
if (legacySchemaConfigProperty != null) {
legacySchema = legacySchemaConfigProperty.getRealValue();
}
LOGGER.trace("Legacy schema (config): {}", legacySchema);
}
use of com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException in project midpoint by Evolveum.
the class ConnIdUtil method lookForKnownCause.
private static Exception lookForKnownCause(Throwable ex, Throwable originalException, OperationResult parentResult) {
if (ex instanceof FileNotFoundException) {
//fix MID-2711 consider FileNotFoundException as CommunicationException
Exception newEx = new com.evolveum.midpoint.util.exception.CommunicationException(createMessageFromAllExceptions(null, ex));
parentResult.recordFatalError("File not found: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof NameAlreadyBoundException) {
// This is thrown by LDAP connector and may be also throw by similar
// connectors
Exception newEx = new ObjectAlreadyExistsException(createMessageFromAllExceptions(null, ex));
parentResult.recordFatalError("Object already exists: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof javax.naming.CommunicationException) {
// This is thrown by LDAP connector and may be also throw by similar
// connectors
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Communication error", ex));
parentResult.recordFatalError("Communication error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof ServiceUnavailableException) {
// In some cases (e.g. JDK 1.6.0_31) this is thrown by LDAP connector and may be also throw by similar
// connectors
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Communication error", ex));
parentResult.recordFatalError("Communication error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof ConnectionBrokenException) {
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Communication error", ex));
parentResult.recordFatalError("Communication error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof ConnectionFailedException) {
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Communication error", ex));
parentResult.recordFatalError("Communication error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof SchemaViolationException) {
// This is thrown by LDAP connector and may be also throw by similar
// connectors
Exception newEx = new SchemaException(createMessageFromAllExceptions("Schema violation", ex));
parentResult.recordFatalError("Schema violation: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException) {
Exception newEx = new SchemaException(createMessageFromAllExceptions("Invalid attribute", ex));
parentResult.recordFatalError("Invalid attribute: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof InvalidAttributeValueException) {
// This is thrown by LDAP connector and may be also throw by similar
// connectors
InvalidAttributeValueException e = (InvalidAttributeValueException) ex;
Exception newEx = null;
if (e.getExplanation().contains("unique attribute conflict")) {
newEx = new ObjectAlreadyExistsException(createMessageFromAllExceptions("Invalid attribute", ex));
} else {
newEx = new SchemaException(createMessageFromAllExceptions("Invalid attribute", ex));
}
parentResult.recordFatalError("Invalid attribute: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof ConnectException) {
// Buried deep in many exceptions, usually connection refused or
// similar errors
// Note: needs to be after javax.naming.CommunicationException as the
// javax.naming exception has more info (e.g. hostname)
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Connect error", ex));
parentResult.recordFatalError("Connect error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof SQLSyntaxErrorException) {
// Buried deep in many exceptions, usually DB schema problems of
// DB-based connectors
Exception newEx = new SchemaException(createMessageFromAllExceptions("DB syntax error", ex));
parentResult.recordFatalError("DB syntax error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof SQLException) {
// Buried deep in many exceptions, usually DB connection problems
Exception newEx = new GenericFrameworkException(createMessageFromAllExceptions("DB error", ex));
parentResult.recordFatalError("DB error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof UnknownUidException) {
// Object not found
Exception newEx = new ObjectNotFoundException(createMessageFromAllExceptions(null, ex));
parentResult.recordFatalError("Object not found: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof NoPermissionException) {
Exception newEx = new SecurityViolationException(createMessageFromAllExceptions(null, ex));
parentResult.recordFatalError("Object not found: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof AttributeInUseException) {
Exception newEx = new SchemaException(createMessageFromAllExceptions(null, ex));
parentResult.recordFatalError("Attribute in use: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof NoSuchAttributeException) {
Exception newEx = new SchemaException(createMessageFromAllExceptions(null, ex));
parentResult.recordFatalError("No such attribute: " + ex.getMessage(), newEx);
return newEx;
}
if (ex.getCause() == null) {
// found nothing
return null;
} else {
// Otherwise go one level deeper ...
return lookForKnownCause(ex.getCause(), originalException, parentResult);
}
}
use of com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException in project midpoint by Evolveum.
the class ConnIdUtil method processIcfException.
/**
* Transform ConnId exception to something more usable.
*
* ICF throws exceptions that contains inner exceptions that cannot be
* reached by current classloader. Such inner exceptions may cause a lot
* of problems in upper layers, such as attempt to serialize/deserialize
* them. Therefore we cannot pass such exceptions to the upper layers.
* As Throwable is immutable and there is no good way how to copy it, we
* just cannot remove the "bad" exceptions from the inner exception stack.
* We need to do the brutal thing: remove all the ICF exceptions and do
* not pass then to upper layers. Try to save at least some information
* and "compress" the class names and messages of the inner ICF exceptions.
* The full exception with a stack trace is logged here, so the details are
* still in the log.
*
* WARNING: This is black magic. Really. Blame Sun Identity Connector
* Framework interface design.
*
* @param connIdException
* exception from the ConnId
* @param connIdResult
* OperationResult to record failure
* @return reasonable midPoint exception
*/
static Throwable processIcfException(Throwable connIdException, String desc, OperationResult connIdResult) {
if (connIdException == null) {
connIdResult.recordFatalError("Null exception while processing ConnId exception ");
throw new IllegalArgumentException("Null exception while processing ConnId exception ");
}
LOGGER.error("ConnId Exception {} in {}: {}", connIdException.getClass().getName(), desc, connIdException.getMessage(), connIdException);
if (connIdException instanceof RemoteWrappedException) {
// brutal hack, for now
RemoteWrappedException remoteWrappedException = (RemoteWrappedException) connIdException;
String className = remoteWrappedException.getExceptionClass();
if (className == null) {
LOGGER.error("Remote ConnId exception without inner exception class name. Continuing with original one: {}", connIdException);
} else if (DOT_NET_ARGUMENT_EXCEPTION.equals(className) && remoteWrappedException.getMessage().contains("0x800708C5")) {
// password too weak
connIdException = new SecurityViolationException(connIdException.getMessage(), connIdException);
} else {
if (className.startsWith(DOT_NET_EXCEPTION_PACKAGE_PLUS_DOT)) {
className = JAVA_EXCEPTION_PACKAGE + "." + className.substring(DOT_NET_EXCEPTION_PACKAGE_PLUS_DOT.length());
LOGGER.trace("Translated exception class: {}", className);
}
try {
connIdException = (Throwable) Class.forName(className).getConstructor(String.class, Throwable.class).newInstance(remoteWrappedException.getMessage(), remoteWrappedException);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) {
LoggingUtils.logException(LOGGER, "Couldn't unwrap remote ConnId exception, continuing with original one {}", e, connIdException);
}
}
}
if (connIdException instanceof NullPointerException && connIdException.getMessage() != null) {
// NPE with a message text is in fact not a NPE but an application exception
// this usually means that some parameter is missing
Exception newEx = new SchemaException(createMessageFromAllExceptions("Required attribute is missing", connIdException));
connIdResult.recordFatalError("Required attribute is missing: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof IllegalArgumentException) {
// Let's assume this must be a configuration problem
Exception newEx = new com.evolveum.midpoint.util.exception.ConfigurationException(createMessageFromInnermostException("Configuration error", connIdException));
connIdResult.recordFatalError("Configuration error: " + connIdException.getMessage(), newEx);
return newEx;
}
//this exception is to be analyzed here before the following if clause
if (connIdException.getCause() != null) {
String exCauseClassName = connIdException.getCause().getClass().getSimpleName();
if (exCauseClassName.equals(CONNECTIONS_EXCEPTION_CLASS_NAME)) {
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Connect error", connIdException));
connIdResult.recordFatalError("Connect error: " + connIdException.getMessage(), newEx);
return newEx;
}
}
if (connIdException.getClass().getPackage().equals(NullPointerException.class.getPackage())) {
// There are java.lang exceptions, they are safe to pass through
connIdResult.recordFatalError(connIdException);
return connIdException;
}
if (connIdException.getClass().getPackage().equals(SchemaException.class.getPackage())) {
// Common midPoint exceptions, pass through
connIdResult.recordFatalError(connIdException);
return connIdException;
}
if (connIdResult == null) {
throw new IllegalArgumentException(createMessageFromAllExceptions("Null parent result while processing ConnId exception", connIdException));
}
// Introspect the inner exceptions and look for known causes
Exception knownCause = lookForKnownCause(connIdException, connIdException, connIdResult);
if (knownCause != null) {
connIdResult.recordFatalError(knownCause);
return knownCause;
}
// Otherwise try few obvious things
if (connIdException instanceof IllegalArgumentException) {
// This is most likely missing attribute or similar schema thing
Exception newEx = new SchemaException(createMessageFromAllExceptions("Schema violation (most likely)", connIdException));
connIdResult.recordFatalError("Schema violation: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof ConfigurationException) {
Exception newEx = new com.evolveum.midpoint.util.exception.ConfigurationException(createMessageFromInnermostException("Configuration error", connIdException));
connIdResult.recordFatalError("Configuration error: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof AlreadyExistsException) {
Exception newEx = new ObjectAlreadyExistsException(createMessageFromAllExceptions(null, connIdException));
connIdResult.recordFatalError("Object already exists: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof PermissionDeniedException) {
Exception newEx = new SecurityViolationException(createMessageFromAllExceptions(null, connIdException));
connIdResult.recordFatalError("Security violation: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof ConnectionBrokenException) {
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Connection broken", connIdException));
connIdResult.recordFatalError("Connection broken: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof ConnectionFailedException) {
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Connection failed", connIdException));
connIdResult.recordFatalError("Connection failed: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof UnknownHostException) {
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Unknown host", connIdException));
connIdResult.recordFatalError("Unknown host: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof ConnectorIOException) {
Exception newEx = new CommunicationException(createMessageFromAllExceptions("IO error", connIdException));
connIdResult.recordFatalError("IO error: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof InvalidCredentialException) {
Exception newEx = new GenericFrameworkException(createMessageFromAllExceptions("Invalid credentials", connIdException));
connIdResult.recordFatalError("Invalid credentials: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof OperationTimeoutException) {
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Operation timed out", connIdException));
connIdResult.recordFatalError("Operation timed out: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof UnknownUidException) {
Exception newEx = new ObjectNotFoundException(createMessageFromAllExceptions(null, connIdException));
connIdResult.recordFatalError("Unknown UID: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof InvalidAttributeValueException) {
Exception newEx = new SchemaException(createMessageFromAllExceptions(null, connIdException));
connIdResult.recordFatalError("Schema violation: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof RetryableException) {
Exception newEx = new CommunicationException(createMessageFromAllExceptions(null, connIdException));
connIdResult.recordFatalError("Retryable errror: " + connIdException.getMessage(), newEx);
return newEx;
} else if (connIdException instanceof ConnectorSecurityException) {
// Note: connection refused is also packed inside
// ConnectorSecurityException. But that will get addressed by the
// lookForKnownCause(..) before
// Maybe we need special exception for security?
Exception newEx = new SecurityViolationException(createMessageFromAllExceptions("Security violation", connIdException));
connIdResult.recordFatalError("Security violation: " + connIdException.getMessage(), newEx);
return newEx;
}
// Fallback
Exception newEx = new GenericFrameworkException(createMessageFromAllExceptions(null, connIdException));
connIdResult.recordFatalError(newEx);
return newEx;
}
use of com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method executeScriptIcf.
private Object executeScriptIcf(StateReporter reporter, ExecuteProvisioningScriptOperation scriptOperation, OperationResult result) throws CommunicationException, GenericFrameworkException {
String icfOpName = null;
if (scriptOperation.isConnectorHost()) {
icfOpName = "runScriptOnConnector";
} else if (scriptOperation.isResourceHost()) {
icfOpName = "runScriptOnResource";
} else {
result.recordFatalError("Where to execute the script?");
throw new IllegalArgumentException("Where to execute the script?");
}
// convert execute script operation to the script context required from
// the connector
ScriptContext scriptContext = convertToScriptContext(scriptOperation);
OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + "." + icfOpName);
icfResult.addContext("connector", connIdConnectorFacade.getClass());
Object output = null;
try {
LOGGER.trace("Running script ({})", icfOpName);
recordIcfOperationStart(reporter, ProvisioningOperation.ICF_SCRIPT, null);
if (scriptOperation.isConnectorHost()) {
InternalMonitor.recordConnectorOperation("runScriptOnConnector");
output = connIdConnectorFacade.runScriptOnConnector(scriptContext, new OperationOptionsBuilder().build());
} else if (scriptOperation.isResourceHost()) {
InternalMonitor.recordConnectorOperation("runScriptOnResource");
output = connIdConnectorFacade.runScriptOnResource(scriptContext, new OperationOptionsBuilder().build());
}
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SCRIPT, null);
icfResult.recordSuccess();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Finished running script ({}), script result: {}", icfOpName, PrettyPrinter.prettyPrint(output));
}
} catch (Throwable ex) {
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SCRIPT, null, ex);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Finished running script ({}), ERROR: {}", icfOpName, ex.getMessage());
}
Throwable midpointEx = processIcfException(ex, this, icfResult);
result.computeStatus();
// exception
if (midpointEx instanceof CommunicationException) {
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof SchemaException) {
// Schema exception during delete? It must be a missing UID
throw new IllegalArgumentException(midpointEx.getMessage(), 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);
}
}
return output;
}
Aggregations