Collection report: Comparing Attributes of Shadow and Attributes of User in MidPoint

Last modified 25 Apr 2024 10:39 +02:00

Please see Report configuration for basic information about configuration variables.

Example Use-case

We need report users with mismatched attributes, so we have to compare attributes of account of user and attributes of user in Midpoint. We create example which compare email prefix of user in Midpoint with firstname and lastname attributes of account chained by '.'.

Configuration

We need import object collection and report.

Example Resource Configuration

Git

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

<resource oid="ef2bc95b-76e0-59e2-86d6-9999cccccccc"
          xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-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:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
          xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-3"
          xmlns:cap="http://midpoint.evolveum.com/xml/ns/public/resource/capabilities-3">

    <name>Test CSV: username</name>

    <description>Simple CSV resource that is using single identifier (username)</description>

    <connectorRef type="ConnectorType">
        <filter>
            <q:equal>
                <q:path>c:connectorType</q:path>
                <q:value>com.evolveum.polygon.connector.csv.CsvConnector</q:value>
            </q:equal>
        </filter>
    </connectorRef>

    <connectorConfiguration xmlns:icfi="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.polygon.connector-csv/com.evolveum.polygon.connector.csv.CsvConnector">

        <icfc:configurationProperties>
            <icfi:filePath>target/midpoint.csv</icfi:filePath>
            <icfi:encoding>utf-8</icfi:encoding>
            <icfi:fieldDelimiter>,</icfi:fieldDelimiter>
            <icfi:multivalueDelimiter>;</icfi:multivalueDelimiter>
            <icfi:uniqueAttribute>username</icfi:uniqueAttribute>
            <icfi:passwordAttribute>password</icfi:passwordAttribute>
        </icfc:configurationProperties>

    </connectorConfiguration>

    <!-- Schema is empty. Schema should be generated by provisioning on the first use of this resource. -->

    <schemaHandling>

        <objectType>
            <displayName>Default Account</displayName>
            <default>true</default>
            <objectClass>ri:AccountObjectClass</objectClass>

            <attribute>
                <ref>ri:username</ref>
                <outbound>
                    <source>
                        <path>$user/name</path>
                    </source>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:firstname</ref>
                <outbound>
                    <source>
                        <path>$user/givenName</path>
                    </source>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:lastname</ref>
                <outbound>
                    <source>
                        <path>$user/familyName</path>
                    </source>
                </outbound>
            </attribute>

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

            <credentials>
                <password>
                    <outbound />
                </password>
            </credentials>

        </objectType>
    </schemaHandling>

    <capabilities>
        <configured>
            <cap:activation>
                <cap:status>
                    <cap:attribute>ri:disabled</cap:attribute>
                    <cap:enableValue>false</cap:enableValue>
                    <cap:disableValue>true</cap:disableValue>
                </cap:status>
            </cap:activation>
        </configured>
    </capabilities>
</resource>
Example CSV Source File

Git

username firstname lastname disabled password

user01

Firstname

Lastname

false

secret

user02

Test

Lastname

false

secret

Example Object Collection

Git

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

<objectCollection oid="72b1f98e-f587-4b9f-b92b-72e251dbb244">
    <name>Account shadows 'Test CSV: username'</name>
    <type>ShadowType</type>
    <filter>
        <text>
        resourceRef matches (oid = 'ef2bc95b-76e0-59e2-86d6-9999cccccccc') and kind = 'account'
        </text>
    </filter>
</objectCollection>
Example Report Configuration

Git

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 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.
  -->
<report 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"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        oid="c4590282-9ef2-4124-9980-a6a22fae009b">
    <name>Comparing attributes</name>
    <assignment>
        <targetRef oid="00000000-0000-0000-0000-000000000171" relation="default" type="ArchetypeType">
            <!-- Collection report -->
        </targetRef>
    </assignment>
    <archetypeRef oid="00000000-0000-0000-0000-000000000171" relation="default" type="ArchetypeType">
        <!-- Collection report -->
    </archetypeRef>
    <roleMembershipRef oid="00000000-0000-0000-0000-000000000171" relation="default" type="ArchetypeType">
        <!-- Collection report -->
    </roleMembershipRef>
    <objectCollection>
        <collection>
            <collectionRef oid="72b1f98e-f587-4b9f-b92b-72e251dbb244" relation="default" type="ObjectCollectionType">
                <!-- Account shadows 'Test CSV: username' -->
            </collectionRef>
        </collection>
        <view>
            <identifier>default-shadow</identifier>
            <column>
                <name>nameColumn</name>
                <path>attributes/username</path>
                <display>
                    <label>Login</label>
                </display>
            </column>
            <column>
                <name>firstNameColumn</name>
                <path>attributes/firstname</path>
                <display>
                    <label>First name</label>
                </display>
                <previousColumn>nameColumn</previousColumn>
            </column>
            <column>
                <name>lastNameColumn</name>
                <path>attributes/lastname</path>
                <display>
                    <label>Last name</label>
                </display>
                <previousColumn>firstNameColumn</previousColumn>
            </column>
            <column>
                <name>emailInMpColumn</name>
                <display>
                    <label>Email in midPoint</label>
                </display>
                <previousColumn>lastNameColumn</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
                                import com.evolveum.midpoint.prism.path.ItemPath;
                                import org.apache.commons.lang3.StringUtils;

                                user = midpoint.searchShadowOwner(object.getOid());
                                return user.asObjectable().getEmailAddress();
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <type>ShadowType</type>
        </view>
        <condition>
            <script>
                <code>
                   import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
                   import com.evolveum.midpoint.prism.path.ItemPath;
                   import org.apache.commons.lang3.StringUtils;

                  shadowAttributes = object.getAttributes().asPrismContainerValue()
                  login = shadowAttributes.findProperty(ItemPath.create("username")).getRealValue();
                  user = midpoint.searchShadowOwner(object.getOid());

                  if (user != null &amp;&amp; user.asObjectable() != null) {
                     email = user.asObjectable().getEmailAddress();
                     if (StringUtils.isEmpty(email)) {
                        return true;
                     }
                     firstName = shadowAttributes.findProperty(ItemPath.create("firstname"));
                     lastName = shadowAttributes.findProperty(ItemPath.create("lastname"));
                     if (firstName == null &amp;&amp; lastName == null) {
                        return false;
                     }

                     prefix = "";
                     if (firstName != null &amp;&amp; firstName.getRealValue() != null) {
                        prefix = firstName.getRealValue().toLowerCase().replace(" ", ".");
                     }

                     if (lastName != null &amp;&amp; lastName.getRealValue() != null) {
                        if (StringUtils.isNotEmpty(prefix)) {
                           prefix = prefix + "."
                        }
                        prefix = prefix + lastName.getRealValue().toLowerCase().replace(" ", ".");
                     }

                     if (StringUtils.isEmpty(prefix)) {
                        return true;
                     }

                     if (!prefix.equals(email.substring(0,email.indexOf("@")))) {
                        return true;
                     }

                  }
                  return false;
                </code>
            </script>
        </condition>
        <useOnlyReportView>true</useOnlyReportView>
    </objectCollection>
</report>
Was this page helpful?
YES NO
Thanks for your feedback