Add onQueryResult script hook to filter managed object query results#139
Open
Add onQueryResult script hook to filter managed object query results#139
onQueryResult script hook to filter managed object query results#139Conversation
… results Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenIDM/sessions/f2c7d70c-33e3-4504-b613-171f30b93c52 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add onQueryResult script hook to ManagedObjectSet for filtering
Add Mar 26, 2026
onQueryResult script hook to filter managed object query results
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenIDM/sessions/e884c292-d30f-45c9-8f55-12b014bf2fd9 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenIDM/sessions/f590346a-e1fb-450d-a5bc-87fdf4875fdd Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
…iles Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenIDM/sessions/980c87aa-e675-45da-a77c-bbccb40d75ea Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ManagedObjectSetTest.java— already hadPortions copyright 2026 3A Systems, LLC.ManagedObjectSet.java— addedPortions copyright 2026 3A Systems, LLC.appendix-objects.adoc— updated toPortions Copyright 2024, 2026 3A Systems LLC.appendix-scripting.adoc— updated toPortions Copyright 2024-2026 3A Systems LLC.managed-user-on-query-result.json— new JSON file, no comment syntax possibleOriginal prompt
Context
Discussion #131 requests the ability to filter individual objects returned from a query on managed objects, similar to how
validSource/validTargetwork insync.jsonmappings. Currently, there is no way to include/exclude specific objects from query results based on custom scripted logic (e.g., access control based on the requester's attributes).What needs to be implemented
Add a new
onQueryResultscript hook to theManagedObjectSetclass inopenidm-core/src/main/java/org/forgerock/openidm/managed/ManagedObjectSet.java.Behaviour
queryCollection()method (lines ~1275–1309).object) plus standard bindings:context,request,resourceName.false(or a falsy value), the object is excluded from the result set and NOT passed tohandler.handleResource(...).true(or a truthy value, ornull— i.e., when no hook is configured), the object is included as normal.ex[0]and returnfalsefromhandleResource).Changes required
1.
ManagedObjectSet.javaFile:
openidm-core/src/main/java/org/forgerock/openidm/managed/ManagedObjectSet.javaonQueryResultto theScriptHookenum (afteronRetrieve, line ~150):queryCollection(), inside theQueryResourceHandler.handleResource()anonymous class, after theonRetrieveblock and before/after relationship population, invoke the new hook and skip the object if the result isBoolean.FALSE:This block should be inserted after the
onRetrieveblock and before the relationship population andhandler.handleResource(...)call.2. Documentation update
File:
openidm-doc/src/main/asciidoc/integrators-guide/appendix-objects.adocAdd documentation for the new
onQueryResulthook in the managed objects script hooks section, similar to howonRetrieveis documented.File:
openidm-doc/src/main/asciidoc/integrators-guide/appendix-scripting.adocAdd
onQueryResultto the script triggers table formanaged.json(the table that listsonCreate,onUpdate,onRetrieve, etc. with their available variables).Example configuration (
managed.json)After this change, users will be able to configure the hook like this:
{ "name": "user", "onQueryResult": { "type": "text/javascript", "source": "var requester = context.security.authenticationId; object.owner === requester || requester === 'admin';" } }The script has access to:
object— the managed object being evaluatedcontext— the current security/request contextrequest— the query requestReturn
trueto include the object in results,falseto exclude it.Files to change
openidm-core/src/main/java/org/forgerock/openidm/managed/ManagedObjectSet.javaopenidm-doc/src/main/asciidoc/integrators-guide/appendix-objects.adocopenidm-doc/src/main/asciidoc/integrators-guide/appendix-scripting.adocThe following is the prior conversation context from the user's chat exploration (may be truncated):
User: подготовь ответ и согласуй со мной
Assistant: Вот подготовленный ответ на дискуссию #131. Пожалуйста, проверьте и согласуйте:
Предлагаемый ответ на дискуссию:
Thank you for the suggestion! This is a valid use case — filtering query results per-requester based on access control logic, similar to how
validSource/validTargetwork in sync mappings.Current workaround options:
onRetrievescript hook — already available inmanaged.json, it runs for every object returned from a query (whenexecuteOnRetrieve=trueis passed). You can use it to modify the returned object (e.g., strip sensitive fields), but it cannot currently exclude an object from the result set — throwing an exception there would fail the entire query.Router filter (
router.json) — you can intercept query responses viaonResponsehook inconf/router.jsonand post-process the result list, filtering out objec...This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.