<?xml version="1.0" encoding="UTF-8"?>
<resource oid="042f4119-1ee9-4f09-b6bc-7a0846d45ac6"
        xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:c="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:org="http://midpoint.evolveum.com/xml/ns/public/common/org-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:t="http://prism.evolveum.com/xml/ns/public/types-3">
    <name>Azure</name>


    <connectorRef relation="org:default" type="c:ConnectorType">
        <filter>
            <q:text>c:connectorType = "com.evolveum.polygon.connector.msgraphapi.MSGraphConnector"</q:text>
        </filter>
    </connectorRef>

    <connectorConfiguration xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-3">
        <icfc:configurationProperties
                xmlns:icfccp="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.polygon.connector-msgraph/com.evolveum.polygon.connector.msgraphapi.MSGraphConnector">
            <icfccp:clientId>c51be51e-c2e1-4ce3-840e-c921f0dce403</icfccp:clientId>
            <icfccp:clientSecret>
                <t:clearValue>Q4j7Q~CQ2zVD5qnZISDdzrH~tu4QqfM_PzMcq</t:clearValue>
            </icfccp:clientSecret>
            <icfccp:tenantId>adb6ebb6-38a7-48d7-91a1-27bd54b25fb3</icfccp:tenantId>
        </icfc:configurationProperties>

        <icfc:resultsHandlerConfiguration>
            <icfc:enableNormalizingResultsHandler>false</icfc:enableNormalizingResultsHandler>
            <icfc:enableFilteredResultsHandler>false</icfc:enableFilteredResultsHandler>
            <icfc:enableAttributesToGetSearchResultsHandler>false</icfc:enableAttributesToGetSearchResultsHandler>
        </icfc:resultsHandlerConfiguration>
    </connectorConfiguration>

    <schemaHandling>
        <objectType>
            <kind>account</kind>
            <intent>default</intent>
            <displayName>Default Account</displayName>
            <default>true</default>
            <objectClass>ri:AccountObjectClass</objectClass>

            <attribute>
                <ref>icfs:name</ref>
                <outbound>
                    <source>
                        <path>$user/emailAddress</path>
                    </source>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.util.exception.ExpressionEvaluationException

                                if (emailAddress != null) {
                                    String[] mailArray = emailAddress.toString().split("@")
                                    return mailArray[0] + "@evolveumsandbox.onmicrosoft.com"
                                } else {

                                    throw new ExpressionEvaluationException("Email address can not be null.")
                                }
                            </code>
                        </script>
                    </expression>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:userPrincipalName</ref>
                <outbound>
                    <source>
                        <path>$user/emailAddress</path>
                    </source>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.util.exception.ExpressionEvaluationException

                                if (emailAddress != null) {
                                    String[] mailArray = emailAddress.toString().split("@")
                                    return mailArray[0] + "@evolveumsandbox.onmicrosoft.com"
                                } else {

                                    throw new ExpressionEvaluationException("Email address can not be null.")
                                }
                            </code>
                        </script>
                    </expression>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:givenName</ref>
                <outbound>
                    <source>
                        <path>$user/givenName</path>
                    </source>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:surname</ref>
                <outbound>
                    <source>
                        <path>$user/familyName</path>
                    </source>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:displayName</ref>
                <outbound>
                    <source>
                        <path>$user/givenName</path>
                    </source>
                    <source>
                        <path>$user/familyName</path>
                    </source>
                    <expression>
                        <script>
                            <code>
                                name = basic.concatName(givenName, familyName)

                                return name
                            </code>
                        </script>
                    </expression>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:mailNickname</ref>
                <outbound>
                    <source>
                        <path>$user/nickName</path>
                    </source>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:memberOfGroup</ref>
                <fetchStrategy>explicit</fetchStrategy>
            </attribute>

            <association>
                <ref>ri:group</ref>
                <kind>entitlement</kind>
                <intent>group</intent>
                <direction>objectToSubject</direction>
                <associationAttribute>ri:members</associationAttribute>
                <valueAttribute>ri:id</valueAttribute>
                <shortcutAssociationAttribute>ri:memberOfGroup</shortcutAssociationAttribute>
                <shortcutValueAttribute>icfs:uid</shortcutValueAttribute>
            </association>

            <activation>
                <administrativeStatus>
                    <outbound>
                        <strength>strong</strength>
                    </outbound>
                </administrativeStatus>
            </activation>

            <credentials>
                <password>
                    <outbound>
                        <strength>weak</strength>
                    </outbound>
                </password>
            </credentials>
        </objectType>

        <objectType>
            <kind>entitlement</kind>
            <intent>group</intent>
            <default>true</default>
            <objectClass>ri:GroupObjectClass</objectClass>

            <attribute>
                <ref>icfs:uid</ref>
            </attribute>

            <attribute>
                <ref>icfs:name</ref>
                <outbound>
                    <source>
                        <path>name</path>
                    </source>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:displayName</ref>
                <outbound>
                    <source>
                        <path>name</path>
                    </source>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:mailEnabled</ref>
                <outbound>
                    <source>
                        <path>extension/mailEnabled</path>
                    </source>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:allowExternalSenders</ref>
                <outbound>
                    <source>
                        <path>extension/allowExternalSenders</path>
                    </source>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:securityEnabled</ref>
                <outbound>
                    <source>
                        <path>extension/securityEnabled</path>
                    </source>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:mailNickname</ref>
                <outbound>
                    <source>
                        <path>name</path>
                    </source>
                </outbound>
            </attribute>

            <attribute>
                <ref>ri:groupTypes</ref>
                <outbound>
                    <source>
                        <path>extension/groupTypes</path>
                    </source>
                </outbound>
            </attribute>

        </objectType>

        <objectType>
            <kind>entitlement</kind>
            <intent>license</intent>
            <default>false</default>
            <objectClass>ri:CustomlicenseObjectClass</objectClass>

            <attribute>
                <ref>icfs:uid</ref>
            </attribute>

            <attribute>
                <ref>icfs:name</ref>
                <inbound>
                    <strength>strong</strength>
                    <target>
                        <path>name</path>
                    </target>
                </inbound>
                <inbound>
                    <strength>strong</strength>
                    <target>
                        <path>displayName</path>
                    </target>
                    <expression>
                        <script>
                            <code>
                                "Azure license: " + input.toString()
                            </code>
                        </script>
                    </expression>
                </inbound>
            </attribute>

            <attribute>
                <ref>ri:skuId</ref>
                <inbound>
                    <strength>strong</strength>
                    <target>
                        <path>identifier</path>
                    </target>
                </inbound>
            </attribute>

            <attribute>
                <ref>ri:consumedUnits</ref>
                <inbound>
                    <strength>strong</strength>
                    <target>
                        <path>extension/consumedUnits</path>
                    </target>
                </inbound>
            </attribute>

            <attribute>
                <ref>ri:prepaidUnits.enabled</ref>
                <fetchStrategy>explicit</fetchStrategy>
                <inbound>
                    <strength>strong</strength>
                    <target>
                        <path>extension/prepaidUnits</path>
                    </target>
                </inbound>
            </attribute>
        </objectType>
    </schemaHandling>

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

    <synchronization>
        <objectSynchronization>
            <objectClass>ri:AccountObjectClass</objectClass>
            <kind>account</kind>
            <intent>default</intent>
            <enabled>true</enabled>
            <focusType>c:UserType</focusType>
            <correlation>
                <q:equal>
                    <q:path>name</q:path>
                    <expression>
                        <path>$projection/attributes/icfs:name</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#inactivateFocus</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>

        <objectSynchronization>
            <kind>entitlement</kind>
            <intent>group</intent>
            <enabled>true</enabled>
            <objectClass>ri:GroupObjectClass</objectClass>
            <focusType>c:RoleType</focusType>

            <correlation>
                <q:equal>
                    <q:path>name</q:path>
                    <expression>
                        <path>$projection/attributes/icfs:name</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>

        <objectSynchronization>
            <kind>entitlement</kind>
            <intent>license</intent>
            <enabled>true</enabled>
            <objectClass>ri:CustomlicenseObjectClass</objectClass>
            <focusType>c:ServiceType</focusType>

            <correlation>
                <q:equal>
                    <q:path>name</q:path>
                    <expression>
                        <path>$projection/attributes/icfs:name</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>