Skip to content

Commit d7bd51f

Browse files
authored
Fix Property mapping /authzRoles transformation script encountered exception javax.script.ScriptException: Script status is 8 (#181)
1 parent 11934f6 commit d7bd51f

3 files changed

Lines changed: 78 additions & 2 deletions

File tree

openidm-zip/src/main/resources/samples/workflow/conf/sync.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"source" : "roles",
9090
"transform" : {
9191
"type" : "text/javascript",
92-
"source" : "source.split(',').map(function (r) { return {'_ref' : (r.indexOf('openidm-') === 0 ? 'repo/internal/role/' : 'managed/role/') + r }; })"
92+
"file" : "script/rolesToAuthzRoles.js"
9393
},
9494
"target" : "authzRoles"
9595
},
@@ -216,7 +216,7 @@
216216
"source" : "",
217217
"transform" : {
218218
"type" : "text/javascript",
219-
"source" : "openidm.query('managed/user/' + source._id + '/authzRoles', {'_queryFilter': 'true'}).result.map(function (r) { return r._ref.split('/').pop(); } ).join(',')"
219+
"file" : "script/authzRolesToRoles.js"
220220
},
221221
"target" : "roles"
222222
},
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* The contents of this file are subject to the terms of the Common Development and
3+
* Distribution License (the License). You may not use this file except in compliance with the
4+
* License.
5+
*
6+
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7+
* specific language governing permission and limitations under the License.
8+
*
9+
* When distributing Covered Software, include this CDDL Header Notice in each file and include
10+
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11+
* Header, with the fields enclosed by brackets [] replaced by your own identifying
12+
* information: "Portions copyright [year] [name of copyright owner]".
13+
*
14+
* Copyright 2026 3A Systems, LLC.
15+
*/
16+
/*global source, openidm */
17+
// Flatten the managed/user authzRoles relationship into the comma-separated
18+
// "roles" attribute consumed by the XML connector.
19+
//
20+
// File-based (vs inline in sync.json) for the same race-condition reason
21+
// documented in rolesToAuthzRoles.js: avoids ScriptRegistry STARTING-state
22+
// ("Script status is 8") errors during the first reconciliation after boot.
23+
(function () {
24+
if (source === null || source === undefined || source._id === null || source._id === undefined) {
25+
return "";
26+
}
27+
var result = openidm.query(
28+
'managed/user/' + source._id + '/authzRoles',
29+
{'_queryFilter': 'true'}
30+
);
31+
if (!result || !result.result) {
32+
return "";
33+
}
34+
return result.result.map(function (r) {
35+
return r._ref.split('/').pop();
36+
}).join(',');
37+
}());
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* The contents of this file are subject to the terms of the Common Development and
3+
* Distribution License (the License). You may not use this file except in compliance with the
4+
* License.
5+
*
6+
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7+
* specific language governing permission and limitations under the License.
8+
*
9+
* When distributing Covered Software, include this CDDL Header Notice in each file and include
10+
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11+
* Header, with the fields enclosed by brackets [] replaced by your own identifying
12+
* information: "Portions copyright [year] [name of copyright owner]".
13+
*
14+
* Copyright 2026 3A Systems, LLC.
15+
*/
16+
17+
/*global source */
18+
19+
// Transform a comma-separated XML "roles" attribute into the array form
20+
// expected by the managed/user "authzRoles" relationship.
21+
//
22+
// Lives in a separate file (rather than as an inline transform inside
23+
// sync.json) so the script is registered through the file-based code path of
24+
// ScriptRegistry. Inline scripts embedded in mapping configs can be invoked
25+
// during the very first reconciliation while the registry is still moving the
26+
// freshly compiled script from STARTING (status=8) to ACTIVE (status=32),
27+
// producing a transient "Script status is 8" ScriptException that gets
28+
// flagged by the strict CI log scan.
29+
(function () {
30+
if (source === null || source === undefined || String(source).length === 0) {
31+
return [];
32+
}
33+
return String(source).split(',').map(function (r) {
34+
return {
35+
"_ref": (r.indexOf('openidm-') === 0 ? 'repo/internal/role/' : 'managed/role/') + r
36+
};
37+
});
38+
}());
39+

0 commit comments

Comments
 (0)