<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (C) 2010-2021 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 DB Table resource
using an Identity Connector Framework DBTable connector.

-->

<objects xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
        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"
>

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

        <!-- Resource name. It will be displayed in GUI.  -->
        <name>Localhost DBTable2</name>

        <!-- Reference to the ICF DatabaseTable connector. OID is "virtual" for now. -->
        <connectorRef type="ConnectorType">
            <filter>
                <q:text>c:connectorType = "org.identityconnectors.databasetable.DatabaseTableConnector"</q:text>
            </filter>
        </connectorRef>

        <!-- Configuration section contains configuration of the connector,
             such as hostnames and passwords -->
        <connectorConfiguration>

            <!-- Configuration specific for the DBTable connector -->
            <icfc:configurationProperties
                    xmlns:icscdbtable="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.polygon.connector-databasetable/org.identityconnectors.databasetable.DatabaseTableConnector">
                <icscdbtable:port>3306</icscdbtable:port>
                <icscdbtable:quoting></icscdbtable:quoting>
                <icscdbtable:host>localhost</icscdbtable:host>
                <icscdbtable:user>midpoint_tests</icscdbtable:user>
                <icscdbtable:password>
                    <clearValue>secret</clearValue>
                </icscdbtable:password>
                <icscdbtable:database>midpoint_tests</icscdbtable:database>
                <icscdbtable:table>idrepo2</icscdbtable:table>
                <icscdbtable:keyColumn>userId</icscdbtable:keyColumn>
                <icscdbtable:passwordColumn>password</icscdbtable:passwordColumn>
                <icscdbtable:jdbcDriver>com.mysql.jdbc.Driver</icscdbtable:jdbcDriver>
                <icscdbtable:jdbcUrlTemplate>jdbc:mysql://%h:%p/%d?useUnicode=true&amp;characterEncoding=utf8&amp;connectionCollation=utf8_bin</icscdbtable:jdbcUrlTemplate>
                <icscdbtable:enableEmptyString>false</icscdbtable:enableEmptyString>
                <icscdbtable:rethrowAllSQLExceptions>true</icscdbtable:rethrowAllSQLExceptions>
                <icscdbtable:nativeTimestamps>false</icscdbtable:nativeTimestamps>
                <icscdbtable:allNative>false</icscdbtable:allNative>
                <icscdbtable:changeLogColumn></icscdbtable:changeLogColumn>
                <icscdbtable:datasource></icscdbtable:datasource>
            </icfc:configurationProperties>

            <!-- Generic ICF configuration -->


        </connectorConfiguration>

        <!-- 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>

            <!-- Definition of default account type.
                 This is now the only account type that midPoint can work with. -->
            <objectType>
                <!-- Readable name for the account type -->
                <displayName>Default Account</displayName>
                <default>true</default>

                <!-- Reference to the Resource Schema (see above) specifying
                     object class for this account type -->
                <objectClass>ri:AccountObjectClass</objectClass>
                <attribute>
                    <ref>icfs:uid</ref>

                    <!-- Readable name for the attribute. This will be used in GUI -->
                    <displayName>Entry UUID</displayName>

                    <!-- Access limitation for this attribute.
                         Entry UUID is created by the directory server itelf
                         and it is immutable. We can only read it. -->
                    <limitations>
                        <access>
                            <read>true</read>
                        </access>
                    </limitations>
                </attribute>
                <attribute>
                    <ref>icfs:name</ref>

                    <!-- Readable name for the attribute. This will be used in GUI -->
                    <displayName>UserId</displayName>

                    <!-- Access limitation for this attribute.
                          -->
                    <limitations>
                        <minOccurs>0</minOccurs>
                        <access>
                            <read>true</read>
                            <add>true</add>
                            <modify>true</modify>
                        </access>
                    </limitations>
                    <outbound>
                        <source>
                            <path>$user/name</path>
                        </source>
                    </outbound>
                </attribute>

                <!-- The "id" attribute is auto-generated by
                database, it should not be changed thus we ignore it completely.

                It would be betted if we could use this as uid, but DBTable connector uses
                icfs:name = icfs:uid so this not yet possible -->
                <attribute>
                    <ref>ri:id</ref>
                    <displayName>Autoincrement id</displayName>
                    <limitations>
                        <processing>ignore</processing>
                    </limitations>
                </attribute>

                <attribute>
                    <ref>ri:firstName</ref>
                    <displayName>First name</displayName>
                    <description>Definition of Firstname attribute handling.</description>
                    <outbound>
                        <source>
                            <path>$user/givenName</path>
                        </source>
                    </outbound>

                </attribute>
                <attribute>
                    <ref>ri:lastName</ref>
                    <displayName>Last name</displayName>
                    <description>Definition of Lastname attribute handling.</description>
                    <outbound>
                        <source>
                            <path>$user/familyName</path>
                        </source>
                    </outbound>

                </attribute>
                <attribute>
                    <ref>ri:fullName</ref>
                    <displayName>Full name</displayName>
                    <description>Definition of Fullname attribute handling.</description>
                    <outbound>
                        <source>
                            <path>$user/fullName</path>
                        </source>
                    </outbound>
                </attribute>

                <attribute>
                    <ref>ri:pin</ref>
                    <displayName>PIN</displayName>
                    <limitations>
                        <minOccurs>0</minOccurs>
                        <access>
                            <read>true</read>
                            <add>true</add>
                            <modify>true</modify>
                        </access>
                    </limitations>
                    <outbound>
                        <strength>weak</strength>
                        <expression>
                            <generate>
                                <valuePolicyRef oid="81818181-76e0-59e2-8888-3d4f02d3fffa"/>
                            </generate>
                        </expression>
                    </outbound>
                </attribute>

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

                <credentials>
                    <password>
                        <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:disabled</cap:attribute>
                        <cap:enableValue></cap:enableValue>
                        <cap:enableValue>false</cap:enableValue>
                        <cap:disableValue>true</cap:disableValue>
                    </cap:status>
                </cap:activation>
            </configured>
        </capabilities>

    </resource>

    <valuePolicy oid="81818181-76e0-59e2-8888-3d4f02d3fffa" xsi:type="c:ValuePolicyType" version="0" xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <name>Numeric PIN Policy - first character not zero</name>
        <description>A policy useful for generating PIN. The first character
            is not zero to avoid string to integer conversion losing the first character.
        </description>
        <stringPolicy>
            <description>String validation policy</description>
            <limitations>
                <minLength>4</minLength>
                <maxLength>4</maxLength>
                <minUniqueChars>2</minUniqueChars>
                <!-- not implemented yet
                 <checkAgainstDictionary>false</checkAgainstDictionary>
                 -->
                <checkPattern/>
                <limit>
                    <description>Numeric characters (first digit - excluding zero)</description>
                    <minOccurs>1</minOccurs>
                    <mustBeFirst>true</mustBeFirst>
                    <characterClass>
                        <value>123456789</value>
                    </characterClass>
                </limit>
                <limit>
                    <description>Numeric characters</description>
                    <mustBeFirst>false</mustBeFirst>
                    <characterClass>
                        <value>1234567890</value>
                    </characterClass>
                </limit>
            </limitations>
        </stringPolicy>
    </valuePolicy>

</objects>
