When midPoint function libraries reduce repeated script logic
The same naming, normalization or lookup code tends to appear in many places in a midPoint configuration: in several mappings, in more than one object template, and in expressions copied from one resource to the next. Each copy starts identical and then drifts as someone fixes a bug in one place but not the others. Function libraries exist to group frequently used code so that configuration is simpler to maintain. Evolveum's current features documentation describes them in exactly those terms, as a way to simplify midPoint configuration and its upkeep. A function library is worth considering when the same logic is needed in more than one expression, when a change to a rule (for example, how a username is normalized) would otherwise require editing many objects, or when a reviewer needs to read one definition rather than trace the same routine through several mappings.
Libraries are a maintenance decision, not a default. Logic that is specific to one mapping, such as a single attribute transformation tied to one resource's data quirks, usually stays in that expression, where its inputs and intent are visible. Expressions still decide what a particular mapping does with its source and target values, and the choice of expression type and strength stays with the mapping itself. Before moving code, list each place it is used and confirm that all copies really do the same thing. Where they differ, the difference is often a business rule that deserves a name of its own or a decision that should stay local. Confirm with your midPoint version's documentation how libraries are declared and called, because the exact structure, and how it is versioned and secured, depends on the release you run.
How to structure a function library for maintainability
A function library is only worth its maintenance cost if it has clear boundaries. The decisions below determine what goes into shared code, how functions are named and documented, and how the library is split so that a change in one area does not break unrelated mappings.
Decide what is shared and what stays local
Move a piece of logic into the library only when two or more mappings, object templates or tasks need the same behavior. Logic that is specific to one resource or one attribute usually belongs in the expression that uses it. Before moving code, list every place it is called and confirm the callers would accept the same inputs and outputs. Sharing too early creates a dependency that is hard to undo.
Group functions by purpose
Organize functions into sub-libraries by what they do, such as naming, attribute normalization, lookups and date handling. A reader who needs to change how a surname is normalized should find that function in one predictable place. Purpose-based groups also make it easier to decide which team owns each group and who reviews changes to it.
Adopt consistent naming conventions
Agree on a naming pattern before the first function is written, for example a verb followed by the object it acts on, and a prefix that shows the group. Include the expected input type in the name where it prevents mistakes, such as a function that takes a DN rather than a plain username. Renaming later touches every expression that calls the function, so the convention is cheaper to set at the start.
Document inputs, outputs and failure behavior
Each function should state the types it accepts, the value it returns, and what it returns or raises when an input is missing. Note whether a function is pure or reads from the repository, because that changes how it behaves during simulation and in tasks. Documentation kept beside the code, in a consistent comment header, is easier to keep accurate than a separate wiki page.
Avoid a single catch-all library
A single file that holds every function grows until no one can see what depends on what. Split the library into several files or modules with narrow responsibilities, and keep dependencies between them one-directional. This also limits the blast radius of a bad change, because a fault in the lookup group does not force a review of the naming group.
Confirm the library loading model
Check in your midPoint version how library functions are loaded and referenced from expressions, and whether a change requires a restart or a reload. Confirm this against the midPoint documentation for your release rather than assuming it from another version. Record the answer in the team's runbook, because it determines how changes are tested and rolled out.
Current features docsOptions for where shared logic lives
This table compares three places to put repeated midPoint logic: inline in each mapping, in a shared function library, or in an overlay project. Read each row to see when the option fits, what it costs to maintain, how exposed it is to upgrades and how it is tested. The main takeaway is that a function library usually covers repeated expression logic, and an overlay should be reserved for changes that configuration cannot express.
| Option | When it fits | Maintenance cost | Upgrade exposure | Testing approach |
|---|---|---|---|---|
| Inline in each mapping | One or two mappings that use the logic, or a quick prototype | Low at first, but every copy must be edited when a rule changes | Low, because the logic lives in configuration objects that migrate with the project | Test each mapping separately with sample identities and compare outputs by hand |
| Shared function library | The same derivation (for example, username or email rules) appears in several mappings or object templates | Moderate: one definition to change, plus review of who may edit it and where it is used | Low to moderate: the library is configuration, so it must be re-checked after expression or security changes in an upgrade | Unit-style test scripts that call library functions with fixed inputs, run before each import into a test environment |
| Overlay project for code-level changes | Behavior that configuration and expressions cannot reach, such as custom Java code or changed internals | High: a build pipeline, code review and ongoing merges with each midPoint release | High: each upgrade may require rebuilding and retesting the overlay against the new version | Automated build and integration tests in a test environment, plus regression checks on each upgrade |
| Where the logic is stored | Inside the midPoint repository as configuration objects | Exported as XML or managed as files in version control | Compiled into the deployed artifact | Affects which review and rollback steps apply |
| Ownership and review | Any mapping author who can edit the object | A named owner who approves changes to shared functions | Platform or development team with release sign-off | Confirm the approval path with your security and change teams |
| Security exposure of expressions | Expressions run with the permissions of the configured script type | Review library code for the same risks as any expression | Confirm the expression and security profile behavior for your target release | Check script execution limits and access in a test environment |
| Decision guidance | Default for logic used once | Default for repeated expression logic | Use only when configuration cannot meet the need | Overlay choices are covered on a separate page in this group |
Setting up a function library from existing script logic
This sequence turns repeated expression code in a midPoint deployment into one tested function library entry that existing mappings and expressions call. It gives the team a single place to change shared logic and a documented check that behavior did not change during the move.
Inventory repeated expression logic
The integration or identity engineer exports the configuration objects that hold scripts, such as mappings on resources, object templates and roles, and searches them for blocks of code that appear more than once. Record each candidate with the object it lives in, the expression type it uses and the inputs it reads. The step is done when the team has a list of duplicated logic with the objects that depend on each copy. Confirm the export method and the object locations for your midPoint version before you search, since they vary by release.
Select one function to extract
The engineer and the identity owner choose a single piece of logic to move first, preferably a small, pure transformation such as normalizing a name or building a username from parts. Avoid starting with code that reads or writes many attributes or depends on other mappings running in a particular order. The output is a short written definition of the function: its name, inputs, expected output and every object that will call it. Confirm that the team agrees on the function's contract before any code moves.
Move the function into the library
The engineer adds the function to the function library object in the configuration, keeping its original logic intact and adding no behavior beyond what the copies already do. The function is given a clear name and a short comment that explains the inputs. Store the change in the same repository as the rest of the configuration so it is reviewed like other code. The step is done when the library loads in a non-production environment without errors in the logs.
Point existing expressions at the library
The engineer replaces each copied block with a call to the library function, one object at a time, and commits each change separately so a rollback is simple. Where a copy differs slightly from the others, the team decides whether to keep it as a separate function or align it, and records that decision. The output is a list of changed objects mapped to the function call that now replaces their code. Check each changed object for syntax errors before moving on.
Compare outputs on sample identities
In a non-production environment, the engineer runs the affected mappings or a simulation against a fixed set of sample identities, covering typical records and known edge cases such as missing attributes, accented characters and duplicate names. The engineer records the results from before and after the change and compares them field by field. The check passes when every sample produces the same output, or each difference is explained and approved by the identity owner.
Test failure and error paths
The engineer runs the function with inputs that should fail, such as null values or unexpected types, and confirms that the error handling matches the original copies. The team checks the logs and any task or object errors produced in the test environment. The step is done when the failure behavior is documented and no path produces a silent blank value that the original code would have flagged.
Remove the old copies after sign-off
After the team signs off on the comparison and error tests, the engineer deletes the remaining copied code in a separate change, with the commit history linking back to the earlier verification records. The configuration is then deployed to production using the normal release process. The step is done when a search for the old code block returns no matches and the production comparison of a small set of records matches the test results.
Versioning library code with configuration as files
A function library and the objects that call it should live in the same version control repository, so a change to a shared function is reviewed and promoted together with the mappings, object templates and roles that depend on it. If the library sits in one repository and the callers sit in another, a developer can change a helper function that breaks a mapping in production with no record linking the two. Keep the library file, the functions definitions it exposes and the calling objects in one tree, and treat a library change as a change to every object that imports it. Before you choose a layout, confirm with the midPoint version you run how library files are loaded from disk and how they map to the repository objects you export.
Use a branch per change, with the main branch as the only source for promotion. A library change should carry its test evidence and a list of the calling objects it touches, so the reviewer can see the blast radius without tracing imports by hand. Assign a named owner to each shared library, and require that owner's approval for any merge that alters a function signature or return value. Agree a rule for breaking changes early, such as adding a new function name and deprecating the old one over one or more releases, so callers can move at their own pace instead of all changing in one deployment.
Environments should receive the same committed version rather than separately edited copies. Promote one tagged commit through development, test and production, and let each environment differ only in its connection settings and secrets, which belong outside the library files. Record which commit is deployed to each environment so an incident can be traced to a specific change. Tooling that edits objects directly against a running system is covered on the midPoint Studio page, and the pipeline itself is covered under configuration as code in the deployment section, so the reader should check those pages before choosing a workflow.
Security profiles and trust for shared script code
A function library is shared code that many mappings, object templates and policies call, so a change to one function can alter access decisions across the whole identity estate. The cards below cover who can edit that code, what privileges it runs with, how changes are recorded, and which expression language carries the risk. Confirm the security profile settings for your midPoint version before you rely on any of them.
Restrict who can edit library objects
Function libraries are stored as midPoint objects, so anyone with permission to modify them can change logic that runs for every user. Limit edit rights on library objects to a small group of named administrators, separate from people who manage roles or users. Review the authorization roles that grant access to script-bearing objects, because a broad administrator role often includes them by default. Confirm which roles in your deployment can read and write function libraries before you grant delegated administration.
Current featuresCheck the privileges expressions run with
Expressions executed through a function library inherit the execution context of the object or task that calls them, so a shared function can reach data or operations the caller never intended. Map which tasks, object templates and mappings call each library function, and note any that run with elevated rights during synchronization. Ask whether a library function can be reached from a user-facing or self-service path, since that changes the risk considerably.
Choose the expression language with security in mind
Whether a library is written in Groovy or in the newer midPoint Expression Language (MEL) changes what code can do at runtime and how it is reviewed. Groovy offers broad capability, which also means broad risk when a script is edited carelessly. Decide the language before you build a large library, and compare the trade-offs on the separate Groovy versus MEL page. Migrating an existing Groovy library later means retesting every caller.
Audit every change to shared logic
A change to one shared function can alter provisioning for thousands of identities, so each edit should leave a trace of who changed it, when, and what the previous version contained. Confirm that midPoint audit logging captures changes to library objects in your deployment, and that the audit records are forwarded to a store your security team controls. Keep the change history alongside your configuration repository so reviewers can compare versions.
Review library code through a controlled path
Shared code should reach production through a review step, not directly through the administration interface. Route changes through version control and a second reviewer, then deploy the approved files to each environment. This limits the chance that an untested or unreviewed edit reaches the production identity stores. Pair this with the team practices described for configuration development so that the review is repeatable.
Confirm the security profile settings
midPoint offers configurable security profiles that govern how scripted expressions are allowed to run, and the available settings differ by release. Record the profile in effect for each environment, test that an unauthorized expression is refused, and document the result as evidence for your access control review. Confirm the exact setting names and defaults against the documentation for your midPoint version, since these settings change between releases.
midPoint releasesTesting shared functions before they reach production
A change to one shared function in a midPoint function library can alter the output of every mapping, expression and object template that calls it, so the test scope for a change should follow the number of dependent objects rather than the size of the edit. Before changing a function, list the expressions, templates and tasks that reference it. Most teams find this list is longer than they expected, and it becomes the checklist for what must be retested. Confirm how your team will produce that list, because the answer depends on your repository layout and on how your Studio or Git workflow exports objects.
Build a set of sample inputs for each function and include the edge cases that show up in real identity data: empty strings, missing attributes, duplicate values such as two people with the same surname and given name, and non-ASCII values such as accented names, names in non-Latin scripts and names with apostrophes or hyphens. For each input, record the expected output in a file kept under version control next to the library. Run the function against those inputs after every change and compare the results with the expected values. Where a function produces a username, an email address or a generated identifier, include cases that trigger the uniqueness logic so that collisions are caught before they reach a live resource.
Promote changes only after they have run in a separate environment that holds a representative copy of identity data, not only synthetic records. Watch the first reconciliation or recompute cycle closely, because a function can be correct in isolation and still produce unexpected values when it runs against accounts that were created years ago under different rules. Ask your team to confirm which test tooling, if any, is available in its environment, how test data is refreshed and who signs off on promotion. Keep the sign-off record with the change so that the next reviewer can see what was tested and against which inputs.
How shared functions connect to mappings and templates
The flow starts in a version-controlled function library, where changes are reviewed and then promoted to each environment. Inside an environment, mappings and object templates call the shared functions, and the results are applied to identities. A security profile check and a testing gate sit before promotion, so a function that fails either step never reaches the identities that depend on it.
Shared function changes pass review, security and testing gates before reaching identities.
Questions teams ask before reusing midPoint logic
What does a midPoint function library project cost and what drives the effort?
The cost is driven by how much repeated logic exists, how many mappings, object templates and expressions call it, and how much testing your environments need before a change reaches production. Work splits into discovery (inventorying duplicated scripts), design (choosing function names, parameters and folder layout), refactoring, testing and handover. Each part is one-time, but libraries also need recurring review whenever identity rules change. Ask any quote to list these phases separately, state which environments are covered and say whether the work includes documentation for your team.
How long does refactoring expressions into a shared library take?
Duration depends mainly on the number of expressions in scope, how much they differ from each other, and how many environments must be retested. A library built from a handful of near-identical scripts is a small change. A large estate with many copies of the same logic, each slightly different, needs an inventory and a decision on which variant becomes the standard before any code moves. No duration figure is supplied for this work, so ask for a phased plan tied to the expression inventory and the test scope.
What does the client team need to provide for a library refactor?
The work needs access to the midPoint configuration exported as files, a list of the environments that exist, and named owners who can approve changes to identity rules. It also needs test accounts or sample data in non-production systems and someone who knows the business meaning of each rule, such as how usernames or role assignments are supposed to behave. Without those owners, a refactor can preserve a rule that nobody can confirm is still correct.
Can an internal team build a midPoint function library without a partner?
Yes, a team with midPoint administration skills and Git experience can build a library, and this is often the right path for a small set of stable rules. The points to weigh are whether the team has time to inventory every expression, whether it has a test environment that mirrors production, and whether anyone has reviewed script security settings. A partner is most useful when the estate is large, the rules are inconsistent, or the team needs an independent review before the library is trusted.
How do midPoint upgrades affect shared function library code?
Upgrades can change the behavior of the midPoint features your library calls, so a library that worked on one release may need retesting on the next. Plan each midPoint upgrade to step through the supported versions listed in the release notes, and rerun your library tests at each step. Keep the library in version control with tagged releases so you can identify which library version ran in which environment. Confirm the exact upgrade path for your current release before scheduling changes.
How do we keep function library scripts secure and under review?
Treat every library function as code that can read and change identity data. Review which security profile the scripts run under, limit who can edit the library in Git, and require review before changes reach production. Check whether your midPoint version supports the expression language you plan to use, and confirm how script permissions are configured in your own environment. Record the review as evidence, since auditors will ask who approved each change to identity logic.
What does DeployOpen do in a function library engagement?
DeployOpen plans and builds the library under a written, fixed scope. Typical deliverables include an inventory of duplicated logic, a library structure stored as configuration files, tests for the shared functions, security profile settings and documentation for your team. Scope, deliverables and timelines are agreed in writing before work starts, and the quote follows from that scope. Ongoing upgrades and testing can be covered by a retainer if you want continuous support.
Does midPoint support subscriptions cover library work?
Evolveum's Product Support subscriptions cover resolving product bugs, with an 8x5 next-business-day or 24x7 SLA option, while Platform Subscriptions add feature development and roadmap influence. Neither is a substitute for designing your own function library, because support addresses product defects rather than your identity rules. Ask Evolveum which subscription fits your situation and confirm the current terms on their support subscriptions page before deciding.
Limits to confirm in your midPoint environment
Function library behavior depends on the midPoint version you run and on how each expression type loads code. The cards below list the points to verify against the vendor documentation and your own test environment before you commit a library design to production.
Expression types that call library functions
Confirm which expression types in your target version can call functions from a library. Mapping expressions, object template expressions, and expressions in custom tasks or policy rules may differ in what they can reference. Build one small test function and call it from every expression type your design needs, then record which ones succeed. A library that works in a mapping but fails in a policy rule is a common surprise when the logic is reused.
Current features docsHow libraries are loaded
Confirm how midPoint discovers and loads library code in your version: where the library object lives in the repository, how it is referenced, and whether changes take effect after an import or a restart. Check whether a library is loaded once per node or per expression evaluation, because that affects behavior in multi-node deployments with a sticky load balancer and shared database.
Version-specific expression languages
Confirm which scripting languages and expression engines your release supports for library code, and whether the functions behave the same across them. Expression language choices change between releases, so a library written for one version may need changes before it runs on another. Note the release you target and check the release notes before upgrading.
midPoint releasesJava runtime requirements
Confirm the Java version your target midPoint release requires, since library code that relies on newer language features or APIs may fail on an older runtime. Check the recommended and supported Java versions for your release, and test the library on the same runtime used in production, including any container image your team builds.
System requirementsSecurity restrictions on script code
Confirm which script-execution rules apply to library code in your release, including any sandboxing, restrictions on Java class access, and how script security profiles are applied. Library functions often call external classes or services, so a function that is allowed in one expression may be blocked elsewhere. Test each function under the security profile your production environment uses.
Behavior of library changes under upgrade
Confirm how a library change interacts with a planned upgrade, including whether existing objects are recomputed when the library changes and whether a rollback restores the earlier library text. Run a recompute test in a staging copy of production data before you change a shared function that drives many user or role assignments.
How DeployOpen scopes midPoint function library work
Function library work for midPoint starts with a written scope, not an open-ended hours estimate. DeployOpen plans and implements self-hosted open-source platforms inside the client's own infrastructure, so the first decision is which repeated expressions move into libraries, which stay inline in mappings and object templates, and which belong in a different place entirely. The agreed scope lists the libraries to be built, the expressions they replace, the environments they must work in, and the deliverables the client receives, such as the library files under version control, test cases, a security profile review and handover notes. Because the scope is fixed and written before work begins, the client can compare it directly with an in-house estimate and see exactly what a partner will and will not touch.
Most of the cost sits in the parts the client must confirm before a build starts: how many expressions repeat across mappings and templates, how much of the logic depends on source system data that has not been profiled, and whether the client already keeps midPoint configuration as files in Git or manages it through the GUI. Ask any partner to state which of these inputs its quote assumes. Support and upgrades can be handled separately under a retainer, which suits teams that will change libraries after each midPoint release. Confirm with the vendor and in your own environment which midPoint version you run before scoping, since library behavior and the tooling around it depend on that version.
Ask for the scope to name who maintains the libraries after handover and how changes are reviewed. DeployOpen does not hold certifications or partner status that would change this process, so the client should verify any credential claim directly with the vendor and with its own assessors. Use the written scope as the acceptance reference at the end of the engagement: each library should map to a named expression set, each test should map to a named behavior, and each deliverable should be checkable by the client's own engineers without DeployOpen present.

