Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Current »


Hooks are midPoint mechanism for injecting a code to or intercepting of normal midPoint flows. E.g. a hook can be used to inset custom notification after an operation is complete, modify the operation request before it is even processed, redirect processing to a workflow or trouble-ticket system or do any other kind of advanced customization magic.

Hooks are typically pieces of Java code that has to be compiled and assembled into midPoint. However there is also a lightweight way to create a hook using a scripting code. Each hook is simply a piece of script code that is executed at the specified moment in the midPoint recompute and execute flow (see Clockwork and Projector). The code can influence the recomputation and execution by manipulating the model context, it can invoke script expression functions, invoke external functions or do almost any other thing.

Scripting Hook Definition

Scripting hooks can be defined in System Configuration Object. The modelHooks element is used the define both heavyweight Java hooks and lightweight scripting hooks. The following code block provides an example of Groovy scripting hook.

<systemConfiguration oid="00000000-0000-0000-0000-000000000001">
                <name>Example scripting hook</name>
                        import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
                        //import com.evolveum.midpoint.model.intest.util.StaticHookRecorder;

                        log.debug('ORG HOOK WAS HERE')

                        UserType user = (UserType)focus;
                        organizations = user.getOrganization();
                        for (orgName in organizations) {
                            org = midpoint.searchObjectByName(OrgType.class, orgName)
                            if (org == null) {
                                // Org does not exist, lets create it
                                org = midpoint.createEmptyObjectWithName(OrgType.class, orgName);
                                topOrgRef = new ObjectReferenceType();
                            if (!midpoint.isDirectlyAssigned(org)) {
                                // The org is not assigned. Let's assign it.
                                // We need to construct a delta to do this
                                assignment = new AssignmentType();
                                orgTarget = new ObjectReferenceType();
                                assignmentDelta = ContainerDelta.createModificationAdd(UserType.F_ASSIGNMENT, UserType.class, prismContext, assignment);

Example 1

Following scripting hook removes all assignments from disabled users. Please note usage of modelContext.rot()

    <name>Remove assignments from disabled users</name>
            import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

            UserType user = (UserType) focus;
            ActivationStatusType administrativeStatus = user.getActivation().getAdministrativeStatus();
            if (administrativeStatus == ActivationStatusType.DISABLED) {     
				changed = false;               
                for (AssignmentType assign : user.getAssignment()) {
                    assignmentDelta = ContainerDelta.createModificationDelete(UserType.F_ASSIGNMENT, UserType.class, prismContext, assign.clone());                                                            
                    log.debug('Removing assignment ' + assignmentDelta + ' from disabled user ' + user.getName());                    
					changed = true;
				if (changed) {  
                    modelContext.rot(); // this makes Projector to recompute the model context



  • No labels