Building a Connector
Create a connector project from the template, implement the Connector interface for the requests your target needs, and package it as a single JAR the agent can load.
JDK 17, Maven 3.9 or later, and Maven access to the Connector API. See Preparing Your Environment.
Connector API io.cyiam:cyiam-connector-api version 1.4.0.
Starting from the connector template
To create your project:
- Copy the
connector-templatefolder from the agent repository and rename it, for example tocyiam-connector-helpdesk. - In
pom.xml, changegroupId,artifactId,versionandnameto your own. - In
pom.xml, set thecyiam-connector-apidependency to version1.4.0. The template still lists an older version, which lacks the suspend and restore constants. - Rename the package and the
ExampleConnectorclass undersrc/main/java. - Replace the line in
src/main/resources/META-INF/services/io.cyiam.connector.api.Connectorwith your class's fully qualified name, for examplecom.example.helpdesk.HelpdeskConnector. - Make
connectorName()return the name you will use in the provisioning XML'sconnectorattribute, for exampleHelpdesk.
pom.xml essentials
| Item | Setting | Why |
|---|---|---|
| io.cyiam:cyiam-connector-api | provided scope | The agent's class loader already holds it. A second copy inside your JAR gives a different Connector class, and loading fails with a ClassCastException. |
| jackson-databind 2.17.1, slf4j-api 2.0.13 | provided scope | Same reason. The request and result models use Jackson's JsonNode. |
| Your own libraries | Default (compile) scope | HTTP clients, SDKs and drivers must be inside the JAR, because the agent doesn't have them. |
| maven-shade-plugin | Bound to package, shadedArtifactAttached=false | Replaces the normal JAR with one fat JAR. |
| Shade filter | Exclude META-INF/*.SF, *.DSA, *.RSA | Signature files from signed libraries make the fat JAR fail to load with a SecurityException. |
| Java level | 17 | Matches the agent's runtime. |
<dependencies>
<!-- PROVIDED: the agent supplies these; never bundle them -->
<dependency>
<groupId>io.cyiam</groupId>
<artifactId>cyiam-connector-api</artifactId>
<version>1.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
<scope>provided</scope>
</dependency>
<!-- BUNDLED: your connector's own libraries (default scope) -->
</dependencies>
Implementing the Connector interface
The whole contract is one interface with three methods.
public interface Connector {
// Must equal the connectorName field Zetect sends in every request
String connectorName();
// Aggregation (SYNC_USER, SYNC_GROUP, IDENTITY_SYNC) and legacy actions.
// Publish one ConnectorResult (one per chunk when chunking).
void handle(ConnectorCommand command, ConnectorPublisher publisher);
// CREATE_ACCOUNT, UPDATE_ACCOUNT, ADD_TO_GROUP, REMOVE_FROM_GROUP,
// DELETE_ACCOUNT, SUSPEND_ACCOUNT, RESTORE_ACCOUNT, RESET_PASSWORD.
// Publish exactly one ProvisioningResult. Default: actionNotSupported.
default void handleProvisioning(ConnectorCommand command, ProvisioningPublisher publisher) {
publisher.publish(ProvisioningResult.notSupported(command));
}
}
A typical connector switches on cmd.getAction() in each method and sends anything it doesn't support to notSupported. The constants are in io.cyiam.connector.api.operation.Operation.
public class HelpdeskConnector implements Connector {
@Override
public String connectorName() {
return "Helpdesk";
}
@Override
public void handle(ConnectorCommand cmd, ConnectorPublisher publisher) {
switch (cmd.getAction()) {
case Operation.SYNC_USER -> syncAccounts(cmd, publisher);
case Operation.SYNC_GROUP -> syncGroups(cmd, publisher);
default -> publisher.publish(ConnectorResult.notSupported(cmd));
}
}
@Override
public void handleProvisioning(ConnectorCommand cmd, ProvisioningPublisher publisher) {
switch (cmd.getAction()) {
case Operation.CREATE_ACCOUNT -> createAccount(cmd, publisher);
case Operation.ADD_TO_GROUP -> addToGroup(cmd, publisher);
case Operation.REMOVE_FROM_GROUP -> removeFromGroup(cmd, publisher);
case Operation.DELETE_ACCOUNT -> deleteAccount(cmd, publisher);
case Operation.SUSPEND_ACCOUNT -> suspendAccount(cmd, publisher);
case Operation.RESTORE_ACCOUNT -> restoreAccount(cmd, publisher);
default -> publisher.publish(ProvisioningResult.notSupported(cmd));
}
}
private void deleteAccount(ConnectorCommand cmd, ProvisioningPublisher publisher) {
String nativeId = cmd.getSubject() == null ? null
: cmd.getSubject().path("nativeAccountIdentifier").asText(null);
if (nativeId == null || nativeId.isBlank()) {
publisher.publish(ProvisioningResult.failure(cmd, "subject.nativeAccountIdentifier is required"));
return;
}
try {
// call the target system's API to delete nativeId
publisher.publish(ProvisioningResult.success(cmd, nativeId, null));
} catch (Exception e) {
publisher.publish(ProvisioningResult.failure(cmd, e.getMessage()));
}
}
// syncAccounts, syncGroups, createAccount, ... follow the same pattern
}
For the fields each request carries and what each result must contain, see Requests and Responses.
Reading connection settings
cmd.getConnectionInfo() holds the values an administrator entered for the application, grouped by the FieldSet names in your provisioning XML and keyed by each field's Name. Secret values arrive decrypted. Fields the administrator left empty are absent, so read them defensively.
JsonNode settings = cmd.getConnectionInfo().path("Connection Settings");
String baseUrl = settings.path("baseUrl").asText(null);
String apiToken = settings.path("apiToken").asText(null);
if (baseUrl == null || apiToken == null) {
publisher.publish(ProvisioningResult.failure(cmd, "connectionInfo is missing baseUrl or apiToken"));
return;
}
Never log connectionInfo or password, and never copy them into a result.
Handling generic lifecycle actions
Zetect sends the same generic actions to every connector. Decide in your connector how each one maps onto your target.
- SUSPEND_ACCOUNT – make the account unusable without losing it, for example disable or lock it. If the target has no disabled state, you may delete the account instead.
- RESTORE_ACCOUNT – reverse the suspension. If your suspend deleted the account, re-create it from the request's
attributeMappingsandpassword, then re-add the memberships inentitlements. - ADD_TO_GROUP – the account may not exist yet. When
subject.nativeAccountIdentifieris empty, Zetect also sends account attributes and an initialpassword; create the account first, then add the membership. - DELETE_ACCOUNT – if the account is already gone, consider returning success, so a retry or an earlier suspend doesn't leave Zetect showing a failure.
Building the JAR
cd cyiam-connector-helpdesk
mvn clean package -DskipTests
# result: target/cyiam-connector-helpdesk-1.0.0.jar
The shade plugin replaces the normal JAR in target/, so there is one file to deploy. Check that it doesn't contain io/cyiam/connector/api/, com/fasterxml/jackson/ or org/slf4j/, for example with jar tf.
Known pitfalls
| Pitfall | What to do |
|---|---|
| JDBC drivers and DriverManager | DriverManager.getConnection() rejects drivers loaded by the connector's own class loader. Load the driver class with Class.forName(name, true, MyConnector.class.getClassLoader()), create an instance and call driver.connect(url, props) directly. |
| Binary attributes | Reading a binary attribute, such as a directory's GUID or SID, as a string produces invalid text. Read the bytes and format them yourself, or Base64-encode them. |
| Passwords over insecure connections | Some targets refuse password writes unless the connection is encrypted. Check your own "secure connection" setting before setting a password, and return a clear failure instead of a confusing target error. |
| Shared state between requests | The agent calls the connector from several threads at once. Create clients per request, or use thread-safe pooled clients. |
| Bundled provided dependencies | A ClassCastException or LinkageError at load time usually means the API, Jackson or SLF4J ended up in the JAR. Set them back to provided. |
