samlesa 2.12.3 → 2.12.6
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/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 +132 -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 +369 -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 +660 -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/index.d.ts +10 -10
- package/index.js +18 -18
- package/package.json +1 -5
- package/qodana.yaml +29 -29
- package/src/binding-post.ts +1 -1
- package/src/binding-redirect.ts +83 -64
- package/src/entity-idp.ts +26 -20
- package/src/libsaml.ts +79 -48
- 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 +35 -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/.idea/compiler.xml +0 -6
- package/.idea/deployment.xml +0 -14
- package/.idea/jsLibraryMappings.xml +0 -6
- package/build/.idea/workspace.xml +0 -58
package/build/src/extractor.js
CHANGED
|
@@ -1,370 +1,370 @@
|
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const
|
|
252
|
-
const
|
|
253
|
-
|
|
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
|
-
const
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
r
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const
|
|
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);
|
|
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);
|
|
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
|
+
[key]: (0, utility_js_1.uniq)((0, xpath_1.select)(multiXPaths, targetDoc).map((n) => n.nodeValue).filter(utility_js_1.notEmpty))
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
// eo special case: multiple path
|
|
230
|
+
const baseXPath = buildAbsoluteXPath(localPath);
|
|
231
|
+
const attributeXPath = buildAttributeXPath(attributes);
|
|
232
|
+
// special case: get attributes where some are in child, some are in parent
|
|
233
|
+
/*
|
|
234
|
+
{
|
|
235
|
+
key: 'attributes',
|
|
236
|
+
localPath: ['Response', 'Assertion', 'AttributeStatement', 'Attribute'],
|
|
237
|
+
index: ['Name'],
|
|
238
|
+
attributePath: ['AttributeValue'],
|
|
239
|
+
attributes: []
|
|
240
|
+
}
|
|
241
|
+
*/
|
|
242
|
+
if (index && attributePath) {
|
|
243
|
+
// find the index in localpath
|
|
244
|
+
const indexPath = buildAttributeXPath(index);
|
|
245
|
+
const fullLocalXPath = `${baseXPath}${indexPath}`;
|
|
246
|
+
const parentNodes = (0, xpath_1.select)(baseXPath, targetDoc);
|
|
247
|
+
// [uid, mail, edupersonaffiliation], ready for aggregate
|
|
248
|
+
const parentAttributes = (0, xpath_1.select)(fullLocalXPath, targetDoc).map((n) => n.value);
|
|
249
|
+
// [attribute, attributevalue]
|
|
250
|
+
const childXPath = buildAbsoluteXPath([(0, utility_js_1.last)(localPath)].concat(attributePath));
|
|
251
|
+
const childAttributeXPath = buildAttributeXPath(attributes);
|
|
252
|
+
const fullChildXPath = `${childXPath}${childAttributeXPath}`;
|
|
253
|
+
// [ 'test', 'test@example.com', [ 'users', 'examplerole1' ] ]
|
|
254
|
+
const childAttributes = parentNodes.map(node => {
|
|
255
|
+
const nodeDoc = dom.parseFromString(node.toString());
|
|
256
|
+
if (attributes.length === 0) {
|
|
257
|
+
const childValues = (0, xpath_1.select)(fullChildXPath, nodeDoc).map((n) => n.nodeValue);
|
|
258
|
+
if (childValues.length === 1) {
|
|
259
|
+
return childValues[0];
|
|
260
|
+
}
|
|
261
|
+
return childValues;
|
|
262
|
+
}
|
|
263
|
+
if (attributes.length > 0) {
|
|
264
|
+
const childValues = (0, xpath_1.select)(fullChildXPath, nodeDoc).map((n) => n.value);
|
|
265
|
+
if (childValues.length === 1) {
|
|
266
|
+
return childValues[0];
|
|
267
|
+
}
|
|
268
|
+
return childValues;
|
|
269
|
+
}
|
|
270
|
+
return null;
|
|
271
|
+
});
|
|
272
|
+
// aggregation
|
|
273
|
+
const obj = (0, utility_js_1.zipObject)(parentAttributes, childAttributes, false);
|
|
274
|
+
return {
|
|
275
|
+
...result,
|
|
276
|
+
[key]: obj
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
// case: fetch entire content, only allow one existence
|
|
280
|
+
/*
|
|
281
|
+
{
|
|
282
|
+
key: 'signature',
|
|
283
|
+
localPath: ['AuthnRequest', 'Signature'],
|
|
284
|
+
attributes: [],
|
|
285
|
+
context: true
|
|
286
|
+
}
|
|
287
|
+
*/
|
|
288
|
+
if (isEntire) {
|
|
289
|
+
const node = (0, xpath_1.select)(baseXPath, targetDoc);
|
|
290
|
+
let value = null;
|
|
291
|
+
if (node.length === 1) {
|
|
292
|
+
value = node[0].toString();
|
|
293
|
+
}
|
|
294
|
+
if (node.length > 1) {
|
|
295
|
+
value = node.map(n => n.toString());
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
...result,
|
|
299
|
+
[key]: value
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
// case: multiple attribute
|
|
303
|
+
/*
|
|
304
|
+
{
|
|
305
|
+
key: 'nameIDPolicy',
|
|
306
|
+
localPath: ['AuthnRequest', 'NameIDPolicy'],
|
|
307
|
+
attributes: ['Format', 'AllowCreate']
|
|
308
|
+
}
|
|
309
|
+
*/
|
|
310
|
+
if (attributes.length > 1) {
|
|
311
|
+
const baseNode = (0, xpath_1.select)(baseXPath, targetDoc).map(n => n.toString());
|
|
312
|
+
const childXPath = `${buildAbsoluteXPath([(0, utility_js_1.last)(localPath)])}${attributeXPath}`;
|
|
313
|
+
const attributeValues = baseNode.map((node) => {
|
|
314
|
+
const nodeDoc = dom.parseFromString(node);
|
|
315
|
+
const values = (0, xpath_1.select)(childXPath, nodeDoc).reduce((r, n) => {
|
|
316
|
+
r[(0, camelcase_1.default)(n.name, { locale: 'en-us' })] = n.value;
|
|
317
|
+
return r;
|
|
318
|
+
}, {});
|
|
319
|
+
return values;
|
|
320
|
+
});
|
|
321
|
+
return {
|
|
322
|
+
...result,
|
|
323
|
+
[key]: attributeValues.length === 1 ? attributeValues[0] : attributeValues
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
// case: single attribute
|
|
327
|
+
/*
|
|
328
|
+
{
|
|
329
|
+
key: 'statusCode',
|
|
330
|
+
localPath: ['Response', 'Status', 'StatusCode'],
|
|
331
|
+
attributes: ['Value'],
|
|
332
|
+
}
|
|
333
|
+
*/
|
|
334
|
+
if (attributes.length === 1) {
|
|
335
|
+
const fullPath = `${baseXPath}${attributeXPath}`;
|
|
336
|
+
const attributeValues = (0, xpath_1.select)(fullPath, targetDoc).map((n) => n.value);
|
|
337
|
+
return {
|
|
338
|
+
...result,
|
|
339
|
+
[key]: attributeValues[0]
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
// case: zero attribute
|
|
343
|
+
/*
|
|
344
|
+
{
|
|
345
|
+
key: 'issuer',
|
|
346
|
+
localPath: ['AuthnRequest', 'Issuer'],
|
|
347
|
+
attributes: []
|
|
348
|
+
}
|
|
349
|
+
*/
|
|
350
|
+
if (attributes.length === 0) {
|
|
351
|
+
let attributeValue = null;
|
|
352
|
+
const node = (0, xpath_1.select)(baseXPath, targetDoc);
|
|
353
|
+
if (node.length === 1) {
|
|
354
|
+
const fullPath = `string(${baseXPath}${attributeXPath})`;
|
|
355
|
+
attributeValue = (0, xpath_1.select)(fullPath, targetDoc);
|
|
356
|
+
}
|
|
357
|
+
if (node.length > 1) {
|
|
358
|
+
attributeValue = node.filter((n) => n.firstChild)
|
|
359
|
+
.map((n) => n.firstChild.nodeValue);
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
...result,
|
|
363
|
+
[key]: attributeValue
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
return result;
|
|
367
|
+
}, {});
|
|
368
|
+
}
|
|
369
|
+
exports.extract = extract;
|
|
370
370
|
//# sourceMappingURL=extractor.js.map
|