<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2010-2017 Evolveum
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->


<!--

This file is an example of Resource definition. It defines an LDAP resource
using an Identity Connector Framework LDAP connector. It contains configuration
for use with stock OpenDJ and OpenDS servers.

This resource definition contains also definition to enable synchronization and
especially an expression that is using a lookup of value from an configuration
object.

-->

<objects xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
         xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
         xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
         xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-3"
         xmlns:my="http://whatever.com/my"
         xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
         xmlns:mr="http://prism.evolveum.com/xml/ns/public/matching-rule-3">


    <resource oid="ef2bc95b-76e0-48e2-86d6-3d4f02d3e1b2">

        <!-- Resource name. It will be displayed in GUI.  -->
        <name>Localhost OpenDJ 2 (no extension schema)</name>

        <description>
            LDAP resource using an Identity Connector Framework LDAP connector. It contains configuration
            for use with stock OpenDJ and OpenDS servers.

            This resource definition contains also definition to enable synchronization and
            especially an expression that is using a lookup of value from an configuration
            object.
        </description>

        <connectorRef type="ConnectorType">
            <description>
                Reference to the ICF LDAP connector. This is dynamic reference, it will be translated to
                OID during import.
            </description>
            <filter>
                <q:text>c:connectorType = "org.identityconnectors.ldap.LdapConnector"</q:text>
            </filter>
        </connectorRef>

        <!-- Configuration section contains configuration of the connector,
             such as hostnames and passwords -->
        <connectorConfiguration>
            <icfc:configurationProperties
                xmlns:icfcldap="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.polygon.connector-ldap/com.evolveum.polygon.connector.ldap.LdapConnector">
                <icfcldap:port>1389</icfcldap:port>
                <icfcldap:host>localhost</icfcldap:host>
                <icfcldap:baseContext>dc=example,dc=com</icfcldap:baseContext>
                <icfcldap:bindDn>uid=idm,ou=Administrators,dc=example,dc=com</icfcldap:bindDn>
                <icfcldap:bindPassword>
                        <t:clearValue>secret</t:clearValue>
                </icfcldap:bindPassword>
                <icfcldap:pagingStrategy>auto</icfcldap:pagingStrategy>
                <icfcldap:vlvSortAttribute>entryUUID</icfcldap:vlvSortAttribute>
<!--                                <icfcldap:accountOperationalAttributes>ds-pwp-account-disabled</icfcldap:accountOperationalAttributes>-->
                <icfcldap:operationalAttributes>ds-pwp-account-disabled</icfcldap:operationalAttributes>
                 <icfcldap:operationalAttributes>isMemberOf</icfcldap:operationalAttributes>
            </icfc:configurationProperties>
            <icfc:connectorPoolConfiguration>
                <icfc:minEvictableIdleTimeMillis>120000</icfc:minEvictableIdleTimeMillis>
                <icfc:minIdle>1</icfc:minIdle>
                <icfc:maxIdle>10</icfc:maxIdle>
                <icfc:maxObjects>10</icfc:maxObjects>
                <icfc:maxWait>150000</icfc:maxWait>
            </icfc:connectorPoolConfiguration>
            <icfc:producerBufferSize>100</icfc:producerBufferSize>
            <icfc:timeouts>
                <icfc:create>-1</icfc:create>
                <icfc:get>-1</icfc:get>
                <icfc:update>-1</icfc:update>
                <icfc:delete>-1</icfc:delete>
                <icfc:test>-1</icfc:test>
                <icfc:scriptOnConnector>-1</icfc:scriptOnConnector>
                <icfc:scriptOnResource>-1</icfc:scriptOnResource>
                <icfc:authentication>-1</icfc:authentication>
                <icfc:search>-1</icfc:search>
                <icfc:validate>-1</icfc:validate>
                <icfc:sync>-1</icfc:sync>
                <icfc:schema>-1</icfc:schema>
            </icfc:timeouts>
            <icfc:resultsHandlerConfiguration>
                <icfc:enableNormalizingResultsHandler>false</icfc:enableNormalizingResultsHandler>
                <icfc:enableFilteredResultsHandler>false</icfc:enableFilteredResultsHandler>
                <icfc:enableAttributesToGetSearchResultsHandler>false</icfc:enableAttributesToGetSearchResultsHandler>
            </icfc:resultsHandlerConfiguration>
        </connectorConfiguration>

        <schema>
            <!-- workaround to MID-2723 -->
            <generationConstraints>
                <generateObjectClass>ri:inetOrgPerson</generateObjectClass>
                <generateObjectClass>ri:groupOfUniqueNames</generateObjectClass>
                <generateObjectClass>ri:groupOfNames</generateObjectClass>
                <generateObjectClass>ri:organizationalUnit</generateObjectClass>
            </generationConstraints>
        </schema>

        <!-- Resource Schema Handling definition.
             This part defines how the schema defined above will be used by
             midPoint. It defines expressions and limitations for individual
             schema attributes.

             The expressions that describe both inbound and outbound flow of
             the attributes are defined in this section.

             This is the part where most of the customization takes place.
        -->

    <schemaHandling>
        <objectType>
            <displayName>Default Account</displayName>
            <default>true</default>
            <objectClass>ri:inetOrgPerson</objectClass>
            <attribute>
                <ref>ri:dn</ref>
                <displayName>Distinguished Name</displayName>
                <description>The DN will be constructed as follows: uid=flastname,ou=people,dc=example,dc=ck</description>
                <limitations>
                    <minOccurs>0</minOccurs>
                    <access>
                        <read>true</read>
                        <add>true</add>
                        <modify>true</modify>
                    </access>
                </limitations>
                <matchingRule>mr:stringIgnoreCase</matchingRule>
                    <outbound>
                        <source>
                            <name>tmpGivenName</name>
                            <path>$user/givenName</path>
                        </source>
                        <source>
                            <name>tmpFamilyName</name>
                            <path>$user/familyName</path>
                        </source>
                        <expression>
                        <script>
                        <code>
