Issues (32)

src/MetadataExchange.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\adfs;
6
7
use SimpleSAML\Module;
8
use SimpleSAML\Module\adfs\Trust;
9
use SimpleSAML\WSDL\XML\soap12\{
10
    Address as Soap12Address,
11
    Binding as Soap12Binding,
12
    Body as Soap12Body,
13
    Operation as Soap12Operation,
14
};
15
use SimpleSAML\WSDL\XML\wsdl\{
16
    Binding,
17
    BindingOperation,
18
    BindingOperationInput,
19
    BindingOperationOutput,
20
    Definitions,
21
    Input,
22
    Message,
23
    Output,
24
    Part,
25
    Port,
26
    PortType,
27
    PortTypeOperation,
28
    Service,
29
    Types,
30
};
31
use SimpleSAML\WSSecurity\Constants as C;
32
use SimpleSAML\WSSecurity\XML\wsa_200508\{Address, EndpointReference};
33
use SimpleSAML\WSSecurity\XML\wsp\PolicyReference;
34
use SimpleSAML\WSSecurity\XML\wst_200502\{
35
    RequestSecurityToken as RequestSecurityToken2005,
36
    RequestSecurityTokenResponse as RequestSecurityTokenResponse2005,
37
};
38
use SimpleSAML\WSSecurity\XML\wst_200512\{
39
    RequestSecurityToken as RequestSecurityToken13,
40
    RequestSecurityTokenResponseCollection as RequestSecurityTokenResponseCollection13,
41
};
42
use SimpleSAML\XML\Attribute as XMLAttribute;
43
44
//use SimpleSAML\XML\Chunk;
45
//use SimpleSAML\XML\DOMDocumentFactory;
46
47
use function array_merge;
48
use function sprintf;
49
50
/**
51
 * Common code for building MetaExchange (mex) documents based on the available configuration.
52
 *
53
 * @package simplesamlphp/simplesamlphp-module-adfs
54
 */
