<resource xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
          xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
          xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
          xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
          xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
          xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
          xmlns:mr="http://prism.evolveum.com/xml/ns/public/matching-rule-3"
          oid="e307a460-2310-4f18-9644-6534d62fa999"
          version="0">
    <name>SAP</name>

    <connectorRef type="ConnectorType">
        <filter>
            <q:text>c:connectorType = "com.evolveum.polygon.connector.sap.SapConnector"</q:text>
        </filter>
    </connectorRef>
    <connectorConfiguration xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-3">
        <icfc:configurationProperties xmlns:sap="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.polygon.connector-sap/com.evolveum.polygon.connector.sap.SapConnector">
            <sap:host>host.to.sap</sap:host>
            <sap:systemNumber>34</sap:systemNumber>
            <sap:systemId>SRS</sap:systemId>
            <sap:client>200</sap:client>
            <sap:user>USER</sap:user>
            <sap:password>
                <t:clearValue>secret</t:clearValue>
            </sap:password>
            <sap:testBapiFunctionPermission>false</sap:testBapiFunctionPermission>
        </icfc:configurationProperties>
        <icfc:resultsHandlerConfiguration>
            <icfc:enableNormalizingResultsHandler>false</icfc:enableNormalizingResultsHandler>
            <icfc:enableFilteredResultsHandler>false</icfc:enableFilteredResultsHandler>
            <icfc:enableAttributesToGetSearchResultsHandler>false</icfc:enableAttributesToGetSearchResultsHandler>
        </icfc:resultsHandlerConfiguration>
        <icfc:legacySchema>true</icfc:legacySchema>
    </connectorConfiguration>

    <schemaHandling>
        <objectType>
            <kind>account</kind>
            <intent>default</intent>
            <displayName>Default Account</displayName>
            <default>true</default>
            <objectClass>ri:AccountObjectClass</objectClass>
            <attribute>
                <c:ref>icfs:name</c:ref>
                <displayName>USERNAME</displayName>
                <limitations>
                    <minOccurs>0</minOccurs>
                </limitations>
                <outbound>
                    <source>
                        <c:path>$user/name</c:path>
                    </source>
                    <expression>
                        <script>
                            <code>
                                return basic.uc(basic.stringify(name));
                            </code>
                        </script>
                    </expression>
                </outbound>
                <inbound>
                    <strength>weak</strength>
                    <target>
                        <c:path>$user/name</c:path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <c:ref>icfs:uid</c:ref>
                <displayName>USERNAME</displayName>
                <limitations>
                    <access>
                        <read>true</read>
                        <add>false</add>
                        <modify>false</modify>
                    </access>
                </limitations>
                <matchingRule>mr:stringIgnoreCase</matchingRule>
            </attribute>
            <attribute>
                <c:ref>ri:ADDRESS.TITLE_P</c:ref>
                <outbound>
                    <source>
                        <c:path>$user/title</c:path>
                    </source>
                </outbound>
                <inbound>
                    <target>
                        <c:path>$user/title</c:path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <c:ref>ri:ADDRESS.FIRSTNAME</c:ref>
                <outbound>
                    <source>
                        <c:path>$user/givenName</c:path>
                    </source>
                </outbound>
                <inbound>
                    <target>
                        <c:path>$user/givenName</c:path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <c:ref>ri:ADDRESS.LASTNAME</c:ref>
                <outbound>
                    <source>
                        <c:path>$user/familyName</c:path>
                    </source>
                </outbound>
                <inbound>
                    <target>
                        <c:path>$user/familyName</c:path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <c:ref>ri:ADDRESS.TITLE_ACA1</c:ref>
                <outbound>
                    <source>
                        <c:path>$user/honorificPrefix</c:path>
                    </source>
                </outbound>
                <inbound>
                    <target>
                        <c:path>$user/honorificPrefix</c:path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <c:ref>ri:ADDRESS.E_MAIL</c:ref>
                <outbound>
                    <source>
                        <c:path>$user/emailAddress</c:path>
                    </source>
                </outbound>
                <inbound>
                    <target>
                        <c:path>$user/emailAddress</c:path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <c:ref>ri:ADDRESS.TEL1_NUMBR</c:ref>
                <outbound>
                    <source>
                        <c:path>$user/telephoneNumber</c:path>
                    </source>
                </outbound>
                <inbound>
                    <target>
                        <c:path>$user/telephoneNumber</c:path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <c:ref>ri:ADDRESS.DEPARTMENT</c:ref>
                <outbound>
                    <source>
                        <c:path>$user/organization</c:path>
                    </source>
                </outbound>
                <inbound>
                    <target>
                        <c:path>$user/organization</c:path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <c:ref>ri:ADDRESS.LANGU_P</c:ref>
                <outbound>
                    <source>
                        <c:path>$user/preferredLanguage</c:path>
                    </source>
                </outbound>
                <inbound>
                    <target>
                        <c:path>$user/preferredLanguage</c:path>
                    </target>
                </inbound>
            </attribute>

            <association>
                <c:ref>ri:roles</c:ref>
                <!-- roles are case sensitive, don't use stringIgnoreCase matchingRule -->
                <displayName>Activity group (role) Membership</displayName>
                <tolerant>true</tolerant>
                <kind>entitlement</kind>
                <intent>roles</intent>
                <direction>subjectToObject</direction>
                <associationAttribute>ri:ACTIVITYGROUPS.AGR_NAME</associationAttribute>
                <valueAttribute>icfs:uid</valueAttribute>
            </association>

            <protected>
                <filter>
                    <q:text>attributes/icfs:name = "admin"</q:text>
                </filter>
            </protected>
            <activation>
                <administrativeStatus>
                    <outbound/>
                    <inbound>
                        <strength>weak</strength>
                    </inbound>
                </administrativeStatus>
                <validFrom>
                    <outbound/>
                    <inbound/>
                </validFrom>
                <validTo>
                    <outbound/>
                    <inbound/>
                </validTo>
            </activation>
            <credentials>
                <password>
                    <outbound/>
                </password>
            </credentials>
        </objectType>
        <objectType>
            <kind>entitlement</kind>
            <intent>roles</intent>
            <displayName>ActivityGroups</displayName>
            <objectClass>ri:CustomACTIVITYGROUPObjectClass</objectClass>
            <attribute>
                <c:ref>icfs:name</c:ref>
                <limitations>
                    <access>
                        <read>true</read>
                        <add>false</add>
                        <modify>false</modify>
                    </access>
                </limitations>
                <!-- CASE Sensitive !!!-->
                <inbound>
                    <target>
                        <c:path>name</c:path>
                    </target>
                </inbound>
                <!-- select this role in midPoint as ActivityGroup, see also object-template and metarole -->
                <inbound>
                    <expression>
                        <value>SAP-ActivityGroup</value>
                    </expression>
                    <target>
                        <c:path>subtype</c:path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <c:ref>icfs:uid</c:ref>
                <limitations>
                    <access>
                        <read>true</read>
                        <add>false</add>
                        <modify>false</modify>
                    </access>
                </limitations>
                <!-- CASE Sensitive !!!-->
            </attribute>
            <!--
            <attribute>
                <c:ref>ri:PARENT_AGR</c:ref>
                <inbound>
                    <target>
                        <c:path>description</c:path>
                    </target>
                </inbound>
            </attribute>-->
        </objectType>

    </schemaHandling>

    <synchronization>
        <objectSynchronization>
            <name>user sync</name>
            <objectClass>ri:AccountObjectClass</objectClass>
            <kind>account</kind>
            <intent>default</intent>
            <enabled>true</enabled>
            <correlation>
                <q:equal>
                    <q:matching>polyStringNorm</q:matching>
                    <q:path>c:name</q:path>
                    <expression>
                        <c:path>$account/attributes/icfs:name</c:path>
                    </expression>
                </q:equal>
            </correlation>
            <reaction>
                <situation>linked</situation>
                <synchronize>true</synchronize>
            </reaction>
            <reaction>
                <situation>deleted</situation>
                <synchronize>true</synchronize>
                <action>
                    <handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-3#unlink</handlerUri>
                </action>
            </reaction>
            <reaction>
                <situation>unlinked</situation>
                <action>
                    <handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-3#link</handlerUri>
                </action>
            </reaction>
            <reaction>
                <situation>unmatched</situation>
                <synchronize>true</synchronize>
                <action>
                    <handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-3#addFocus</handlerUri>
                </action>
            </reaction>
        </objectSynchronization>


        <objectSynchronization>
            <name>role sync</name>
            <objectClass>ri:CustomACTIVITYGROUPObjectClass</objectClass>
            <kind>entitlement</kind>
            <intent>roles</intent>
            <focusType>c:RoleType</focusType>
            <enabled>true</enabled>
            <correlation>
                <q:equal>
                    <q:path>c:name</q:path>
                    <expression>
                        <c:path>$shadow/attributes/icfs:name</c:path>
                    </expression>
                </q:equal>
            </correlation>
            <reaction>
                <situation>linked</situation>
                <synchronize>true</synchronize>
            </reaction>
            <reaction>
                <situation>deleted</situation>
                <synchronize>true</synchronize>
                <action>
                    <handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-3#unlink</handlerUri>
                </action>
            </reaction>
            <reaction>
                <situation>unlinked</situation>
                <synchronize>true</synchronize>
                <action>
                    <handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-3#link</handlerUri>
                </action>
            </reaction>
            <reaction>
                <situation>unmatched</situation>
                <synchronize>true</synchronize>
                <action>
                    <handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-3#addFocus</handlerUri>
                </action>
            </reaction>
        </objectSynchronization>
    </synchronization>
</resource>
