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