---
title: Script on resource operation
description: Connectors continue to be released outside the IDM release. For the latest documentation, refer to the OpenICF documentation.
component: pingidm
version: 7.2
page_id: pingidm:connector-dev-guide:operations/operation-script-on-resource
canonical_url: https://docs.pingidentity.com/pingidm/7.2/connector-dev-guide/operations/operation-script-on-resource.html
section_ids:
  ScriptOnResourceApiOp-api-level-rules: Use the OpenICF script on resource operation
  ScriptOnResourceOp-spi-level-rules: Implement the script on resource operation
---

# Script on resource operation

|   |                                                                                                                                                                                   |
| - | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|   | Connectors continue to be released outside the IDM release. For the latest documentation, refer to the [OpenICF documentation](https://docs.pingidentity.com/openicf/index.html). |

The script on resource operation runs a script directly on the target resource (unlike the [Script on connector operation](operation-script-on-connector.html), which runs a script in the context of a specific connector.)

Implement this interface if your connector intends to support the `ScriptOnResourceApiOp` API operation. If your connector implements this interface, you must document the script languages that the connector supports, as well as any supported `OperationOptions`.

## Use the OpenICF script on resource operation

The contract at the API level is intentionally very loose. Each connector decides what script languages it supports, what running a script on a target resource actually means, and what script options (if any) the connector supports.

Consumption of the ScriptOnResource operation, at the API Level

```java
@Test
public void runScriptOnResourceTest() {
    logger.info("Running RunScriptOnResource Test");
    final ConnectorFacade facade = createConnectorFacade(BasicConnector.class, null);
    final OperationOptionsBuilder builder = new OperationOptionsBuilder();
    builder.setRunAsUser("admin");
    builder.setRunWithPassword(new GuardedString("Passw0rd".toCharArray()));

    final ScriptContextBuilder scriptBuilder = new ScriptContextBuilder("bash", "whoami");

    Object result = facade.runScriptOnResource(scriptBuilder.build(), builder.build());
    Assert.assertEquals(result, "admin");
}
```

## Implement the script on resource operation

The `scriptOnResource` SPI operation takes the following parameters:

* `request` - the script and the arguments to be run

* `options` - additional options that control how the script is run

The operation returns the result of the script. The return type must be a type that the framework supports for serialization. Refer to the [ObjectSerializerFactory](../../_attachments/apidocs/org/identityconnectors/framework/common/serializer/ObjectSerializerFactory.html) javadoc for a list of supported return types.

Implementation of the ScriptOnResource operation, at the SPI Level

```java
public Object runScriptOnResource(ScriptContext request, OperationOptions options) {
    try {
        // Execute the script on remote resource
        if (StringUtil.isNotBlank(options.getRunAsUser())) {
            String password = SecurityUtil.decrypt(options.getRunWithPassword());
            // Use these to execute the script with these credentials
            return options.getRunAsUser();
        }
        throw new UnknownHostException("Failed to connect to remote SSH");
    } catch (Throwable e) {
        logger.warn(e, "Failed to execute Script");
        throw ConnectorException.wrap(e);
    }
}
```
