<?xml version="1.0"?>
<ldap-mapping>
    <!-- Core User resource schema -->
    <schema id="user-core" uri="urn:ietf:params:scim:schemas:core:2.0:User">
        <attribute name="id" mappedTo="entryUUID" />
        <attribute name="userName" mappedTo="uid" />
        <attribute name="displayName" mappedTo="displayName" />
        <attribute name="nickName" mappedTo="" />
        <attribute name="profileUrl" mappedTo="" />
        <attribute name="title" mappedTo="title" />
        <attribute name="userType" mappedTo="employeeType" />
        <attribute name="preferredLanguage" mappedTo="preferredLanguage" />
        <attribute name="locale" mappedTo="" />
        <attribute name="timezone" mappedTo="" />
        <attribute name="active" handlerRef="activeHandler" />
        <attribute name="password" show="false" mappedTo="userPassword" />

        <complex-attribute name="name">
            <at-group>
                <attribute name="familyName" mappedTo="sn" />
                <attribute name="givenName" mappedTo="cn" />
                <attribute name="middleName" mappedTo="" />
                <attribute name="honorificPrefix" mappedTo="title" />
                <attribute name="honorificSuffix" mappedTo="" />
            </at-group>
        </complex-attribute>

        <multival-attribute name="emails">
            <at-group>
                <attribute name="value" mappedTo="mail" />
            </at-group>
        </multival-attribute>

        <multival-attribute name="phoneNumbers">
            <at-group>
                <attribute name="value" mappedTo="telephoneNumber" />
            </at-group>
        </multival-attribute>

        <multival-attribute name="ims">
        </multival-attribute>

        <multival-attribute name="photos" handlerRef="photosHandler">
            <at-group>
                <attribute name="value" mappedTo="jpegPhoto" />
            </at-group>
        </multival-attribute>

        <multival-attribute name="addresses">
            <at-group>
                <attribute name="streetAddress" mappedTo="street" />
                <attribute name="locality" mappedTo="l" />
                <attribute name="region" mappedTo="" />
                <attribute name="postalCode" mappedTo="postalCode" />
                <attribute name="country" mappedTo="" />
                <formatted format="$streetAddress $locality" />
            </at-group>
        </multival-attribute>

        <multival-attribute name="groups" handlerRef="groupsHandler">
            <handlerArg name="baseDn" value="ou=system"/>
            <handlerArg name="filter" value="(member=$entryDn)"/> 
        </multival-attribute>

        <multival-attribute name="entitlements" />

        <multival-attribute name="roles" />

        <multival-attribute name="x509Certificates">
            <at-group>
                <attribute name="value" mappedTo="userCertificate" />
            </at-group>
        </multival-attribute>

        <complex-attribute name="meta" handlerRef="metaHandler" />

    </schema>

    <!-- Enterprise User resource schema -->
    <schema id="enterprise-user" uri="urn:ietf:params:scim:schemas:extension:enterprise:2.0:User">
        <attribute name="employeeNumber" mappedTo="" />
        <attribute name="costCenter" mappedTo="" />
        <attribute name="organization" mappedTo="" />
        <attribute name="division" mappedTo="" />
        <attribute name="department" mappedTo="" />

        <complex-attribute name="manager">
            <at-group>
                <attribute name="managerId" mappedTo="" />
                <attribute name="$ref" mappedTo="" />
                <attribute name="displayName" mappedTo="" />
            </at-group>
        </complex-attribute>
    </schema>

    <schema id="group" uri="urn:ietf:params:scim:schemas:core:2.0:Group">
        <attribute name="displayName" mappedTo="cn" />
        <attribute name="id" mappedTo="entryUUID" />
        <multival-attribute name="members" handlerRef="membersHandler"/>
        <complex-attribute name="meta" handlerRef="metaHandler" />
    </schema>

    <resourceType name="User" baseDn="ou=system" filter="(objectClass=inetOrgPerson)">
        <schemaRef id="user-core" />
        <schemaRef id="enterprise-user" />
        <rdnAtRef name="userName"/>
        <reqUri value="/Users"/>
        <objectClasses>
         <objectClass>inetOrgPerson</objectClass>
        </objectClasses>
    </resourceType>

    <resourceType name="Group" baseDn="ou=system" filter="(objectClass=groupOfUniqueNames)">
        <schemaRef id="group" />
        <rdnAtRef name="displayName"/>
        <reqUri value="/Groups"/>
        <objectClasses>
         <objectClass>groupOfUniqueNames</objectClass>
        </objectClasses>
    </resourceType>

    <atHandlers>
        <handler name="activeHandler"
            class="org.apache.directory.scim.ldap.handlers.ActiveAttributeHandler" />
        <handler name="metaHandler"
            class="org.apache.directory.scim.ldap.handlers.MetaAttributeHandler" />
        <handler name="groupsHandler"
            class="org.apache.directory.scim.ldap.handlers.GroupsAttributeHandler" />
        <handler name="photosHandler"
            class="org.apache.directory.scim.ldap.handlers.PhotosAttributeHandler" />
        <handler name="membersHandler"
            class="org.apache.directory.scim.ldap.handlers.MembersAttributeHandler" />
    </atHandlers>
</ldap-mapping>