<?xml version="1.0" encoding="UTF-8"?>
<!--
  ! CCPL HEADER START
  !
  ! This work is licensed under the Creative Commons
  ! Attribution-NonCommercial-NoDerivs 3.0 Unported License.
  ! To view a copy of this license, visit
  ! http://creativecommons.org/licenses/by-nc-nd/3.0/
  ! or send a letter to Creative Commons, 444 Castro Street,
  ! Suite 900, Mountain View, California, 94041, USA.
  !
  ! You can also obtain a copy of the license at
  ! legal/CC-BY-NC-ND.txt.
  ! See the License for the specific language governing permissions
  ! and limitations under the License.
  !
  ! If applicable, add the following below this CCPL HEADER, with the fields
  ! enclosed by brackets "[]" replaced with your own identifying information:
  !      Portions Copyright [yyyy] [name of copyright owner]
  !
  ! CCPL HEADER END
  !
  !      Copyright 2011-2012 ForgeRock AS
  !    
-->
<appendix xml:id='appendix-connector-wiz'
 xmlns='http://docbook.org/ns/docbook'
 version='5.0' xml:lang='en'
 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
 xsi:schemaLocation='http://docbook.org/ns/docbook http://docbook.org/xml/5.0/xsd/docbook.xsd'
 xmlns:xlink='http://www.w3.org/1999/xlink'
 xmlns:xinclude='http://www.w3.org/2001/XInclude'>
 <title>Creating Default Provisioner Configurations</title>
 
 <section xml:id="intro">
  <title>Introduction</title>
  
  <para>Since creating a provisioner configuration from scratch is pretty much work, OpenIDM offers a service on the REST interface which should help to get a basic configuration for a <filename>provisioner-openicf-&lt;Connection Name&gt;.json</filename> file. In further releases of OpenIDM this wizard like communication will be available on the command line too.</para>
 
 </section>
 
 <section>
  <title>Creating a new Configuration</title>
  
  <para>The procedure of creating a new provisioner configuration comprises of thee steps:</para>
  
  <orderedlist >
   <listitem><para>Get all available connectors</para></listitem>
   <listitem><para>Generate the core configuration.</para></listitem>
   <listitem><para>Connect to the end system and generate the final configuration.</para></listitem>
  </orderedlist>
  
  <para>The first step is executed by sending a simple REST command to the server:</para>
  
  <screen width="91"><?dbfo pgwide="1"?>$ curl
 --header "X-OpenIDM-Username: openidm-admin"
 --header "X-OpenIDM-Password: openidm-admin"
 --request POST "http://localhost:8080/openidm/system?_action=CREATECONFIGURATION"</screen>
 
  <para>This will return a list of already available connectors. Available connectors are those which are installed in <filename>openidm/connectors</filename>. In OpenIDM 2.0.1 this is currently:</para>
  
  <itemizedlist>
   <listitem><para>csvfile</para></listitem>
   <listitem><para>ldap</para></listitem>
   <listitem><para>scriptedsql</para></listitem>
   <listitem><para>xml</para></listitem>
  </itemizedlist>
 
  <para>The expected return value of the curl command above is therefore:</para> 
  
  <programlisting xml:id="step1-return" language="javascript">
{
   "connectorRef" :
      [
         {
            "connectorName" : "org.identityconnectors.ldap.LdapConnector",
            "bundleName" : "org.forgerock.openicf.connectors.ldap.openicf-ldap-connector",
            "bundleVersion" : "1.1.0.0"
         },
         {
            "connectorName" : "com.forgerock.openicf.xml.XMLConnector",
            "bundleName" : "org.forgerock.openicf.connectors.file.openicf-xml-connector",
            "bundleVersion" : "1.1.0.0"
         },
         {
            "connectorHostRef" : "osgi:service/org.forgerock.openicf.framework.api.osgi.ConnectorManager",
            "connectorName" : "org.forgerock.openicf.scriptedsql.ScriptedSQLConnector",
            "bundleName" : "org.forgerock.openicf.connectors.db.openicf-scriptedsql-connector",
            "bundleVersion" : "1.1.0.0"
         },
         {
            "connectorHostRef" : "osgi:service/org.forgerock.openicf.framework.api.osgi.ConnectorManager",
            "connectorName" : "org.forgerock.openicf.csvfile.CSVFileConnector",
            "bundleName" : "org.forgerock.openicf.connectors.file.openicf-csvfile-connector",
            "bundleVersion" : "1.1.0.0"
         }
      ]
}  
  </programlisting>
  
  <note><para>All return values are pretty unformatted when using curl. Transform them into a better readable format can be acheved by using a json formatter like JSON Formatter &amp; Validator which can be found <link xlink:href="http://jsonformatter.curiousconcept.com/" xlink:show="new" >here</link>.</para></note>
  
  <para>For the next step one of the connectors above must be chosen by copying the result above into the body of the REST command, like shown below for the xml connector</para>
  
  <screen width="91"><?dbfo pgwide="1"?>$ curl
 --header "X-OpenIDM-Username: openidm-admin"
 --header "X-OpenIDM-Password: openidm-admin"
 -d '{"connectorRef":
 {"connectorName":"com.forgerock.openicf.xml.XMLConnector",
 "bundleName":"org.forgerock.openicf.connectors.file.openicf-xml-connector",
 "bundleVersion":"1.1.0.0"}}' 
 --request POST "http://localhost:8080/openidm/system?_action=CREATECONFIGURATION"</screen>
 
  <para>This curl command will return a core connector configuration. It is not functional since it does not contain system specific parameters, the so called "configurationProperties" like hostname or port for web based connectors, or "xmlFilePath" for the file based connectrs as can be seen below. In addition it is missing the complete "objectTypes" and "operationOptions" parts.</para>
  
  <programlisting language="javascript">
{
   "connectorRef" :
      {
         "connectorName" : "com.forgerock.openicf.xml.XMLConnector",
         "bundleName" : "org.forgerock.openicf.connectors.file.openicf-xml-connector",
         "bundleVersion" : "1.1.0.0"
      },
   "poolConfigOption" :
      {
         "maxObjects" : 10,
         "maxIdle" : 10,
         "maxWait" : 150000,
         "minEvictableIdleTimeMillis" : 120000,
         "minIdle" : 1
      },
   "resultsHandlerConfig" :
      {
         "enableNormalizingResultsHandler" : true,
         "enableFilteredResultsHandler" : true,
         "enableCaseInsensitiveFilter" : false,
         "enableAttributesToGetSearchResultsHandler" : true
      },
   "operationTimeout" :
      {
         "CREATE" : -1,
         "UPDATE" : -1,
         "DELETE" : -1,
         "TEST" : -1,
         "SCRIPT_ON_CONNECTOR" : -1,
         "SCRIPT_ON_RESOURCE" : -1,
         "GET" : -1,
         "RESOLVEUSERNAME" : -1,
         "AUTHENTICATE" : -1,
         "SEARCH" : -1,
         "VALIDATE" : -1,
         "SYNC" : -1,
         "SCHEMA" : -1
      },
   "configurationProperties" :
      {
         "xmlFilePath" : null,
         "xsdFilePath" : null,
         "xsdIcfFilePath" : null
      }
}
  </programlisting>
 
  <para>For performing the final step, the missing "configurationProperties" must be filled into the core configuration and the core configuration must be sent sent to the server as the body of a new REST commend:</para>
  
  <screen width="91"><?dbfo pgwide="1"?>$ curl
 --header "X-OpenIDM-Username: openidm-admin"
 --header "X-OpenIDM-Password: openidm-admin"
 -d '{
   "connectorRef" :
      {
         "connectorName" : "com.forgerock.openicf.xml.XMLConnector",
         "bundleName" : "org.forgerock.openicf.connectors.file.openicf-xml-connector",
         "bundleVersion" : "1.1.0.0"
      },
   "poolConfigOption" :
      {
         "maxObjects" : 10,
         "maxIdle" : 10,
         "maxWait" : 150000,
         "minEvictableIdleTimeMillis" : 120000,
         "minIdle" : 1
      },
   "resultsHandlerConfig" :
      {
         "enableNormalizingResultsHandler" : true,
         "enableFilteredResultsHandler" : true,
         "enableCaseInsensitiveFilter" : false,
         "enableAttributesToGetSearchResultsHandler" : true
      },
   "operationTimeout" :
      {
         "CREATE" : -1,
         "UPDATE" : -1,
         "DELETE" : -1,
         "TEST" : -1,
         "SCRIPT_ON_CONNECTOR" : -1,
         "SCRIPT_ON_RESOURCE" : -1,
         "GET" : -1,
         "RESOLVEUSERNAME" : -1,
         "AUTHENTICATE" : -1,
         "SEARCH" : -1,
         "VALIDATE" : -1,
         "SYNC" : -1,
         "SCHEMA" : -1
      },
   "configurationProperties" :
      {
         "xsdIcfFilePath" : "samples/sample1/data/resource-schema-1.xsd",
         "xsdFilePath" : "samples/sample1/data/resource-schema-extension.xsd",
         "xmlFilePath" : "samples/sample1/data/xmlConnectorData.xml"
      }
 }'
 --request POST "http://localhost:8080/openidm/system?_action=CREATECONFIGURATION"</screen>
  
  <note><para>On most UNIX shells the single quote which is used on the -d option above will hide all formatting from being executed. Therefore there is no need to transform the -d '...' part to a single line.</para></note>
  
  <para>For producing the result of the last REST command OpenIDM will try to query the schema from the external system, if such a schema is available. It will then iterate through the objects and attributes in the schema and add the create representations in the "objectTypes" and "operationOptions" for the supported objects and operations.</para>
  
  <programlisting language="javascript">
{
   "connectorRef" :
      {
         "connectorHostRef" : "#LOCAL",
         "connectorName" : "com.forgerock.openicf.xml.XMLConnector",
         "bundleName" : "org.forgerock.openicf.connectors.file.openicf-xml-connector",
         "bundleVersion" : "1.1.0.0-EA"
      },
   "poolConfigOption" :
      {
         "maxObjects" : 10,
         "maxIdle" : 10,
         "maxWait" : 150000,
         "minEvictableIdleTimeMillis" : 120000,
         "minIdle" : 1
      },
   "resultsHandlerConfig" :
      {
         "enableNormalizingResultsHandler" : true,
         "enableFilteredResultsHandler" : true,
         "enableCaseInsensitiveFilter" : false,
         "enableAttributesToGetSearchResultsHandler" : true
      },
   "operationTimeout" :
      {
         "CREATE" : -1,
         "UPDATE" : -1,
         "DELETE" : -1,
         "TEST" : -1,
         "SCRIPT_ON_CONNECTOR" : -1,
         "SCRIPT_ON_RESOURCE" : -1,
         "GET" : -1,
         "RESOLVEUSERNAME" : -1,
         "AUTHENTICATE" : -1,
         "SEARCH" : -1,
         "VALIDATE" : -1,
         "SYNC" : -1,
         "SCHEMA" : -1
      },
   "configurationProperties" :
      {
         "xmlFilePath" : "samples/sample1/data/xmlConnectorData.xml",
         "xsdFilePath" : "samples/sample1/data/resource-schema-extension.xsd",
         "xsdIcfFilePath" : "samples/sample1/data/resource-schema-1.xsd"
      },
   "objectTypes" :
      {
         "OrganizationUnit" :
            {...
            },
         "__GROUP__" :
            {
               "$schema" : "http://json-schema.org/draft-03/schema",
               "id" : "__GROUP__",
               "type" : "object",
               "nativeType" : "__GROUP__",
               "properties" :
                  {
                     "__DESCRIPTION__" :
                        {
                           "type" : "string",
                           "required" : true,
                           "nativeName" : "__DESCRIPTION__",
                           "nativeType" : "string"
                        },
                     "__NAME__" :
                        {
                           "type" : "string",
                           "required" : true,
                           "nativeName" : "__NAME__",
                           "nativeType" : "string"
                        },
                        ...
                  }
            },
         "__ACCOUNT__" :
            {
               "$schema" : "http://json-schema.org/draft-03/schema",
               "id" : "__ACCOUNT__",
               "type" : "object",
               "nativeType" : "__ACCOUNT__",
               "properties" :
                  {
                     "firstname" :
                        {
                           "type" : "string",
                           "nativeName" : "firstname",
                           "nativeType" : "string"
                        },
                     "__DESCRIPTION__" :
                        {
                           "type" : "string",
                           "nativeName" : "__DESCRIPTION__",
                           "nativeType" : "string"
                        },
                     "__UID__" :
                        {
                           "type" : "string",
                           "nativeName" : "__UID__",
                           "nativeType" : "string"
                        },
                     "__NAME__" :
                        {
                           "type" : "string",
                           "required" : true,
                           "nativeName" : "__NAME__",
                           "nativeType" : "string"
                        },
                        ...
                  }
            }
      },
   "operationOptions" :
      {
         "CREATE" :
            {
               "objectFeatures" :
                  {
                     "OrganizationUnit" :
                        {...
                        },
                     "__GROUP__" :
                        {...
                        },
                     "__ACCOUNT__" :
                        {
                           "denied" : false,
                           "onDeny" : "DO_NOTHING",
                           "operationOptionInfo" :
                              {
                                 "$schema" : "http://json-schema.org/draft-03/schema",
                                 "id" : "FIX_ME",
                                 "type" : "object",
                                 "properties" :
                                    {
                                    }
                              }
                        }
                  }
            },
         "UPDATE" :
            {
               "objectFeatures" :
                  {
                     "__ACCOUNT__" :
                        {
                           "denied" : false,
                           "onDeny" : "DO_NOTHING",
                           "operationOptionInfo" :
                              {
                                 "$schema" : "http://json-schema.org/draft-03/schema",
                                 "id" : "FIX_ME",
                                 "type" : "object",
                                 "properties" :
                                    {
                                    }
                              }
                        }
                  }
            },
            ...
      }
}  
  </programlisting>
  
  <note><para>Due to downloading the schema from the resource and producing a full property set for all attributes in all object types of the resource schema, the result can be a rather long configuration file. Several 10000 lines in case of an LDAP server, for instance. Therefore it might be desirable to reduce the schema to the minimum required on the resource before running this command.</para></note>
 </section> 

</appendix>