tmpGivenNameInitial = basic.stringify(tmpGivenName)?.size() &gt; 0 ? (basic.stringify(tmpGivenName)).substring(0,1) : ''

if (iteration == 0) {
        'uid=' + basic.norm(basic.stringify(tmpGivenNameInitial + tmpFamilyName)) + ',ou=people,dc=example,dc=com'
}
else {
        'uid=' + basic.norm(basic.stringify(tmpGivenNameInitial + tmpFamilyName)) + iterationToken + ',ou=people,dc=example,dc=com'
}
                        </code>
                        </script>
                        </expression>
                    </outbound>
            </attribute>
            <attribute>
                <ref>ri:entryUUID</ref>
                <displayName>Entry UUID</displayName>
                <limitations>
                    <access>
                        <read>true</read>
                        <add>false</add>
                        <modify>false</modify>
                    </access>
                </limitations>
                <matchingRule>mr:stringIgnoreCase</matchingRule>
            </attribute>
            <attribute>
                <ref>ri:cn</ref>
                <displayName>Common Name</displayName>
                <limitations>
                    <minOccurs>0</minOccurs>
                    <access>
                        <read>true</read>
                        <add>true</add>
                        <modify>true</modify>
                    </access>
                </limitations>

                <outbound>
                    <source>
                        <path>$user/fullName</path>
                    </source>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:sn</ref>
                <displayName>Surname</displayName>
                <limitations>
                    <minOccurs>0</minOccurs>
                </limitations>
                <outbound>
                    <source>
                        <!-- The path can be shorteden like this. $user is a default source "context" in outbound -->
                        <path>familyName</path>
                    </source>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:givenName</ref>
                <displayName>Given Name</displayName>
                <outbound>
                    <source>
                        <!-- Full namespace prefixes can be used in the path -->
                        <path>$c:user/c:givenName</path>
                    </source>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:uid</ref>
                <displayName>Login Name</displayName>
                <matchingRule>mr:stringIgnoreCase</matchingRule>
                    <outbound>
                    <strength>weak</strength>
                        <source>
                            <name>tmpGivenName</name>
                            <path>$user/givenName</path>
                        </source>
                        <source>
                            <name>tmpFamilyName</name>
                            <path>$user/familyName</path>
                        </source>
                        <expression>
                        <script>
                        <code>
tmpGivenNameInitial = basic.stringify(tmpGivenName)?.size() &gt; 0 ? (basic.stringify(tmpGivenName)).substring(0,1) : ''

if (iteration == 0) {
    basic.norm(basic.stringify(tmpGivenNameInitial + tmpFamilyName))
}
else {
        basic.norm(basic.stringify(tmpGivenNameInitial + tmpFamilyName)) + iterationToken
    }
                        </code>
                        </script>
                        </expression>
                    </outbound>
            </attribute>
            <attribute>
                <ref>ri:description</ref>
                <outbound>
                    <strength>weak</strength>
                    <expression>
                        <description>Expression that assigns a fixed value</description>
                        <value>Created by IDM</value>
                    </expression>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:l</ref>
                <outbound>
                    <expression>
                        <variable xmlns:my="http://whatever.com/my">
                            <name>my:defaultLocation</name>
                            <value xsiType="xsd:string">middle of nowhere</value>
                        </variable>
                        <script>
                            <description>XPath expression that is using a variable declared above</description>
                            <language>http://www.w3.org/TR/xpath/</language>
                            <returnType>scalar</returnType>
                            <code xmlns:my="http://whatever.com/my">
                                    $my:defaultLocation
                            </code>
                        </script>
                    </expression>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:employeeType</ref>
                <displayName>Employee Type</displayName>
                <tolerant>false</tolerant>
                <outbound>
                    <source>
                        <path>$user/subtype</path>
                    </source>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:departmentNumber</ref>
                <displayName>Department Number</displayName>
                <tolerant>true</tolerant>
                <outbound>
                    <source>
                        <path>$user/organizationalUnit</path>
                    </source>
                </outbound>
            </attribute>

            <iteration>
                <maxIterations>5</maxIterations>
            </iteration>

            <protected>
                <filter>
                    <q:text>attributes/ri:dn =[distinguishedName] "uid=idm,ou=Administrators,dc=example,dc=com"</q:text>
                </filter>
            </protected>


            <activation>
                <administrativeStatus>
                    <outbound/>
                </administrativeStatus>
            </activation>

            <credentials>
                <password>
                    <outbound>
                        <expression>
                            <asIs/>
                        </expression>
                    </outbound>
                </password>
            </credentials>

        </objectType>
    </schemaHandling>


    <capabilities xmlns:cap="http://midpoint.evolveum.com/xml/ns/public/resource/capabilities-3">
        <configured>
            <cap:activation>
                <cap:status>
                    <cap:attribute>ri:ds-pwp-account-disabled</cap:attribute>
                    <cap:enableValue/>
                    <cap:disableValue>true</cap:disableValue>
                </cap:status>
            </cap:activation>
        </configured>
    </capabilities>

    </resource>
</objects>
