Production-ready JavaScript and Groovy scripts for ForgeRock Access Management (AM) Scripted Decision Nodes. Full tutorials at IAMDevBox.com →
This repository provides a library of production-grade Scripted Decision Node scripts for ForgeRock Access Management 7.x authentication trees. Each script is tested, includes error handling, logging, and detailed comments explaining the ForgeRock-specific APIs.
| Script | Language | Purpose |
|---|---|---|
scripts/risk-based-auth.js |
JavaScript | Risk score evaluation — allow/step-up/deny |
scripts/device-fingerprint.js |
JavaScript | Browser fingerprint collection & comparison |
scripts/ldap-group-check.groovy |
Groovy | LDAP group membership → route to outcome |
scripts/custom-attribute-collector.js |
JavaScript | Collect custom attributes into sharedState |
scripts/jwt-validator.js |
JavaScript | Validate and decode external JWT in tree |
scripts/http-api-call.js |
JavaScript | REST API call with retries and error handling |
scripts/mfa-bypass-check.js |
JavaScript | Conditional MFA bypass based on trusted IPs |
scripts/audit-logger.js |
JavaScript | Structured audit event logging to AM log |
tests/ |
Jest | Unit tests for all JavaScript scripts |
docker-compose.yml |
YAML | ForgeRock AM 7.x dev environment |
- ForgeRock AM 7.0+ (or PingOne Advanced Identity Cloud)
- Java 11+
- Docker & Docker Compose (for dev environment)
- Node.js 18+ (for running unit tests)
git clone https://github.com/IAMDevBox/forgerock-am-scripted-decisions.git
cd forgerock-am-scripted-decisionsdocker-compose up -d
# ForgeRock AM will be available at http://localhost:8080/openam
# Default credentials: amadmin / password- Navigate to Realm → Scripts → New Script
- Set Script Type to
Decision node script for authentication trees - Paste the contents of the desired script file
- Click Save
- Navigate to Realm → Authentication → Trees
- Create or edit a tree
- Drag the Scripted Decision node onto the canvas
- Select your script from the dropdown
- Wire the
true/falseoutcomes
Evaluates risk factors from sharedState and routes the user to low, medium, or high outcomes.
Inputs from sharedState:
riskScore(Number, 0-100) — pre-calculated risk scoreuserAgent(String) — browser user agent stringgeoCountry(String) — ISO country code from IP geolocation
Outcomes: low | medium | high
Usage: Place after an IP Risk node or custom risk scoring node.
// Thresholds are configurable at the top of the script
var LOW_RISK_THRESHOLD = 30;
var HIGH_RISK_THRESHOLD = 70;Collects browser attributes into sharedState on first login, then compares on subsequent logins to detect new or suspicious devices.
Outcomes: recognized | new_device | suspicious
For the full tutorial on this pattern, see: Custom Callback Usage and Extension Techniques in ForgeRock AM
Checks if the authenticated user is a member of a specific LDAP group using the ForgeRock idRepository API. Routes to member or not_member.
Configuration (at top of script):
def TARGET_GROUP_DN = "cn=admins,ou=groups,dc=example,dc=com"
def LDAP_ATTRIBUTE = "isMemberOf"For advanced LDAP patterns, see: Keycloak LDAP User Federation Guide
Makes an authenticated REST API call from within a Scripted Decision Node. Includes timeout, retry with exponential backoff, and structured error handling.
Note: ForgeRock AM scripts run in a restricted
javax.scriptsandbox. HTTP calls use thehttpClientprovided by the ForgeRock scripting context — not Node.jsfetch.
// Configure at top of script
var API_ENDPOINT = "https://api.example.com/v1/risk/evaluate";
var API_TIMEOUT_MS = 3000;
var MAX_RETRIES = 2;Writes structured JSON audit events to the AM audit log. Use this to track authentication decisions, policy evaluations, or fraud signals.
// Output format (AM debug log):
// {"event":"SCRIPTED_DECISION","user":"jsmith","outcome":"high_risk","ts":"2026-03-24T10:00:00Z"}For AM logging configuration, see: Deep Dive: ForgeRock AM Scripted Decision Node Debugging
npm install
npm testTests use Jest with a mock for ForgeRock's sharedState, transientState, idRepository, and httpClient APIs.
| Object | Type | Description |
|---|---|---|
sharedState |
Map |
Persistent across nodes in the same tree session |
transientState |
Map |
Cleared after session; use for secrets |
idRepository |
IdRepository |
Read/write user profile attributes |
httpClient |
HttpClient |
Make external HTTP calls |
logger |
Logger |
Write to AM debug/audit logs |
outcome |
String |
Set to one of the configured outcomes |
callbacks |
Callbacks |
Access callback values from the request |
- Deep Dive: Scripted Decision Node Debugging & Best Practices
- Custom Callback Usage and Extension Techniques in ForgeRock AM
- ForgeRock AM Script Customization: A Practical Guide
- IAM Tools Comparison: Keycloak vs ForgeRock vs Okta
- Browse All ForgeRock Tutorials →
MIT — see LICENSE