samlesa 2.12.3 → 2.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of samlesa might be problematic. Click here for more details.
- package/build/.idea/workspace.xml +13 -1
- package/build/index.js +54 -64
- package/build/index.js.map +1 -1
- package/build/src/api.js +24 -23
- package/build/src/api.js.map +1 -1
- package/build/src/binding-post.js +358 -368
- package/build/src/binding-post.js.map +1 -1
- package/build/src/binding-redirect.js +333 -332
- package/build/src/binding-redirect.js.map +1 -1
- package/build/src/binding-simplesign.js +222 -232
- package/build/src/binding-simplesign.js.map +1 -1
- package/build/src/entity-idp.js +130 -130
- package/build/src/entity-idp.js.map +1 -1
- package/build/src/entity-sp.js +96 -96
- package/build/src/entity-sp.js.map +1 -1
- package/build/src/entity.js +225 -235
- package/build/src/entity.js.map +1 -1
- package/build/src/extractor.js +385 -369
- package/build/src/extractor.js.map +1 -1
- package/build/src/flow.js +320 -319
- package/build/src/flow.js.map +1 -1
- package/build/src/libsaml.js +665 -641
- package/build/src/libsaml.js.map +1 -1
- package/build/src/metadata-idp.js +127 -127
- package/build/src/metadata-idp.js.map +1 -1
- package/build/src/metadata-sp.js +231 -231
- package/build/src/metadata-sp.js.map +1 -1
- package/build/src/metadata.js +166 -176
- package/build/src/metadata.js.map +1 -1
- package/build/src/types.js +11 -11
- package/build/src/urn.js +212 -212
- package/build/src/urn.js.map +1 -1
- package/build/src/utility.js +292 -248
- package/build/src/utility.js.map +1 -1
- package/build/src/validator.js +27 -26
- package/build/src/validator.js.map +1 -1
- package/package.json +8 -10
- package/src/api.ts +1 -1
- package/src/binding-redirect.ts +83 -64
- package/src/extractor.ts +23 -5
- package/src/libsaml.ts +95 -62
- package/src/utility.ts +147 -76
- package/types/index.d.ts +10 -10
- package/types/src/api.d.ts +13 -13
- package/types/src/binding-post.d.ts +46 -46
- package/types/src/binding-redirect.d.ts +52 -52
- package/types/src/binding-simplesign.d.ts +39 -39
- package/types/src/entity-idp.d.ts +42 -42
- package/types/src/entity-sp.d.ts +36 -36
- package/types/src/entity.d.ts +101 -99
- package/types/src/extractor.d.ts +25 -25
- package/types/src/flow.d.ts +6 -6
- package/types/src/libsaml.d.ts +200 -210
- package/types/src/metadata-idp.d.ts +24 -24
- package/types/src/metadata-sp.d.ts +36 -36
- package/types/src/metadata.d.ts +59 -57
- package/types/src/types.d.ts +129 -127
- package/types/src/urn.d.ts +194 -194
- package/types/src/utility.d.ts +134 -134
- package/types/src/validator.d.ts +3 -3
package/build/src/extractor.js
CHANGED
|
@@ -1,370 +1,386 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.logoutResponseFields = exports.logoutRequestFields = exports.loginResponseFields = exports.logoutResponseStatusFields = exports.loginResponseStatusFields = exports.loginRequestFields = void 0;
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
exports.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
['Response', 'Issuer']
|
|
213
|
-
|
|
214
|
-
]
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
[key]: (0, utility_js_1.uniq)((0, xpath_1.select)(multiXPaths, targetDoc).map((n) => n.nodeValue).filter(utility_js_1.notEmpty))
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
// eo special case: multiple path
|
|
231
|
-
const baseXPath = buildAbsoluteXPath(localPath);
|
|
232
|
-
const attributeXPath = buildAttributeXPath(attributes);
|
|
233
|
-
// special case: get attributes where some are in child, some are in parent
|
|
234
|
-
/*
|
|
235
|
-
{
|
|
236
|
-
key: 'attributes',
|
|
237
|
-
localPath: ['Response', 'Assertion', 'AttributeStatement', 'Attribute'],
|
|
238
|
-
index: ['Name'],
|
|
239
|
-
attributePath: ['AttributeValue'],
|
|
240
|
-
attributes: []
|
|
241
|
-
}
|
|
242
|
-
*/
|
|
243
|
-
if (index && attributePath) {
|
|
244
|
-
// find the index in localpath
|
|
245
|
-
const indexPath = buildAttributeXPath(index);
|
|
246
|
-
const fullLocalXPath = `${baseXPath}${indexPath}`;
|
|
247
|
-
const parentNodes = (0, xpath_1.select)(baseXPath, targetDoc);
|
|
248
|
-
// [uid, mail, edupersonaffiliation], ready for aggregate
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extract = exports.logoutResponseFields = exports.logoutRequestFields = exports.loginResponseFields = exports.logoutResponseStatusFields = exports.loginResponseStatusFields = exports.loginRequestFields = void 0;
|
|
7
|
+
const xpath_1 = require("xpath");
|
|
8
|
+
const utility_js_1 = require("./utility.js");
|
|
9
|
+
const api_js_1 = require("./api.js");
|
|
10
|
+
const camelcase_1 = __importDefault(require("camelcase"));
|
|
11
|
+
function buildAbsoluteXPath(paths) {
|
|
12
|
+
return paths.reduce((currentPath, name) => {
|
|
13
|
+
let appendedPath = currentPath;
|
|
14
|
+
const isWildcard = name.startsWith('~');
|
|
15
|
+
if (isWildcard) {
|
|
16
|
+
const pathName = name.replace('~', '');
|
|
17
|
+
appendedPath = currentPath + `/*[contains(local-name(), '${pathName}')]`;
|
|
18
|
+
}
|
|
19
|
+
if (!isWildcard) {
|
|
20
|
+
appendedPath = currentPath + `/*[local-name(.)='${name}']`;
|
|
21
|
+
}
|
|
22
|
+
return appendedPath;
|
|
23
|
+
}, '');
|
|
24
|
+
}
|
|
25
|
+
function buildAttributeXPath(attributes) {
|
|
26
|
+
if (attributes.length === 0) {
|
|
27
|
+
return '/text()';
|
|
28
|
+
}
|
|
29
|
+
if (attributes.length === 1) {
|
|
30
|
+
return `/@${attributes[0]}`;
|
|
31
|
+
}
|
|
32
|
+
const filters = attributes.map(attribute => `name()='${attribute}'`).join(' or ');
|
|
33
|
+
return `/@*[${filters}]`;
|
|
34
|
+
}
|
|
35
|
+
exports.loginRequestFields = [
|
|
36
|
+
{
|
|
37
|
+
key: 'request',
|
|
38
|
+
localPath: ['AuthnRequest'],
|
|
39
|
+
attributes: ['ID', 'IssueInstant', 'Destination', 'AssertionConsumerServiceURL']
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: 'issuer',
|
|
43
|
+
localPath: ['AuthnRequest', 'Issuer'],
|
|
44
|
+
attributes: []
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
key: 'nameIDPolicy',
|
|
48
|
+
localPath: ['AuthnRequest', 'NameIDPolicy'],
|
|
49
|
+
attributes: ['Format', 'AllowCreate']
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: 'authnContextClassRef',
|
|
53
|
+
localPath: ['AuthnRequest', 'AuthnContextClassRef'],
|
|
54
|
+
attributes: []
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
key: 'signature',
|
|
58
|
+
localPath: ['AuthnRequest', 'Signature'],
|
|
59
|
+
attributes: [],
|
|
60
|
+
context: true
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
// support two-tiers status code
|
|
64
|
+
exports.loginResponseStatusFields = [
|
|
65
|
+
{
|
|
66
|
+
key: 'top',
|
|
67
|
+
localPath: ['Response', 'Status', 'StatusCode'],
|
|
68
|
+
attributes: ['Value'],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
key: 'second',
|
|
72
|
+
localPath: ['Response', 'Status', 'StatusCode', 'StatusCode'],
|
|
73
|
+
attributes: ['Value'],
|
|
74
|
+
}
|
|
75
|
+
];
|
|
76
|
+
// support two-tiers status code
|
|
77
|
+
exports.logoutResponseStatusFields = [
|
|
78
|
+
{
|
|
79
|
+
key: 'top',
|
|
80
|
+
localPath: ['LogoutResponse', 'Status', 'StatusCode'],
|
|
81
|
+
attributes: ['Value']
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
key: 'second',
|
|
85
|
+
localPath: ['LogoutResponse', 'Status', 'StatusCode', 'StatusCode'],
|
|
86
|
+
attributes: ['Value'],
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
const loginResponseFields = assertion => [
|
|
90
|
+
{
|
|
91
|
+
key: 'conditions',
|
|
92
|
+
localPath: ['Assertion', 'Conditions'],
|
|
93
|
+
attributes: ['NotBefore', 'NotOnOrAfter'],
|
|
94
|
+
shortcut: assertion
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
key: 'response',
|
|
98
|
+
localPath: ['Response'],
|
|
99
|
+
attributes: ['ID', 'IssueInstant', 'Destination', 'InResponseTo'],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
key: 'audience',
|
|
103
|
+
localPath: ['Assertion', 'Conditions', 'AudienceRestriction', 'Audience'],
|
|
104
|
+
attributes: [],
|
|
105
|
+
shortcut: assertion
|
|
106
|
+
},
|
|
107
|
+
// {
|
|
108
|
+
// key: 'issuer',
|
|
109
|
+
// localPath: ['Response', 'Issuer'],
|
|
110
|
+
// attributes: []
|
|
111
|
+
// },
|
|
112
|
+
{
|
|
113
|
+
key: 'issuer',
|
|
114
|
+
localPath: ['Assertion', 'Issuer'],
|
|
115
|
+
attributes: [],
|
|
116
|
+
shortcut: assertion
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
key: 'nameID',
|
|
120
|
+
localPath: ['Assertion', 'Subject', 'NameID'],
|
|
121
|
+
attributes: [],
|
|
122
|
+
shortcut: assertion
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
key: 'sessionIndex',
|
|
126
|
+
localPath: ['Assertion', 'AuthnStatement'],
|
|
127
|
+
attributes: ['AuthnInstant', 'SessionNotOnOrAfter', 'SessionIndex'],
|
|
128
|
+
shortcut: assertion
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
key: 'attributes',
|
|
132
|
+
localPath: ['Assertion', 'AttributeStatement', 'Attribute'],
|
|
133
|
+
index: ['Name'],
|
|
134
|
+
attributePath: ['AttributeValue'],
|
|
135
|
+
attributes: [],
|
|
136
|
+
shortcut: assertion
|
|
137
|
+
}
|
|
138
|
+
];
|
|
139
|
+
exports.loginResponseFields = loginResponseFields;
|
|
140
|
+
exports.logoutRequestFields = [
|
|
141
|
+
{
|
|
142
|
+
key: 'request',
|
|
143
|
+
localPath: ['LogoutRequest'],
|
|
144
|
+
attributes: ['ID', 'IssueInstant', 'Destination']
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
key: 'issuer',
|
|
148
|
+
localPath: ['LogoutRequest', 'Issuer'],
|
|
149
|
+
attributes: []
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
key: 'nameID',
|
|
153
|
+
localPath: ['LogoutRequest', 'NameID'],
|
|
154
|
+
attributes: []
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
key: 'sessionIndex',
|
|
158
|
+
localPath: ['LogoutRequest', 'SessionIndex'],
|
|
159
|
+
attributes: []
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
key: 'signature',
|
|
163
|
+
localPath: ['LogoutRequest', 'Signature'],
|
|
164
|
+
attributes: [],
|
|
165
|
+
context: true
|
|
166
|
+
}
|
|
167
|
+
];
|
|
168
|
+
exports.logoutResponseFields = [
|
|
169
|
+
{
|
|
170
|
+
key: 'response',
|
|
171
|
+
localPath: ['LogoutResponse'],
|
|
172
|
+
attributes: ['ID', 'Destination', 'InResponseTo']
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
key: 'issuer',
|
|
176
|
+
localPath: ['LogoutResponse', 'Issuer'],
|
|
177
|
+
attributes: []
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
key: 'signature',
|
|
181
|
+
localPath: ['LogoutResponse', 'Signature'],
|
|
182
|
+
attributes: [],
|
|
183
|
+
context: true
|
|
184
|
+
}
|
|
185
|
+
];
|
|
186
|
+
function extract(context, fields) {
|
|
187
|
+
const { dom } = (0, api_js_1.getContext)();
|
|
188
|
+
const rootDoc = dom.parseFromString(context, 'application/xml');
|
|
189
|
+
return fields.reduce((result, field) => {
|
|
190
|
+
// get essential fields
|
|
191
|
+
const key = field.key;
|
|
192
|
+
const localPath = field.localPath;
|
|
193
|
+
const attributes = field.attributes;
|
|
194
|
+
const isEntire = field.context;
|
|
195
|
+
const shortcut = field.shortcut;
|
|
196
|
+
// get optional fields
|
|
197
|
+
const index = field.index;
|
|
198
|
+
const attributePath = field.attributePath;
|
|
199
|
+
// set allowing overriding if there is a shortcut injected
|
|
200
|
+
let targetDoc = rootDoc;
|
|
201
|
+
// if shortcut is used, then replace the doc
|
|
202
|
+
// it's a design for overriding the doc used during runtime
|
|
203
|
+
if (shortcut) {
|
|
204
|
+
targetDoc = dom.parseFromString(shortcut, 'application/xml');
|
|
205
|
+
}
|
|
206
|
+
// special case: multiple path
|
|
207
|
+
/*
|
|
208
|
+
{
|
|
209
|
+
key: 'issuer',
|
|
210
|
+
localPath: [
|
|
211
|
+
['Response', 'Issuer'],
|
|
212
|
+
['Response', 'Assertion', 'Issuer']
|
|
213
|
+
],
|
|
214
|
+
attributes: []
|
|
215
|
+
}
|
|
216
|
+
*/
|
|
217
|
+
if (localPath.every(path => Array.isArray(path))) {
|
|
218
|
+
const multiXPaths = localPath
|
|
219
|
+
.map(path => {
|
|
220
|
+
// not support attribute yet, so ignore it
|
|
221
|
+
return `${buildAbsoluteXPath(path)}/text()`;
|
|
222
|
+
})
|
|
223
|
+
.join(' | ');
|
|
224
|
+
return {
|
|
225
|
+
...result,
|
|
226
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
227
|
+
[key]: (0, utility_js_1.uniq)((0, xpath_1.select)(multiXPaths, targetDoc).map((n) => n.nodeValue).filter(utility_js_1.notEmpty))
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
// eo special case: multiple path
|
|
231
|
+
const baseXPath = buildAbsoluteXPath(localPath);
|
|
232
|
+
const attributeXPath = buildAttributeXPath(attributes);
|
|
233
|
+
// special case: get attributes where some are in child, some are in parent
|
|
234
|
+
/*
|
|
235
|
+
{
|
|
236
|
+
key: 'attributes',
|
|
237
|
+
localPath: ['Response', 'Assertion', 'AttributeStatement', 'Attribute'],
|
|
238
|
+
index: ['Name'],
|
|
239
|
+
attributePath: ['AttributeValue'],
|
|
240
|
+
attributes: []
|
|
241
|
+
}
|
|
242
|
+
*/
|
|
243
|
+
if (index && attributePath) {
|
|
244
|
+
// find the index in localpath
|
|
245
|
+
const indexPath = buildAttributeXPath(index);
|
|
246
|
+
const fullLocalXPath = `${baseXPath}${indexPath}`;
|
|
247
|
+
const parentNodes = (0, xpath_1.select)(baseXPath, targetDoc);
|
|
248
|
+
// [uid, mail, edupersonaffiliation], ready for aggregate
|
|
249
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
250
|
+
const parentAttributes = (0, xpath_1.select)(fullLocalXPath, targetDoc).map((n) => n.value);
|
|
251
|
+
// [attribute, attributevalue]
|
|
252
|
+
const childXPath = buildAbsoluteXPath([(0, utility_js_1.last)(localPath)].concat(attributePath));
|
|
253
|
+
const childAttributeXPath = buildAttributeXPath(attributes);
|
|
254
|
+
const fullChildXPath = `${childXPath}${childAttributeXPath}`;
|
|
255
|
+
// [ 'test', 'test@example.com', [ 'users', 'examplerole1' ] ]
|
|
256
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
257
|
+
const childAttributes = parentNodes.map(node => {
|
|
258
|
+
const nodeDoc = dom.parseFromString(node.toString(), 'application/xml');
|
|
259
|
+
if (attributes.length === 0) {
|
|
260
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
261
|
+
const childValues = (0, xpath_1.select)(fullChildXPath, nodeDoc).map((n) => n.nodeValue);
|
|
262
|
+
if (childValues.length === 1) {
|
|
263
|
+
return childValues[0];
|
|
264
|
+
}
|
|
265
|
+
return childValues;
|
|
266
|
+
}
|
|
267
|
+
if (attributes.length > 0) {
|
|
268
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
269
|
+
const childValues = (0, xpath_1.select)(fullChildXPath, nodeDoc).map((n) => n.value);
|
|
270
|
+
if (childValues.length === 1) {
|
|
271
|
+
return childValues[0];
|
|
272
|
+
}
|
|
273
|
+
return childValues;
|
|
274
|
+
}
|
|
275
|
+
return null;
|
|
276
|
+
});
|
|
277
|
+
// aggregation
|
|
278
|
+
const obj = (0, utility_js_1.zipObject)(parentAttributes, childAttributes, false);
|
|
279
|
+
return {
|
|
280
|
+
...result,
|
|
281
|
+
[key]: obj
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
// case: fetch entire content, only allow one existence
|
|
285
|
+
/*
|
|
286
|
+
{
|
|
287
|
+
key: 'signature',
|
|
288
|
+
localPath: ['AuthnRequest', 'Signature'],
|
|
289
|
+
attributes: [],
|
|
290
|
+
context: true
|
|
291
|
+
}
|
|
292
|
+
*/
|
|
293
|
+
if (isEntire) {
|
|
294
|
+
const node = (0, xpath_1.select)(baseXPath, targetDoc);
|
|
295
|
+
let value = null;
|
|
296
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
297
|
+
if (node.length === 1) {
|
|
298
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
299
|
+
value = node[0].toString();
|
|
300
|
+
}
|
|
301
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
302
|
+
if (node.length > 1) {
|
|
303
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
304
|
+
value = node.map(n => n.toString());
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
...result,
|
|
308
|
+
[key]: value
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
// case: multiple attribute
|
|
312
|
+
/*
|
|
313
|
+
{
|
|
314
|
+
key: 'nameIDPolicy',
|
|
315
|
+
localPath: ['AuthnRequest', 'NameIDPolicy'],
|
|
316
|
+
attributes: ['Format', 'AllowCreate']
|
|
317
|
+
}
|
|
318
|
+
*/
|
|
319
|
+
if (attributes.length > 1) {
|
|
320
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
321
|
+
const baseNode = (0, xpath_1.select)(baseXPath, targetDoc).map(n => n.toString());
|
|
322
|
+
const childXPath = `${buildAbsoluteXPath([(0, utility_js_1.last)(localPath)])}${attributeXPath}`;
|
|
323
|
+
const attributeValues = baseNode.map((node) => {
|
|
324
|
+
const nodeDoc = dom.parseFromString(node, 'application/xml');
|
|
325
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
326
|
+
const values = (0, xpath_1.select)(childXPath, nodeDoc).reduce((r, n) => {
|
|
327
|
+
r[(0, camelcase_1.default)(n.name, { locale: 'en-us' })] = n.value;
|
|
328
|
+
return r;
|
|
329
|
+
}, {});
|
|
330
|
+
return values;
|
|
331
|
+
});
|
|
332
|
+
return {
|
|
333
|
+
...result,
|
|
334
|
+
[key]: attributeValues.length === 1 ? attributeValues[0] : attributeValues
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
// case: single attribute
|
|
338
|
+
/*
|
|
339
|
+
{
|
|
340
|
+
key: 'statusCode',
|
|
341
|
+
localPath: ['Response', 'Status', 'StatusCode'],
|
|
342
|
+
attributes: ['Value'],
|
|
343
|
+
}
|
|
344
|
+
*/
|
|
345
|
+
if (attributes.length === 1) {
|
|
346
|
+
const fullPath = `${baseXPath}${attributeXPath}`;
|
|
347
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
348
|
+
const attributeValues = (0, xpath_1.select)(fullPath, targetDoc).map((n) => n.value);
|
|
349
|
+
return {
|
|
350
|
+
...result,
|
|
351
|
+
[key]: attributeValues[0]
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
// case: zero attribute
|
|
355
|
+
/*
|
|
356
|
+
{
|
|
357
|
+
key: 'issuer',
|
|
358
|
+
localPath: ['AuthnRequest', 'Issuer'],
|
|
359
|
+
attributes: []
|
|
360
|
+
}
|
|
361
|
+
*/
|
|
362
|
+
if (attributes.length === 0) {
|
|
363
|
+
let attributeValue = null;
|
|
364
|
+
const node = (0, xpath_1.select)(baseXPath, targetDoc);
|
|
365
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
366
|
+
if (node.length === 1) {
|
|
367
|
+
const fullPath = `string(${baseXPath}${attributeXPath})`;
|
|
368
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
369
|
+
attributeValue = (0, xpath_1.select)(fullPath, targetDoc);
|
|
370
|
+
}
|
|
371
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
372
|
+
if (node.length > 1) {
|
|
373
|
+
// @ts-expect-error misssing Node properties are not needed
|
|
374
|
+
attributeValue = node.filter((n) => n.firstChild)
|
|
375
|
+
.map((n) => n.firstChild.nodeValue);
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
...result,
|
|
379
|
+
[key]: attributeValue
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
return result;
|
|
383
|
+
}, {});
|
|
384
|
+
}
|
|
385
|
+
exports.extract = extract;
|
|
370
386
|
//# sourceMappingURL=extractor.js.map
|