<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 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.
  -->

<role oid="daa3b69a-107e-11e6-9551-538f491a0753"
        xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
        xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
        xmlns:piracy="http://midpoint.evolveum.com/xml/ns/samples/piracy">
    <name>Project Metarole</name>

    <inducement>
        <construction>
            <!-- OpenLDAP resource -->
            <resourceRef oid="28b699cc-107c-11e6-8277-034841879377" type="c:ResourceType"/>
            <kind>entitlement</kind>
            <intent>ldapGroup</intent>
            <attribute>
                <ref>ri:description</ref>
                <outbound>
                    <strength>strong</strength>
                    <source>
                        <path>displayName</path>
                    </source>
                </outbound>
            </attribute>
        </construction>
       </inducement>

    <inducement>
        <description>PM-I2-L</description>
        <construction>
            <description>PM-I2-L</description>
            <resourceRef oid="28b699cc-107c-11e6-8277-034841879377" type="c:ResourceType"/>
            <kind>account</kind>
            <intent>default</intent>
            <association>
                <ref>ri:ldapGroup</ref>
                <outbound>
                    <expression>
                        <associationFromLink>
                            <projectionDiscriminator>
                                <kind>entitlement</kind>
                                <intent>ldapGroup</intent>
                            </projectionDiscriminator>
                        </associationFromLink>
                    </expression>
                </outbound>
            </association>
        </construction>
        <order>2</order>
        <condition>
            <expression>
                <script>
                    <code>
                        focus.getClass() == com.evolveum.midpoint.xml.ns._public.common.common_3.UserType.class
                    </code>
                </script>
            </expression>
        </condition>
    </inducement>

    <inducement>
        <construction>
            <!-- OpenLDAP resource -->
            <resourceRef oid="28b699cc-107c-11e6-8277-034841879377" type="c:ResourceType"/>
            <kind>entitlement</kind>
            <intent>posixGroup</intent>
            <attribute>
                <ref>ri:description</ref>
                <outbound>
                    <strength>strong</strength>
                    <source>
                        <path>displayName</path>
                    </source>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:gidNumber</ref>
                <outbound>
                    <source>
                        <path>identifier</path>
                    </source>
                    <expression>
                        <script>
                            <code>5000 + identifier as int</code>
                        </script>
                    </expression>
                </outbound>
            </attribute>
        </construction>
    </inducement>

    <inducement>
        <description>PM-I2-P</description>
        <construction>
            <description>PM-I2-P</description>
            <resourceRef oid="28b699cc-107c-11e6-8277-034841879377" type="c:ResourceType"/>
            <kind>account</kind>
            <intent>default</intent>
            <association>
                <ref>ri:posixGroup</ref>
                <outbound>
                    <expression>
                        <associationFromLink>
                            <projectionDiscriminator>
                                <kind>entitlement</kind>
                                <intent>posixGroup</intent>
                            </projectionDiscriminator>
                        </associationFromLink>
                    </expression>
                </outbound>
            </association>
        </construction>
        <order>2</order>
        <condition>
            <expression>
                <script>
                    <code>
                        focus.getClass() == com.evolveum.midpoint.xml.ns._public.common.common_3.UserType.class
                    </code>
                </script>
            </expression>
        </condition>
    </inducement>

</role>
