Search in sources :

Example 1 with ScriptContext

use of org.identityconnectors.framework.common.objects.ScriptContext in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method convertToScriptContext.

private ScriptContext convertToScriptContext(ExecuteProvisioningScriptOperation executeOp) {
    // creating script arguments map form the execute script operation
    // arguments
    Map<String, Object> scriptArguments = new HashMap<String, Object>();
    for (ExecuteScriptArgument argument : executeOp.getArgument()) {
        scriptArguments.put(argument.getArgumentName(), argument.getArgumentValue());
    }
    ScriptContext scriptContext = new ScriptContext(executeOp.getLanguage(), executeOp.getTextCode(), scriptArguments);
    return scriptContext;
}
Also used : ExecuteScriptArgument(com.evolveum.midpoint.provisioning.ucf.api.ExecuteScriptArgument) ScriptContext(org.identityconnectors.framework.common.objects.ScriptContext) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) GuardedString(org.identityconnectors.common.security.GuardedString)

Example 2 with ScriptContext

use of org.identityconnectors.framework.common.objects.ScriptContext 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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) ScriptContext(org.identityconnectors.framework.common.objects.ScriptContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) GuardedString(org.identityconnectors.common.security.GuardedString) OperationOptionsBuilder(org.identityconnectors.framework.common.objects.OperationOptionsBuilder) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConnectorFacade(org.identityconnectors.framework.api.ConnectorFacade) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject)

Aggregations

GuardedString (org.identityconnectors.common.security.GuardedString)2 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)2 ScriptContext (org.identityconnectors.framework.common.objects.ScriptContext)2 ExecuteScriptArgument (com.evolveum.midpoint.provisioning.ucf.api.ExecuteScriptArgument)1 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)1 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 ConnectorFacade (org.identityconnectors.framework.api.ConnectorFacade)1 OperationOptionsBuilder (org.identityconnectors.framework.common.objects.OperationOptionsBuilder)1