How to override administrative status

In my previous post, I wrote how to override full name if you don’t have actual data from HR in all cases. We can have a similar problem with a special property like Administrative status (user is enabled/disabled/archived). In most cases you already have done the mapping from HR. If the employee is active (or current date is in valid range based on validFrom/validTo information from HR), you need to enable the user. If the employee left your company, you need to disable him/her. But there are some extra cases in reality where this is not enough. For example, the employee needs to extend his/her employment, but papers are late or HR data are not fresh. The employee needs an access to the systems to work (so you need to enable already automatically disabled user). Or you need to disable his/her access right now, definitely because he/she did something wrong (so you need to disable already automatically enabled user). How to solve this situation?

You can extend the user schema with the new attribute like “Override administrative status”, and if this attribute is set, its value has priority before standard automatic algorithm for calculating Administrative status over user object template.

Step 1: Extend the User Schema

Create a new extension.xsd file in [midpoint-home]\schema\ directory with this content:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsd:schema elementFormDefault="qualified"
  targetNamespace="http://midpoint.evolveum.com/xml/ns/custom/blog/extension-1"
  xmlns:tns="http://midpoint.evolveum.com/xml/ns/custom/blog/extension-1"
  xmlns:a="http://prism.evolveum.com/xml/ns/public/annotation-3"
  xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:import namespace="http://midpoint.evolveum.com/xml/ns/public/common/common-3" />

  <xsd:complexType name="UserExtensionType">
    <xsd:annotation>
      <xsd:appinfo>
        <a:extension ref="c:UserType" />
      </xsd:appinfo>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="overrideAdministrativeStatus" type="c:ActivationStatusType" minOccurs="0">
        <xsd:annotation>
          <xsd:appinfo>
            <a:indexed>true</a:indexed>
            <a:displayName>Override Administrative status</a:displayName>
            <a:displayOrder>900</a:displayOrder>
          </xsd:appinfo>
          <xsd:documentation>
            If this is filled, override administrative status from HR calculated from status.
            If you use this, please write to description a reason, why you do this (for example: She works on maternity leave).
          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

 

(Or open your existing file and put the appropriate code fragment to it.) 

Step 2: Restart midPoint

Stop and start tomcat service to read the extension schema.

Step 3: Create User object template

Log in to midPoint, go to menu –> Configuration –> Import object –> Get objects from “Embedded editor”, paste the next code snippet and click “Import object” button.

<objectTemplate xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:q="http://prism.evolveum.com/xml/ns/public/query-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:org="http://midpoint.evolveum.com/xml/ns/public/common/org-3" xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3" xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3" oid="c0c010c0-d34d-b33f-f00d-777222222333">
  <name>Sample User Template</name>

  <mapping>
    <name>Calculate administrative status from Valid from/to.
      If Override administrative status is filled, has priority.</name>
    <strength>strong</strength>
    <source>
      <c:path>$user/activation/validFrom</c:path>
    </source>
    <source>
      <c:path>$user/activation/validTo</c:path>
    </source>
    <source>
      <c:path>$user/extension/overrideAdministrativeStatus</c:path>
    </source>
    <expression>
      <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%20xsi%3Atype%3D%22c%3AScriptExpressionEvaluatorType%22%3E%0A%20%20%20%20%20%20%20%20%3Ccode%3E%0A%20%20%20%20%20%20%20%20%20%20import%20com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType%3B%0A%0A%20%20%20%20%20%20%20%20%20%20if%20(overrideAdministrativeStatus!%3Dnull)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20overrideAdministrativeStatus%3B%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20now%20%3D%20new%20java.util.Date()%3B%0A%20%20%20%20%20%20%20%20%20%20if%20(validFrom%20!%3D%20null%20%26amp%3B%26amp%3B%20now.before(validFrom.toGregorianCalendar().getTime()))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20ActivationStatusType.DISABLED%3B%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20if%20(validTo%20!%3D%20null%20%26amp%3B%26amp%3B%20now.after(validTo.toGregorianCalendar().getTime()))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20ActivationStatusType.DISABLED%3B%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20return%20ActivationStatusType.ENABLED%3B%0A%20%20%20%20%20%20%20%20%3C%2Fcode%3E%0A%20%20%20%20%20%20%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" />
    </expression>
    <target>
      <c:path>$user/activation/administrativeStatus</c:path>
    </target>
  </mapping>

  <mapping>
    <name>Calculate effective status from Valid from/to.
        If Override administrative status is filled, has priority.</name>
    <strength>strong</strength>
    <source>
      <c:path>$user/activation/validFrom</c:path>
    </source>
    <source>
      <c:path>$user/activation/validTo</c:path>
    </source>
    <source>
      <c:path>$user/extension/overrideAdministrativeStatus</c:path>
    </source>
    <expression>
      <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%20xsi%3Atype%3D%22c%3AScriptExpressionEvaluatorType%22%3E%0A%20%20%20%20%20%20%20%20%3Ccode%3E%0A%20%20%20%20%20%20%20%20%20%20import%20com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType%3B%0A%0A%20%20%20%20%20%20%20%20%20%20if%20(overrideAdministrativeStatus!%3Dnull)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20overrideAdministrativeStatus%3B%0A%20%20%20%20%20%20%20%20%20%20%7D%20%20%0A%0A%20%20%20%20%20%20%20%20%20%20now%20%3D%20new%20java.util.Date()%3B%0A%20%20%20%20%20%20%20%20%20%20if%20(validFrom%20!%3D%20null%20%26amp%3B%26amp%3B%20now.before(validFrom.toGregorianCalendar().getTime()))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20ActivationStatusType.DISABLED%3B%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20if%20(validTo%20!%3D%20null%20%26amp%3B%26amp%3B%20now.after(validTo.toGregorianCalendar().getTime()))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20ActivationStatusType.DISABLED%3B%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20return%20ActivationStatusType.ENABLED%3B%0A%20%20%20%20%20%20%20%20%3C%2Fcode%3E%0A%20%20%20%20%20%20%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" />
    </expression>
    <target>
      <c:path>$user/activation/effectiveStatus</c:path>
    </target>
  </mapping>
</objectTemplate>

 

Enable new user object template in menu –> Configuration –> System –> Object policies –> Edit –> select Object type = “UserType”, Object template = “Sample User Template” –> click “Save” & “Save” button.

(If you already have user object template put/edit the appropriate code snippet.)

Step 4: Fill in the new extended property to verify the functionality

Open existing user over menu –> List users –> click on existing user –> on tab “Basic”, at the end of line “Properties” click on “Show empty fields”, find new property “Override Administrative status” and select for example “disable” if current administrative status is enabled (or vice versa)

Override administrative status 1

–> click “Save” button. Now you can see in the standard “Administrative status” property the newly set value (Disabled):

Override administrative status 2

(or create a new user and fill Name, Valid from, Valid to and Override Administrative status)

Enjoy your work and excellent feedback from the customer, and do not forget to thank to midPoint and Evolveum by considering subscription and/or partnership.

Leave a Reply

Your email address will not be published.