55
class MetadataExchange
56
{
57
    /**
58
     * Constructor.
59
     */
60
    public function __construct()
61
    {
62
    }
63
64
65
    /**
66
     * Build a mex document
67
     *
68
     * @return \SimpleSAML\WSDL\XML\wsdl\Definitions
69
     */
70
    public function buildDocument(): Definitions
71
    {
72
        return new Definitions(
73
            targetNamespace: 'http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice',
74
            name: 'SecurityTokenService',
75
            //import: [],
76
            //types: $this->getTypes(),
77
            message: $this->getMessages(),
78
            portType: $this->getPortTypes(),
79
            binding: $this->getBindings(),
80
            service: $this->getServices(),
81
            elements: $this->getPolicies(),
82
        );
83
    }
84
85
86
    /**
87
     * This method builds the wsp:Policy elements
88
     *
89
     * @return \SimpleSAML\WSSecurity\XML\wsp\Policy[]
90
     */
91
    private function getPolicies(): array
92
    {
93
        $policy2005 = new Trust\Policy2005();
94
        $policy13 = new Trust\Policy13();
0 ignored issues
show
The assignment to $policy13 is dead and can be removed.
Loading history...
95
96
        return array_merge(
97
            $policy2005->getPolicies(),
98
            //$policy13->getPolicies(),
99
        );
100
    }
101
102
103
    /**
104
     * This method builds the wsdl:types elements
105
     *
106
     * @return \SimpleSAML\WSSL\XML\wsdl\Types[]
107
    private function getTypes(): array
108
    {
109
        $defaultEndpoint = Module::getModuleURL('adfs/services/trust/mex');
110
        $xml = <<<IMPORT
111
<xsd:schema
112
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
113
  targetNamespace="http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice/Imports">
114
<xsd:import schemaLocation="$defaultEndpoint?xsd=xsd0" namespace="http://schemas.microsoft.com/Message"/>
115
<xsd:import schemaLocation="$defaultEndpoint?xsd=xsd1" namespace="http://schemas.xmlsoap.org/ws/2005/02/trust"/>
116
<xsd:import schemaLocation="$defaultEndpoint?xsd=xsd2" namespace="http://docs.oasis-open.org/ws-sx/ws-trust/200512"/>
117
</xsd:schema>
118
IMPORT;
119
120
        return [
121
            new Types([
122
                new Chunk(DOMDocumentFactory::fromString($xml)->documentElement),
123
            ]),
124
        ];
125
    }
126
     */
127
128
129
    /**
130
     * This method builds the wsdl:message elements
131
     *
132
     * @return \SimpleSAML\WSDL\XML\wsdl\Message[]
133
     */
134
    private function getMessages(): array
135
    {
136
        return [
137
            new Message(
138
                'IWSTrustFeb2005Async_TrustFeb2005IssueAsync_InputMessage',
139
                [new Part(
140
                    'request',
141
                    sprintf(
142
                        "%s:%s",
143
                        RequestSecurityToken2005::getNamespacePrefix(),
144
                        RequestSecurityToken2005::getLocalName(),
145
                    ),
146
                )],
147
            ),
148
            new Message(
149
                'IWSTrustFeb2005Async_TrustFeb2005IssueAsync_OutputMessage',
150
                [new Part(
151
                    'TrustFeb2005IssueAsyncResult',
152
                    sprintf(
153
                        "%s:%s",
154
                        RequestSecurityTokenResponse2005::getNamespacePrefix(),
155
                        RequestSecurityTokenResponse2005::getLocalName(),
156
                    ),
157
                )],
158
            ),
159
/*
160
            new Message(
161
                'IWSTrust13Async_Trust13IssueAsync_InputMessage',
162
                [new Part(
163
                    'request',
164
                    sprintf(
165
                        "%s:%s",
166
                        RequestSecurityToken13::getNamespacePrefix(),
167
                        RequestSecurityToken13::getLocalName(),
168
                    ),
169
                )],
170
            ),
171
            new Message(
172
                'IWSTrust13Async_Trust13IssueAsync_OutputMessage',
173
                [new Part(
174
                    'Trust13IssueAsyncResult',
175
                    sprintf(
176
                        "%s:%s",
177
                        RequestSecurityTokenResponseCollection13::getNamespacePrefix(),
178
                        RequestSecurityTokenResponseCollection13::getLocalName(),
179
                    ),
180
                )],
181
            ),
182
*/
183
        ];
184
    }
185
186
187
    /**
188
     * This method builds the wsdl:portType elements
189
     *
190
     * @return \SimpleSAML\WSDL\XML\wsdl\PortType[]
191
     */
192
    private function getPortTypes(): array
193
    {
194
        return [
195
            new PortType('IWSTrustFeb2005Async', [
196
                new PortTypeOperation(
197
                    name: 'TrustFeb2005IssueAsync',
198
                    input: new Input(
199
                        message: 'tns:IWSTrustFeb2005Async_TrustFeb2005IssueAsync_InputMessage',
200
                        attributes: [
201
                            new XMLAttribute(
202
                                C::NS_WSDL_ADDR,
203
                                'wsaw',
204
                                'Action',
205
                                'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue',
206
                            ),
207
                        ],
208
                    ),
209
                    output: new Output(
210
                        message: 'tns:IWSTrustFeb2005Async_TrustFeb2005IssueAsync_OutputMessage',
211
                        attributes: [
212
                            new XMLAttribute(
213
                                C::NS_WSDL_ADDR,
214
                                'wsaw',
215
                                'Action',
216
                                'http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Issue',
217
                            ),
218
                        ],
219
                    ),
220
                ),
221
            ]),
222
/*
223
            new PortType('IWSTrust13Async', [
224
                new PortTypeOperation(
225
                    name: 'Trust13IssueAsync',
226
                    input: new Input(
227
                        message: 'tns:IWSTrust13Async_Trust13IssueAsync_InputMessage',
228
                        attributes: [
229
                            new XMLAttribute(
230
                                C::NS_WSDL_ADDR,
231
                                'wsaw',
232
                                'Action',
233
                                'http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue',
234
                            ),
235
                        ],
236
                    ),
237
                    output: new Output(
238
                        message: 'tns:IWSTrust13Async_Trust13IssueAsync_OutputMessage',
239
                        attributes: [
240
                            new XMLAttribute(
241
                                C::NS_WSDL_ADDR,
242
                                'wsaw',
243
                                'Action',
244
                                'http://docs.oasis-open.org/ws-sx/ws-trust/200512/RSTRC/IssueFinal',
245
                            ),
246
                        ],
247
                    ),
248
                ),
249
            ]),
250
*/
251
        ];
252
    }
253
254
255
    /**
256
     * This method builds the wsdl:binding elements
257
     *
258
     * @return \SimpleSAML\WSDL\XML\wsdl\Binding[]
259
     */
260
    private function getBindings(): array
261
    {
262
        return [
263
            new Binding(
264
                name: 'CertificateWSTrustBinding_IWSTrustFeb2005Async',
265
                type: 'tns:IWSTrustFeb2005Async',
266
                operation: [
267
                    new BindingOperation(
268
                        name: 'TrustFeb2005IssueAsync',
269
                        input: new BindingOperationInput(
270
                            elements: [
271
                                new Soap12Body(null, null, 'literal'),
272
                            ],
273
                        ),
274
                        output: new BindingOperationOutput(
275
                            elements: [
276
                                new Soap12Body(null, null, 'literal'),
277
                            ],
278
                        ),
279
                        elements: [
280
                            new Soap12Operation(
281
                                'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue',
282
                                null,
283
                                'document',
284
                            ),
285
                        ],
286
                    ),
287
                ],
288
                elements: [
289
                    new PolicyReference(
290
                        URI: '#CertificateWSTrustBinding_IWSTrustFeb2005Async_policy',
291
                        DigestAlgorithm: null,
292
                    ),
293
                    new Soap12Binding('http://schemas.xmlsoap.org/soap/http'),
294
                ],
295
            ),
296
            new Binding(
297
                name: 'CertificateWSTrustBinding_IWSTrustFeb2005Async1',
298
                type: 'tns:IWSTrustFeb2005Async',
299
                operation: [
300
                    new BindingOperation(
301
                        name: 'TrustFeb2005IssueAsync',
302
                        input: new BindingOperationInput(
303
                            elements: [
304
                                new Soap12Body(null, null, 'literal'),
305
                            ],
306
                        ),
307
                        output: new BindingOperationOutput(
308
                            elements: [
309
                                new Soap12Body(null, null, 'literal'),
310
                            ],
311
                        ),
312
                        elements: [
313
                            new Soap12Operation(
314
                                'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue',
315
                                null,
316
                                'document',
317
                            ),
318
                        ],
319
                    ),
320
                ],
321
                elements: [
322
                    new PolicyReference(
323
                        URI: '#CertificateWSTrustBinding_IWSTrustFeb2005Async1_policy',
324
                        DigestAlgorithm: null,
325
                    ),
326
                    new Soap12Binding('http://schemas.xmlsoap.org/soap/http'),
327
                ],
328
            ),
329
            new Binding(
330
                name: 'UserNameWSTrustBinding_IWSTrustFeb2005Async',
331
                type: 'tns:IWSTrustFeb2005Async',
332
                operation: [
333
                    new BindingOperation(
334
                        name: 'TrustFeb2005IssueAsync',
335
                        input: new BindingOperationInput(
336
                            elements: [
337
                                new Soap12Body(null, null, 'literal'),
338
                            ],
339
                        ),
340
                        output: new BindingOperationOutput(
341
                            elements: [
342
                                new Soap12Body(null, null, 'literal'),
343
                            ],
344
                        ),
345
                        elements: [
346
                            new Soap12Operation(
347
                                'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue',
348
                                null,
349
                                'document',
350
                            ),
351
                        ],
352
                    ),
353
                ],
354
                elements: [
355
                    new PolicyReference(
356
                        URI: '#UserNameWSTrustBinding_IWSTrustFeb2005Async_policy',
357
                        DigestAlgorithm: null,
358
                    ),
359
                    new Soap12Binding('http://schemas.xmlsoap.org/soap/http'),
360
                ],
361
            ),
362
            new Binding(
363
                name: 'IssuedTokenWSTrustBinding_IWSTrustFeb2005Async',
364
                type: 'tns:IWSTrustFeb2005Async',
365
                operation: [
366
                    new BindingOperation(
367
                        name: 'TrustFeb2005IssueAsync',
368
                        input: new BindingOperationInput(
369
                            elements: [
370
                                new Soap12Body(null, null, 'literal'),
371
                            ],
372
                        ),
373
                        output: new BindingOperationOutput(
374
                            elements: [
375
                                new Soap12Body(null, null, 'literal'),
376
                            ],
377
                        ),
378
                        elements: [
379
                            new Soap12Operation(
380
                                'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue',
381
                                null,
382
                                'document',
383
                            ),
384
                        ],
385
                    ),
386
                ],
387
                elements: [
388
                    new PolicyReference(
389
                        URI: '#IssuedTokenWSTrustBinding_IWSTrustFeb2005Async_policy',
390
                        DigestAlgorithm: null,
391
                    ),
392
                    new Soap12Binding('http://schemas.xmlsoap.org/soap/http'),
393
                ],
394
            ),
395
            new Binding(
396
                name: 'IssuedTokenWSTrustBinding_IWSTrustFeb2005Async1',
397
                type: 'tns:IWSTrustFeb2005Async',
398
                operation: [
399
                    new BindingOperation(
400
                        name: 'TrustFeb2005IssueAsync',
401
                        input: new BindingOperationInput(
402
                            elements: [
403
                                new Soap12Body(null, null, 'literal'),
404
                            ],
405
                        ),
406
                        output: new BindingOperationOutput(
407
                            elements: [
408
                                new Soap12Body(null, null, 'literal'),
409
                            ],
410
                        ),
411
                        elements: [
412
                            new Soap12Operation(
413
                                'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue',
414
                                null,
415
                                'document',
416
                            ),
417
                        ],
418
                    ),
419
                ],
420
                elements: [
421
                    new PolicyReference(
422
                        URI: '#IssuedTokenWSTrustBinding_IWSTrustFeb2005Async1_policy',
423
                        DigestAlgorithm: null,
424
                    ),
425
                    new Soap12Binding('http://schemas.xmlsoap.org/soap/http'),
426
                ],
427
            ),
428
/*
429
            new Binding(
430
                name: 'CertificateWSTrustBinding_IWSTrust13Async',
431
                type: 'tns:IWSTrust13Async',
432
                operation: [
433
                    new BindingOperation(
434
                        name: 'Trust13IssueAsync',
435
                        input: new BindingOperationInput(
436
                            elements: [
437
                                new Soap12Body(null, null, 'literal'),
438
                            ],
439
                        ),
440
                        output: new BindingOperationOutput(
441
                            elements: [
442
                                new Soap12Body(null, null, 'literal'),
443
                            ],
444
                        ),
445
                        elements: [
446
                            new Soap12Operation(
447
                                'http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue',
448
                                null,
449
                                'document',
450
                            ),
451
                        ],
452
                    ),
453
                ],
454
                elements: [
455
                    new PolicyReference(
456
                        URI: '#CertificateWSTrustBinding_IWSTrust13Async_policy',
457
                        DigestAlgorithm: null,
458
                    ),
459
                    new Soap12Binding('http://schemas.xmlsoap.org/soap/http'),
460
                ],
461
            ),
462
            new Binding(
463
                name: 'UserNameWSTrustBinding_IWSTrust13Async',
464
                type: 'tns:IWSTrust13Async',
465
                operation: [
466
                    new BindingOperation(
467
                        name: 'Trust13IssueAsync',
468
                        input: new BindingOperationInput(
469
                            elements: [
470
                                new Soap12Body(null, null, 'literal'),
471
                            ],
472
                        ),
473
                        output: new BindingOperationOutput(
474
                            elements: [
475
                                new Soap12Body(null, null, 'literal'),
476
                            ],
477
                        ),
478
                        elements: [
479
                            new Soap12Operation(
480
                                'http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue',
481
                                null,
482
                                'document',
483
                            ),
484
                        ],
485
                    ),
486
                ],
487
                elements: [
488
                    new PolicyReference(
489
                        URI: '#UserNameWSTrustBinding_IWSTrust13Async_policy',
490
                        DigestAlgorithm: null,
491
                    ),
492
                    new Soap12Binding('http://schemas.xmlsoap.org/soap/http'),
493
                ],
494
            ),
495
            new Binding(
496
                name: 'IssuedTokenWSTrustBinding_IWSTrust13Async',
497
                type: 'tns:IWSTrust13Async',
498
                operation: [
499
                    new BindingOperation(
500
                        name: 'Trust13IssueAsync',
501
                        input: new BindingOperationInput(
502
                            elements: [
503
                                new Soap12Body(null, null, 'literal'),
504
                            ],
505
                        ),
506
                        output: new BindingOperationOutput(
507
                            elements: [
508
                                new Soap12Body(null, null, 'literal'),
509
                            ],
510
                        ),
511
                        elements: [
512
                            new Soap12Operation(
513
                                'http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue',
514
                                null,
515
                                'document',
516
                            ),
517
                        ],
518
                    ),
519
                ],
520
                elements: [
521
                    new PolicyReference(
522
                        URI: '#IssuedTokenWSTrustBinding_IWSTrust13Async_policy',
523
                        DigestAlgorithm: null,
524
                    ),
525
                    new Soap12Binding('http://schemas.xmlsoap.org/soap/http'),
526
                ],
527
            ),
528
            new Binding(
529
                name: 'IssuedTokenWSTrustBinding_IWSTrust13Async1',
530
                type: 'tns:IWSTrust13Async',
531
                operation: [
532
                    new BindingOperation(
533
                        name: 'Trust13IssueAsync',
534
                        input: new BindingOperationInput(
535
                            elements: [
536
                                new Soap12Body(null, null, 'literal'),
537
                            ],
538
                        ),
539
                        output: new BindingOperationOutput(
540
                            elements: [
541
                                new Soap12Body(null, null, 'literal'),
542
                            ],
543
                        ),
544
                        elements: [
545
                            new Soap12Operation(
546
                                'http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue',
547
                                null,
548
                                'document',
549
                            ),
550
                        ],
551
                    ),
552
                ],
553
                elements: [
554
                    new PolicyReference(
555
                        URI: '#IssuedTokenWSTrustBinding_IWSTrust13Async1_policy',
556
                        DigestAlgorithm: null,
557
                    ),
558
                    new Soap12Binding('http://schemas.xmlsoap.org/soap/http'),
559
                ],
560
            ),
561
*/
562
        ];
563
    }
564
565
566
    /**
567
     * This method builds the wsdl:service elements
568
     *
569
     * @return \SimpleSAML\WSDL\XML\wsdl\Service[]
570
     */
571
    private function getServices(): array
572
    {
573
        $defaultEndpoint = Module::getModuleURL('adfs/ws-trust/2005/services/');
574
575
        return [
576
            new Service(
577
                name: 'SecurityTokenService',
578
                ports: [
579
                    new Port(
580
                        name: 'CertificateWSTrustBinding_IWSTrustFeb2005Async',
581
                        binding: 'tns:CertificateWSTrustBinding_IWSTrustFeb2005Async',
582
                        elements: [
583
                            new Soap12Address($defaultEndpoint . 'certificatemixed'),
584
                            new EndpointReference(
585
                                new Address($defaultEndpoint . 'certificatemixed'),
586
                            ),
587
                        ],
588
                    ),
589
                    new Port(
590
                        name: 'CertificateWSTrustBinding_IWSTrustFeb2005Async1',
591
                        binding: 'tns:CertificateWSTrustBinding_IWSTrustFeb2005Async1',
592
                        elements: [
593
                            new Soap12Address($defaultEndpoint . 'certificatetransport'),
594
                            new EndpointReference(
595
                                new Address($defaultEndpoint . 'certificatetransport'),
596
                            ),
597
                        ],
598
                    ),
599
                    new Port(
600
                        name: 'UserNameWSTrustBinding_IWSTrustFeb2005Async',
601
                        binding: 'tns:UserNameWSTrustBinding_IWSTrustFeb2005Async',
602
                        elements: [
603
                            new Soap12Address($defaultEndpoint . 'usernamemixed'),
604
                            new EndpointReference(
605
                                new Address($defaultEndpoint . 'usernamemixed'),
606
                            ),
607
                        ],
608
                    ),
609
                    new Port(
610
                        name: 'IssuedTokenWSTrustBinding_IWSTrustFeb2005Async',
611
                        binding: 'tns:IssuedTokenWSTrustBinding_IWSTrustFeb2005Async',
612
                        elements: [
613
                            new Soap12Address($defaultEndpoint . 'issuedtokenmixedasymmetricbasic256'),
614
                            new EndpointReference(
615
                                new Address($defaultEndpoint . 'issuedtokenmixedasymmetricbasic256'),
616
                            ),
617
                        ],
618
                    ),
619
                    new Port(
620
                        name: 'IssuedTokenWSTrustBinding_IWSTrustFeb2005Async1',
621
                        binding: 'tns:IssuedTokenWSTrustBinding_IWSTrustFeb2005Async1',
622
                        elements: [
623
                            new Soap12Address($defaultEndpoint . 'issuedtokenmixedsymmetricbasic256'),
624
                            new EndpointReference(
625
                                new Address($defaultEndpoint . 'issuedtokenmixedsymmetricbasic256'),
626
                            ),
627
                        ],
628
                    ),
629
                /*
630
                    new Port(
631
                        name: 'CertificateWSTrustBinding_IWSTrust13Async',
632
                        binding: 'tns:CertificateWSTrustBinding_IWSTrust13Async',
633
                        elements: [
634
                            new Soap12Address($defaultEndpoint . '13/certificatemixed'),
635
                            new EndpointReference(
636
                                new Address($defaultEndpoint . '13/certificatemixed'),
637
                            ),
638
                        ],
639
                    ),
640
                    new Port(
641
                        name: 'UserNameWSTrustBinding_IWSTrust13Async',
642
                        binding: 'tns:UserNameWSTrustBinding_IWSTrust13Async',
643
                        elements: [
644
                            new Soap12Address($defaultEndpoint . '13/usernamemixed'),
645
                            new EndpointReference(
646
                                new Address($defaultEndpoint . '13/usernamemixed'),
647
                            ),
648
                        ],
649
                    ),
650
                    new Port(
651
                        name: 'IssuedTokenWSTrustBinding_IWSTrust13Async',
652
                        binding: 'tns:IssuedTokenWSTrustBinding_IWSTrust13Async',
653
                        elements: [
654
                            new Soap12Address($defaultEndpoint . '13/issuedtokenmixedasymmetricbasic256'),
655
                            new EndpointReference(
656
                                new Address($defaultEndpoint . '13/issuedtokenmixedasymmetricbasic256'),
657
                            ),
658
                        ],
659
                    ),
660
                    new Port(
661
                        name: 'IssuedTokenWSTrustBinding_IWSTrust13Async1',
662
                        binding: 'tns:IssuedTokenWSTrustBinding_IWSTrust13Async1',
663
                        elements: [
664
                            new Soap12Address($defaultEndpoint . '13/issuedtokenmixedsymmetricbasic256'),
665
                            new EndpointReference(
666
                                new Address($defaultEndpoint . '13/issuedtokenmixedsymmetricbasic256'),
667
                            ),
668
                        ],
669
                    ),
670
                */
671
                ],
672
            ),
673
        ];
674
    }
675
}
676