Using the ICF API

16-6 Oracle Fusion Middleware Developers Guide for Oracle Identity Manager ■ org.identityconnectors.framework.spi.Connector ■ org.identityconnectors.framework.spi.Configuration

16.3.1.1 org.identityconnectors.framework.spi.Connector

This is the main interface to declare an identity connector. Many connectors create the connection to the target system when the connection is required, removing the connection when finished with it, and disposing of any resources it has used. The interface provides the init and dispose life cycle methods for this purpose. Every connector implementation must be annotated with ConnectorClass. This is required because the ICF would scan all top level .class files in the connector bundle looking for classes that have the ConnectorClass annotation, therefore, autodiscovering connectors that are defined in the bundle. This annotation requires the following elements: ■ configurationClass: This is the configuration class for this connector. This class has all the information about the target that can be used by the connector to connect and perform various provisioning and reconciliation operations. See section org.identityconnectors.framework.spi.Configuration on page 16-8 for more information on how to implement the configuration class. ■ displayNameKey: Display name key that must be present in the message catalog. Example 16–10 is a sample connector implementation. Example 16–10 Flat File Connector Implementation Flat file connector implementation. This connector supports create, delete, search and update operations. ConnectorClass configurationClass=FlatFileConfigurationImpl.class, displayNameKey=FLAT_FILE_CONNECTOR public class FlatFileConnector implements Connector, CreateOp, DeleteOp,SearchOpMapString, String,UpdateOp{ In Example 16–10 : ■ CreateOp: Helps the connector to create an entity on the target system ■ DeleteOp: Helps the connector to delete an entity on the target system ■ SearchOp: Helps the connector to search an entity on the target system ■ UpdateOp: Helps the connector to update an existing entity on the target system See Implementing the Operation Interfaces on page 16-12 for more information. The following sections contain information and sample code that illustrates how you might implement the Connector methods. For complete code regarding a Connector implementation, see Developing a Flat File Connector on page 17-1. Note: Connector implementations must be annotated with type org.identityconnectors.framework.spi.ConnectorClass by providing the configurationClass and displayNameKey information. The displayNameKey must be a key defined in the Messages.properties file. Understanding the Identity Connector Framework 16-7 ■ Implementing the init Method ■ Implementing the dispose Method ■ Implementing the getConfiguration Method

16.3.1.1.1 Implementing the init Method

The init method initializes the connector. The connector initializes itself with the configuration instance as provided with the annotation ConnectorClass. The init method takes a Configuration object as an argument. The Configuration object has all the information required by the Connector to connect to the target system. Example 16–11 illustrates how to implement the init method of interfaces in JDK 1.6. Example 16–11 init Method Implementation Override public void initConfiguration config { this.flatFileConfig = FlatFileConfiguration config; FlatFileIOFactory flatFileIOFactory = FlatFileIOFactory.getInstanceflatFileConfig; this.flatFileMetadata = flatFileIOFactory.getMetadataInstance; this.flatFileParser = flatFileIOFactory.getFileParserInstance; this.flatFileWriter = flatFileIOFactory.getFileWriterInstance; log.okInitialization done; } The init method implementation shown in Example 16–11 does the following: ■ Stores the configuration information of the target system. This can be used later while performing an operation. ■ Initializes all the supporting classes it uses while performing any provisioning and reconciliation operations.

16.3.1.1.2 Implementing the dispose Method

The dispose method disposes of any resources held by this Connector instance. Once the method is called, the Connector instance is discarded and can not be used. Example 16–12 illustrates how to implement the dispose method. Example 16–12 dispose Method Implementation Disposes any resource used by the connector. Override public void dispose { Note: In this document, all code samples use the methods implementing interfaces in JDK 1.6. Note: FlatFileIOFactory, FlatFileMetadata, FlatFileParser and FlatFileWriter are supporting classes and are not part of the ICF. An implementation of these classes is illustrated in Developing a Flat File Connector on page 17-1. 16-8 Oracle Fusion Middleware Developers Guide for Oracle Identity Manager close any open FileReader or FileWriter instances. close connection with the target close connection if any with database }

16.3.1.1.3 Implementing the getConfiguration Method

The getConfiguration method returns the Configuration instance passed to the Connector when the init method was used. Example 16–13 illustrates how to implement the getConfiguration method. Example 16–13 getConfiguration Method Implementation returns the Configuration of this connector Override public Configuration getConfiguration { return this.flatFileConfig; }

16.3.1.2 org.identityconnectors.framework.spi.Configuration

The implementation of this interface encapsulates the configuration of a connector. Configuration implementation includes all the necessary information of the target system, which is used by the Connector implementation to connect to the target system and perform various reconciliation and provisioning operations. The implementation should have a default Constructor with setters and getters defined for its properties. Every property declared may not be required but if a property is required, then it should be marked required using the annotation org.identityconnectors.framework.spi.ConfigurationProperty. Configuration implementation is a Java bean and all the instance variables mandatory or not do have default values. For example, a string userName is used to connect to the target system and this is a mandatory attribute. This has a default value of null. When userName is a mandatory attribute, ICF expects a value to be provided by Oracle Identity Manager. In other words, Oracle Identity Manager cannot miss out this parameter. If missed, then the connector throws ConfigurationException. The implementation should check that all required properties are available and validated before passing itself to the Connector. The interface provides a validate method for this purpose. For example, there are three mandatory configuration parameters, such as the IP address of the target, the username to connect to the target, and the password for the user. The validate method implementation can check for non-NULL values and valid IP address by using regex. Note: Sometimes, components must be able to access the Configuration instance after initialization. This is supported by the accessor method getConfiguration. Note: ICF also provides a convenient base class org.identityconnectors.framework.spi.AbstractConfiguration for configuration objects to extend.