Groovy Connector Toolkit
Important
Connectors continue to be released outside the IDM release. For the latest documentation, refer to the ICF documentation.
ICF provides a generic Groovy Connector Toolkit that enables you to run a Groovy script for any ICF operation, such as search, update, create, and others, on any external resource.
The Groovy Connector Toolkit is not a complete connector in the traditional sense. Rather, it is a framework within which you must write your own Groovy scripts to address the requirements of your implementation.
Configuring Scripted Groovy Connectors
The Groovy Connector Toolkit is bundled in the JAR openidm/connectors/groovy-connector-1.5.20.8.jar
.
The Samples Guide describes a number of scripted connector implementations. The scripts provided with these samples demonstrate how the Groovy Connector Toolkit can be used. These scripts cannot be used as is in your deployment, but are a good starting point on which to base your customization. For information about writing your own scripts, see Writing Scripted Connectors With the Groovy Connector Toolkit.
You specify the connector configuration in your project's conf/provisioner.openicf-connector.json
file. A number of sample configurations for scripted Groovy implementations are provided in openidm/samples/example-configurations/provisioners/provisioner.openicf-scriptedimpementation.json
. Use these as the basis for configuring your own scripted connector.
The scripted SQL connector uses the Tomcat JDBC Connection Pool to manage its connections. Occasionally, a JDBC resource accessed by the scripted SQL connector might become unavailable for a period. When the resource comes back online, IDM is able to recover automatically and resume operations. However, the connector might not be able to refresh its connection pool and might then pass a closed connection to its scripts. This can affect operations until IDM is restarted.
To avoid this situation, you can configure connection validation, where connections are validated before being borrowed from the connection pool.
To configure connection validation, add the following properties to the configurationProperties
object in your connector configuration:
testOnBorrow
Validates the connection object before it is borrowed from the pool. If the object fails to validate, it is dropped from the pool and the connector attempts to borrow another object.
For this property to have an effect, you must set
validationQuery
to a non-null string.validationQuery
The SQL query used to validate connections from the pool before returning them to the caller.
The precise query will differ, depending on the database that you are accessing. The following list provides sample queries for common databases:
- HyperSQL DataBase (HSQLDB)
select 1 from INFORMATION_SCHEMA.SYSTEM_USERS
- Oracle DB
select 1 from dual
- DB2
select 1 from sysibm.sysdummy1
- MySQL
select 1
- Microsoft SQL
select 1
- PostgreSQL
select 1
- Ingres Database
select 1
- Apache Derby
values 1
- H2 Database
select 1
- Firebird SQL
select 1 from rdb$database
validationInterval
Specifies the maximum frequency (in milliseconds) at which validation is run. If a connection is due for validation but was previously validated within this interval, it is not validated again.
The larger the value, the better the connector performance. However, with a large value you increase the chance of a stale connection being presented to the connector.
Connection validation can have an impact on performance and should not be done too frequently. With the following configuration, connections are validated no more than every 34 seconds:
{ ... "configurationProperties" : { ... "testOnBorrow" : true, "validationQuery" : "select 1 from dual", "validationInterval" : 34000, ... }, ... }
The customConfiguration
and customSensitiveConfiguration
properties enable you to inject custom properties into your scripts. Properties listed in customSensitiveConfiguration
are encrypted.
For example, the following excerpt of the scripted Kerberos provisioner file shows how these properties inject the Kerberos user and encrypted password into the scripts, using the kadmin
command.
"customConfiguration" : "kadmin { cmd = '/usr/sbin/kadmin.local'; user='<KADMIN USERNAME>'; default_realm='<REALM>' }", "customSensitiveConfiguration" : "kadmin { password = '<KADMIN PASSWORD>'}",
When you call a Groovy script from the Groovy connector, you can use the SLF4J logging facility to obtain debug information.
For instructions on how to use this facility, see the KnowledgeBase article How do I add logging to Groovy scripts in IDM.
The first time a script is read, it is compiled (from Groovy script to Java bytecode) and cached in memory. Each time the script is called, the Groovy script engine checks the last modified timestamp of the script file to see if it has changed. If it has not changed, the cached bytecode is executed. If it has changed, the script is reloaded, compiled and cached.
Run scripts through the connector
Groovy Toolkit connectors have two operations that allow you to run arbitrary script actions: runScriptOnConnector
and runScriptOnResource
. runScriptOnConnector
is an operation that sends the script action to the connector to be compiled and executed. runScriptOnResource
is an operation that sends the script to another script to be handled.
runScriptOnConnector
The runScriptOnConnector
script lets you run an arbitrary script action through the connector. This script takes the following variables as input:
configuration
A handler to the connector's configuration object.
options
A handler to the Operation Options.
operation
The operation type that corresponds to the action.
log
A handler to the connector's log.
To run an arbitrary script on a Groovy Toolkit connector, define the script in the systemActions
property of your provisioner file:
"systemActions" : [ { "scriptId" : "MyScript", "actions" : [ { "systemType" : ".*ScriptedConnector", "actionType" : "groovy", "actionFile" : "path/to/scriptname.groovy" } ] } ]
If you wish to define your script in the provisioner file itself rather than in a separate file, you can use the actionSource
property instead of the actionFile
one. A simple example follows:
"systemActions" : [ { "scriptId" : "MyScript", "actions" : [ { "systemType" : ".*ScriptedConnector", "actionType" : "groovy", "actionSource" : "2 * 2" } ] } ]
Note
It is optional to prepend the last script statement in actionSource
with return
.
Running MyScript
will return:
{ "actions" : [ { "result": 4 } ] }
If your script accepts parameters, you can supply them in the request body or the query string. For example:
curl \
--header "X-OpenIDM-Username: openidm-admin" \
--header "X-OpenIDM-Password: openidm-admin" \
--header "Content-Type: application/json" \
--header "Accept-API-Version: resource=1.0" \
--request POST \
--data-raw '{"param1":"value1"}' \
"http://localhost:8080/openidm/system/groovy?_action=script&scriptId=MyScript¶m2=value2"
You can also call it through the script engine. The system can accept arbitrary parameters:
openidm.action("/system/groovy", "script", {"contentParameter": "value"}, {"scriptId": "MyScript", "additionalParameter1": "value1", "additionalParameter2": "value2"})
runScriptOnResource
To run an arbitrary script using runScriptOnResource
, you must add some configuration details to your provisioner file. These details include a scriptOnResourceScriptFileName
that references a script file located in a path contained in the scriptRoots
array.
Define these properties in your provisioner file:
"configurationProperties": { "scriptRoots": [ "path/to/scripts" ], "scriptOnResourceScriptFileName": "ScriptOnResourceScript.groovy" }, "systemActions" : [ { "scriptId" : "script-1", "actions" : [ { "systemType" : ".*ScriptedConnector", "actionType" : "groovy", "actionFile" : "path/to/scriptname.groovy" } ] } ]
When you have defined the script, call it over REST on the system endpoint:
curl \
--header "X-OpenIDM-Username: openidm-admin" \
--header "X-OpenIDM-Password: openidm-admin" \
--header "Content-Type: application/json" \
--header "Accept-API-Version: resource=1.0" \
--request POST \
"http://localhost:8080/openidm/system/groovy?_action=script&scriptId=scriptOnResourceScript&scriptExecuteMode=resource"
Implemented Interfaces
The following tables list the ICF interfaces that are implemented for non-poolable and poolable connector implementations:
OpenICF Interfaces Implemented by the Scripted Groovy Connector
The Scripted Groovy Connector implements the following OpenICF interfaces.
- Authenticate
Provides simple authentication with two parameters, presumed to be a user name and password.
- Create
Creates an object and its
uid
.- Delete
Deletes an object, referenced by its
uid
.- Resolve Username
Resolves an object by its username and returns the
uid
of the object.- Schema
Describes the object types, operations, and options that the connector supports.
- Script on Connector
Enables an application to run a script in the context of the connector. Any script that runs on the connector has the following characteristics:
The script runs in the same execution environment as the connector and has access to all the classes to which the connector has access.
The script has access to a
connector
variable that is equivalent to an initialized instance of the connector. At a minimum, the script can access the connector configuration.The script has access to any script-arguments passed in by the application.
- Script on Resource
Runs a script on the target resource that is managed by this connector.
- Search
Searches the target resource for all objects that match the specified object class and filter.
- Sync
Polls the target resource for synchronization events, that is, native changes to objects on the target resource.
- Test
Tests the connector configuration. Testing a configuration checks all elements of the environment that are referred to by the configuration are available. For example, the connector might make a physical connection to a host that is specified in the configuration to verify that it exists and that the credentials that are specified in the configuration are valid.
This operation might need to connect to a resource, and, as such, might take some time. Do not invoke this operation too often, such as before every provisioning operation. The test operation is not intended to check that the connector is alive (that is, that its physical connection to the resource has not timed out).
You can invoke the test operation before a connector configuration has been validated.
- Update
Updates (modifies or replaces) objects on a target resource.
OpenICF Interfaces Implemented by the Scripted Poolable Groovy Connector
The Scripted Poolable Groovy Connector implements the following OpenICF interfaces.
- Authenticate
Provides simple authentication with two parameters, presumed to be a user name and password.
- Create
Creates an object and its
uid
.- Delete
Deletes an object, referenced by its
uid
.- Resolve Username
Resolves an object by its username and returns the
uid
of the object.- Schema
Describes the object types, operations, and options that the connector supports.
- Script on Connector
Enables an application to run a script in the context of the connector. Any script that runs on the connector has the following characteristics:
The script runs in the same execution environment as the connector and has access to all the classes to which the connector has access.
The script has access to a
connector
variable that is equivalent to an initialized instance of the connector. At a minimum, the script can access the connector configuration.The script has access to any script-arguments passed in by the application.
- Script on Resource
Runs a script on the target resource that is managed by this connector.
- Search
Searches the target resource for all objects that match the specified object class and filter.
- Sync
Polls the target resource for synchronization events, that is, native changes to objects on the target resource.
- Test
Tests the connector configuration. Testing a configuration checks all elements of the environment that are referred to by the configuration are available. For example, the connector might make a physical connection to a host that is specified in the configuration to verify that it exists and that the credentials that are specified in the configuration are valid.
This operation might need to connect to a resource, and, as such, might take some time. Do not invoke this operation too often, such as before every provisioning operation. The test operation is not intended to check that the connector is alive (that is, that its physical connection to the resource has not timed out).
You can invoke the test operation before a connector configuration has been validated.
- Update
Updates (modifies or replaces) objects on a target resource.
Configuration Properties
The following tables list the configuration properties for non-poolable and poolable connector implementations:
Scripted Groovy Connector Configuration
The Scripted Groovy Connector has the following configurable properties.
Configuration properties
Property | Type | Default | Encrypted [a] | Required [b] |
---|---|---|---|---|
customSensitiveConfiguration | GuardedString | null | ||
Custom Sensitive Configuration script for Groovy ConfigSlurper | ||||
| ||||
customConfiguration | String | null | ||
Custom Configuration script for Groovy ConfigSlurper | ||||
| ||||
[a] Indicates whether the property value is considered confidential, and therefore encrypted in OpenIDM. [b] A list of operations in this column indicates that the property is required for those operations. |
Operation Script Files
Property | Type | Default | Encrypted [a] | Required [b] | ||
---|---|---|---|---|---|---|
createScriptFileName | String | null |
| |||
The name of the file used to perform the CREATE operation. | ||||||
| ||||||
customizerScriptFileName | String | null | ||||
The script used to customize some function of the connector. Read the documentation for more details. | ||||||
| ||||||
authenticateScriptFileName | String | null |
| |||
The name of the file used to perform the AUTHENTICATE operation. | ||||||
| ||||||
scriptOnResourceScriptFileName | String | null |
| |||
The name of the file used to perform the RUNSCRIPTONRESOURCE operation. | ||||||
| ||||||
deleteScriptFileName | String | null |
| |||
The name of the file used to perform the DELETE operation. | ||||||
| ||||||
resolveUsernameScriptFileName | String | null |
| |||
The name of the file used to perform the RESOLVE_USERNAME operation. | ||||||
| ||||||
searchScriptFileName | String | null |
| |||
The name of the file used to perform the SEARCH operation. | ||||||
| ||||||
updateScriptFileName | String | null |
| |||
The name of the file used to perform the UPDATE operation. | ||||||
| ||||||
schemaScriptFileName | String | null |
| |||
The name of the file used to perform the SCHEMA operation. | ||||||
| ||||||
testScriptFileName | String | null |
| |||
The name of the file used to perform the TEST operation. | ||||||
| ||||||
syncScriptFileName | String | null |
| |||
The name of the file used to perform the SYNC operation. | ||||||
| ||||||
[a] Indicates whether the property value is considered confidential, and therefore encrypted in OpenIDM. [b] A list of operations in this column indicates that the property is required for those operations. |
Groovy Engine configuration
Property | Type | Default | Encrypted [a] | Required [b] |
---|---|---|---|---|
targetDirectory | File | null | ||
Directory into which to write classes. | ||||
| ||||
warningLevel | int | 1 | ||
Warning Level of the compiler | ||||
| ||||
scriptExtensions | String[] | ['groovy'] | ||
Gets the extensions used to find groovy files | ||||
| ||||
minimumRecompilationInterval | int | 100 | ||
Sets the minimum of time after a script can be recompiled. | ||||
| ||||
scriptBaseClass | String | null | ||
Base class name for scripts (must derive from Script) | ||||
| ||||
scriptRoots | String[] | null | ||
The root folder to load the scripts from. If the value is null or empty the classpath value is used. | ||||
| ||||
tolerance | int | 10 | ||
The error tolerance, which is the number of non-fatal errors (per unit) that should be tolerated before compilation is aborted. | ||||
| ||||
debug | boolean | false | ||
If true, debugging code should be activated | ||||
| ||||
classpath | String[] | [] | ||
Classpath for use during compilation. | ||||
| ||||
disabledGlobalASTTransformations | String[] | null | ||
Sets a list of global AST transformations which should not be loaded even if they are defined in META-INF/org.codehaus.groovy.transform.ASTTransformation files. By default, none is disabled. | ||||
| ||||
verbose | boolean | false | ||
If true, the compiler should produce action information | ||||
| ||||
sourceEncoding | String | UTF-8 | ||
Encoding for source files | ||||
| ||||
recompileGroovySource | boolean | false | ||
If set to true recompilation is enabled | ||||
| ||||
[a] Indicates whether the property value is considered confidential, and therefore encrypted in OpenIDM. [b] A list of operations in this column indicates that the property is required for those operations. |
Scripted Poolable Groovy Connector Configuration
The Scripted Poolable Groovy Connector has the following configurable properties.
Configuration properties
Property | Type | Default | Encrypted [a] | Required [b] |
---|---|---|---|---|
customSensitiveConfiguration | GuardedString | null | ||
Custom Sensitive Configuration script for Groovy ConfigSlurper | ||||
| ||||
customConfiguration | String | null | ||
Custom Configuration script for Groovy ConfigSlurper | ||||
| ||||
[a] Indicates whether the property value is considered confidential, and therefore encrypted in OpenIDM. [b] A list of operations in this column indicates that the property is required for those operations. |
Operation Script Files
Property | Type | Default | Encrypted [a] | Required [b] | ||
---|---|---|---|---|---|---|
createScriptFileName | String | null |
| |||
The name of the file used to perform the CREATE operation. | ||||||
| ||||||
customizerScriptFileName | String | null | ||||
The script used to customize some function of the connector. Read the documentation for more details. | ||||||
| ||||||
authenticateScriptFileName | String | null |
| |||
The name of the file used to perform the AUTHENTICATE operation. | ||||||
| ||||||
scriptOnResourceScriptFileName | String | null |
| |||
The name of the file used to perform the RUNSCRIPTONRESOURCE operation. | ||||||
| ||||||
deleteScriptFileName | String | null |
| |||
The name of the file used to perform the DELETE operation. | ||||||
| ||||||
resolveUsernameScriptFileName | String | null |
| |||
The name of the file used to perform the RESOLVE_USERNAME operation. | ||||||
| ||||||
searchScriptFileName | String | null |
| |||
The name of the file used to perform the SEARCH operation. | ||||||
| ||||||
updateScriptFileName | String | null |
| |||
The name of the file used to perform the UPDATE operation. | ||||||
| ||||||
schemaScriptFileName | String | null |
| |||
The name of the file used to perform the SCHEMA operation. | ||||||
| ||||||
testScriptFileName | String | null |
| |||
The name of the file used to perform the TEST operation. | ||||||
| ||||||
syncScriptFileName | String | null |
| |||
The name of the file used to perform the SYNC operation. | ||||||
| ||||||
[a] Indicates whether the property value is considered confidential, and therefore encrypted in OpenIDM. [b] A list of operations in this column indicates that the property is required for those operations. |
Groovy Engine configuration
Property | Type | Default | Encrypted [a] | Required [b] |
---|---|---|---|---|
targetDirectory | File | null | ||
Directory into which to write classes. | ||||
| ||||
warningLevel | int | 1 | ||
Warning Level of the compiler | ||||
| ||||
scriptExtensions | String[] | ['groovy'] | ||
Gets the extensions used to find groovy files | ||||
| ||||
minimumRecompilationInterval | int | 100 | ||
Sets the minimum of time after a script can be recompiled. | ||||
| ||||
scriptBaseClass | String | null | ||
Base class name for scripts (must derive from Script) | ||||
| ||||
scriptRoots | String[] | null | ||
The root folder to load the scripts from. If the value is null or empty the classpath value is used. | ||||
| ||||
tolerance | int | 10 | ||
The error tolerance, which is the number of non-fatal errors (per unit) that should be tolerated before compilation is aborted. | ||||
| ||||
debug | boolean | false | ||
If true, debugging code should be activated | ||||
| ||||
classpath | String[] | [] | ||
Classpath for use during compilation. | ||||
| ||||
disabledGlobalASTTransformations | String[] | null | ||
Sets a list of global AST transformations which should not be loaded even if they are defined in META-INF/org.codehaus.groovy.transform.ASTTransformation files. By default, none is disabled. | ||||
| ||||
verbose | boolean | false | ||
If true, the compiler should produce action information | ||||
| ||||
sourceEncoding | String | UTF-8 | ||
Encoding for source files | ||||
| ||||
recompileGroovySource | boolean | false | ||
If set to true recompilation is enabled | ||||
| ||||
[a] Indicates whether the property value is considered confidential, and therefore encrypted in OpenIDM. [b] A list of operations in this column indicates that the property is required for those operations. |