Policy2005::getIssuedTokenWSTrustBinding()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 99
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 62
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 99
rs 8.829

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\adfs\Trust;
6
7
use SimpleSAML\WSSecurity\Constants as C;
8
use SimpleSAML\WSSecurity\XML\mssp\RsaToken;
9
use SimpleSAML\WSSecurity\XML\sp_200507\AlgorithmSuite;
10
use SimpleSAML\WSSecurity\XML\sp_200507\Basic256;
11
use SimpleSAML\WSSecurity\XML\sp_200507\EndorsingSupportingTokens;
12
use SimpleSAML\WSSecurity\XML\sp_200507\Header;
13
use SimpleSAML\WSSecurity\XML\sp_200507\HttpsToken;
14
use SimpleSAML\WSSecurity\XML\sp_200507\IncludeTimestamp;
15
use SimpleSAML\WSSecurity\XML\sp_200507\IncludeToken;
16
use SimpleSAML\WSSecurity\XML\sp_200507\IssuedToken;
17
use SimpleSAML\WSSecurity\XML\sp_200507\Layout;
18
use SimpleSAML\WSSecurity\XML\sp_200507\MustSupportIssuedTokens;
19
use SimpleSAML\WSSecurity\XML\sp_200507\MustSupportRefThumbprint;
20
use SimpleSAML\WSSecurity\XML\sp_200507\RequestSecurityTokenTemplate;
21
use SimpleSAML\WSSecurity\XML\sp_200507\RequireClientEntropy;
22
use SimpleSAML\WSSecurity\XML\sp_200507\RequireInternalReference;
23
use SimpleSAML\WSSecurity\XML\sp_200507\RequireServerEntropy;
24
use SimpleSAML\WSSecurity\XML\sp_200507\RequireThumbprintReference;
25
use SimpleSAML\WSSecurity\XML\sp_200507\SignedParts;
26
use SimpleSAML\WSSecurity\XML\sp_200507\SignedSupportingTokens;
27
use SimpleSAML\WSSecurity\XML\sp_200507\Strict;
28
use SimpleSAML\WSSecurity\XML\sp_200507\TransportBinding;
29
use SimpleSAML\WSSecurity\XML\sp_200507\TransportToken;
30
use SimpleSAML\WSSecurity\XML\sp_200507\Trust10;
31
use SimpleSAML\WSSecurity\XML\sp_200507\UsernameToken;
32
use SimpleSAML\WSSecurity\XML\sp_200507\Wss11;
33
use SimpleSAML\WSSecurity\XML\sp_200507\WssUsernameToken10;
34
use SimpleSAML\WSSecurity\XML\sp_200507\WssX509V3Token10;
35
use SimpleSAML\WSSecurity\XML\sp_200507\X509Token;
36
use SimpleSAML\WSSecurity\XML\wsaw\UsingAddressing;
37
use SimpleSAML\WSSecurity\XML\wsp\All;
38
use SimpleSAML\WSSecurity\XML\wsp\ExactlyOne;
39
use SimpleSAML\WSSecurity\XML\wsp\Policy;
40
use SimpleSAML\WSSecurity\XML\wst_200502\CanonicalizationAlgorithm;
41
use SimpleSAML\WSSecurity\XML\wst_200502\EncryptionAlgorithm;
42
use SimpleSAML\WSSecurity\XML\wst_200502\EncryptWith;
43
use SimpleSAML\WSSecurity\XML\wst_200502\KeySize;
44
use SimpleSAML\WSSecurity\XML\wst_200502\KeyType;
45
use SimpleSAML\WSSecurity\XML\wst_200502\KeyTypeEnum;
46
use SimpleSAML\WSSecurity\XML\wst_200502\SignatureAlgorithm;
47
use SimpleSAML\XML\Attribute as XMLAttribute;
48
49
/**
50
 * @package simplesamlphp/simplesamlphp-module-adfs
51
 */
52
class Policy2005
53
{
54
    /**
55
     * Constructor.
56
     *
57
     * @param \SimpleSAML\Configuration $config The general configuration
58
     * @param \SimpleSAML\Configuration $metadata The metadata configuration
59
     */
60
    public function __construct()
61
    {
62
    }
63
64
65
    /**
66
     * This method builds the wsp:Policy elements
67
     *
68
     * @param \SimpleSAML\WSSecurity\XML\wsp\Policy[]
69
     */
70
    public function getPolicies(): array
71
    {
72
        return [
73
            $this->getCertificateWSTrustBinding(),
74
            $this->getCertificateWSTrustBinding1(),
75
            $this->getUserNameWSTrustBindingPolicy(),
76
            $this->getIssuedTokenWSTrustBinding(),
77
            $this->getIssuedTokenWSTrustBinding1(),
78
        ];
79
    }
80
81
82
    /**
83
     * This method builds the CertificateWSTrustBinding policy.
84
     *
85
     * @param \SimpleSAML\WSSecurity\XML\wsp\Policy
86
     */
87
    private function getCertificateWSTrustBinding(): Policy
88
    {
89
        $transportBinding = new TransportBinding(
90
            elements: [new Policy(
91
                children: [
92
                    new TransportToken(
93
                        elements: [new Policy(
94
                            children: [new HttpsToken(false)],
95
                        )],
96
                    ),
97
                    new AlgorithmSuite(
98
                        elements: [new Policy(
99
                            children: [new Basic256()],
100
                        )],
101
                    ),
102
                    new Layout(
103
                        elements: [new Policy(
104
                            children: [new Strict()],
105
                        )],
106
                    ),
107
                    new IncludeTimestamp(),
108
                ],
109
            )],
110
        );
111
112
        $endorsingSupportingTokens = new EndorsingSupportingTokens(
113
            elements: [new Policy(
114
                children: [
115
                    new X509Token(
116
                        elts: [new Policy(
117
                            children: [
118
                                new RequireThumbprintReference(),
119
                                new WssX509V3Token10(),
120
                            ],
121
                        )],
122
                        namespacedAttributes: [
123
                            new XMLAttribute(
124
                                C::NS_SEC_POLICY_11,
125
                                'sp',
126
                                'IncludeToken',
127
                                IncludeToken::AlwaysToRecipient->value,
128
                            ),
129
                        ],
130
                    ),
131
                    new RsaToken(
132
                        namespacedAttributes: [
133
                            new XMLAttribute(C::NS_SEC_POLICY_11, 'sp', 'IncludeToken', IncludeToken::Never->value),
134
                            new XMLAttribute(C::NS_POLICY, 'wsp', 'Optional', 'true'),
135
                        ],
136
                    ),
137
                    new SignedParts(
138
                        header: [
139
                            new Header(
140
                                namespace: C::NS_ADDR_200508,
141
                                name: 'To',
142
                            ),
143
                        ],
144
                    ),
145
                ],
146
            )],
147
        );
148
149
        $wss11 = new Wss11(
150
            elements: [new Policy(
151
                children: [
152
                    new MustSupportRefThumbprint(),
153
                ],
154
            )],
155
        );
156
157
        $trust10 = new Trust10(
158
            elements: [new Policy(
159
                children: [
160
                    new MustSupportIssuedTokens(),
161
                    new RequireClientEntropy(),
162
                    new RequireServerEntropy(),
163
                ],
164
            )],
165
        );
166
167
        $usingAddressing = new UsingAddressing();
168
169
        return new Policy(
170
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'CertificateWSTrustBinding_IWSTrustFeb2005Async_policy'),
171
            operatorContent: [new ExactlyOne(
172
                operatorContent: [new All(
173
                    children: [
174
                        $transportBinding,
175
                        $endorsingSupportingTokens,
176
                        $wss11,
177
                        $trust10,
178
                        $usingAddressing,
179
                    ],
180
                )],
181
            )],
182
        );
183
    }
184
185
186
    /**
187
     * This method builds the CertificateWSTrustBinding1 policy.
188
     *
189
     * @param \SimpleSAML\WSSecurity\XML\wsp\Policy
190
     */
191
    private function getCertificateWSTrustBinding1(): Policy
192
    {
193
        $transportBinding = new TransportBinding(
194
            elements: [new Policy(
195
                children: [
196
                    new TransportToken(
197
                        elements: [new Policy(
198
                            children: [new HttpsToken(true)],
199
                        )],
200
                    ),
201
                    new AlgorithmSuite(
202
                        elements: [new Policy(
203
                            children: [new Basic256()],
204
                        )],
205
                    ),
206
                    new Layout(
207
                        elements: [new Policy(
208
                            children: [new Strict()],
209
                        )],
210
                    ),
211
                ],
212
            )],
213
        );
214
215
        $usingAddressing = new UsingAddressing();
216
217
        return new Policy(
218
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'CertificateWSTrustBinding_IWSTrustFeb2005Async1_policy'),
219
            operatorContent: [new ExactlyOne(
220
                operatorContent: [new All(
221
                    children: [
222
                        $transportBinding,
223
                        $usingAddressing,
224
                    ],
225
                )],
226
            )],
227
        );
228
    }
229
230
231
    /**
232
     * This method builds the UserNameWSTrustBinding policy.
233
     *
234
     * @param \SimpleSAML\WSSecurity\XML\wsp\Policy
235
     */
236
    private function getUserNameWSTrustBindingPolicy(): Policy
237
    {
238
        $transportBinding = new TransportBinding(
239
            elements: [new Policy(
240
                children: [
241
                    new TransportToken(
242
                        elements: [new Policy(
243
                            children: [new HttpsToken(false)],
244
                        )],
245
                    ),
246
                    new AlgorithmSuite(
247
                        elements: [new Policy(
248
                            children: [new Basic256()],
249
                        )],
250
                    ),
251
                    new Layout(
252
                        elements: [new Policy(
253
                            children: [new Strict()],
254
                        )],
255
                    ),
256
                    new IncludeTimestamp(),
257
                ],
258
            )],
259
        );
260
261
        $signedSupportingTokens = new SignedSupportingTokens(
262
            elements: [new Policy(
263
                children: [new UsernameToken(
264
                    elts: [new Policy(
265
                        children: [new WssUsernameToken10()],
266
                    )],
267
                    namespacedAttributes: [
268
                        new XMLAttribute(
269
                            C::NS_SEC_POLICY_11,
270
                            'sp',
271
                            'IncludeToken',
272
                            IncludeToken::AlwaysToRecipient->value,
273
                        ),
274
                    ],
275
                )],
276
            )],
277
        );
278
279
        $endorsingSupportingTokens = new EndorsingSupportingTokens(
280
            elements: [new Policy(
281
                children: [
282
                    new RsaToken(
283
                        namespacedAttributes: [
284
                            new XMLAttribute(C::NS_SEC_POLICY_11, 'sp', 'IncludeToken', IncludeToken::Never->value),
285
                            new XMLAttribute(C::NS_POLICY, 'wsp', 'Optional', 'true'),
286
                        ],
287
                    ),
288
                    new SignedParts(
289
                        header: [
290
                            new Header(
291
                                namespace: C::NS_ADDR_200508,
292
                                name: 'To',
293
                            ),
294
                        ],
295
                    ),
296
                ],
297
            )],
298
        );
299
300
        $wss11 = new Wss11(
301
            elements: [new Policy()],
302
        );
303
304
        $trust10 = new Trust10(
305
            elements: [new Policy(
306
                children: [
307
                    new MustSupportIssuedTokens(),
308
                    new RequireClientEntropy(),
309
                    new RequireServerEntropy(),
310
                ],
311
            )],
312
        );
313
314
        $usingAddressing = new UsingAddressing();
315
316
        return new Policy(
317
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'UserNameWSTrustBinding_IWSTrustFeb2005Async_policy'),
318
            operatorContent: [new ExactlyOne(
319
                operatorContent: [new All(
320
                    children: [
321
                        $transportBinding,
322
                        $signedSupportingTokens,
323
                        $endorsingSupportingTokens,
324
                        $wss11,
325
                        $trust10,
326
                        $usingAddressing,
327
                    ],
328
                )],
329
            )],
330
        );
331
    }
332
333
334
    /**
335
     * This method builds the IssuedTokenWSTrustBinding policy.
336
     *
337
     * @param \SimpleSAML\WSSecurity\XML\wsp\Policy
338
     */
339
    private function getIssuedTokenWSTrustBinding(): Policy
340
    {
341
        $transportBinding = new TransportBinding(
342
            elements: [new Policy(
343
                children: [
344
                    new TransportToken(
345
                        elements: [new Policy(
346
                            children: [new HttpsToken(false)],
347
                        )],
348
                    ),
349
                    new AlgorithmSuite(
350
                        elements: [new Policy(
351
                            children: [new Basic256()],
352
                        )],
353
                    ),
354
                    new Layout(
355
                        elements: [new Policy(
356
                            children: [new Strict()],
357
                        )],
358
                    ),
359
                    new IncludeTimestamp(),
360
                ],
361
            )],
362
        );
363
364
        $endorsingSupportingTokens = new EndorsingSupportingTokens(
365
            elements: [new Policy(
366
                children: [
367
                    new IssuedToken(
368
                        requestSecurityTokenTemplate: new RequestSecurityTokenTemplate(
369
                            elts: [
370
                                new KeyType([KeyTypeEnum::PublicKey]),
371
                                new EncryptWith(C::KEY_TRANSPORT_OAEP_MGF1P),
372
                                new SignatureAlgorithm(C::SIG_RSA_SHA1),
373
                                new CanonicalizationAlgorithm(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS),
374
                                new EncryptionAlgorithm(C::BLOCK_ENC_AES256),
375
                            ],
376
                        ),
377
                        elts: [
378
                            new Policy(
379
                                children: [
380
                                    new RequireInternalReference(),
381
                                ],
382
                            ),
383
                        ],
384
                        namespacedAttributes: [
385
                            new XMLAttribute(
386
                                C::NS_SEC_POLICY_11,
387
                                'sp',
388
                                'IncludeToken',
389
                                IncludeToken::AlwaysToRecipient->value,
390
                            ),
391
                        ],
392
                    ),
393
                    new RsaToken(
394
                        namespacedAttributes: [
395
                            new XMLAttribute(C::NS_SEC_POLICY_11, 'sp', 'IncludeToken', IncludeToken::Never->value),
396
                            new XMLAttribute(C::NS_POLICY, 'wsp', 'Optional', 'true'),
397
                        ],
398
                    ),
399
                    new SignedParts(
400
                        header: [
401
                            new Header(
402
                                namespace: C::NS_ADDR_200508,
403
                                name: 'To',
404
                            ),
405
                        ],
406
                    ),
407
                ],
408
            )],
409
        );
410
411
        $wss11 = new Wss11(
412
            elements: [new Policy(
413
            )],
414
        );
415
416
        $trust10 = new Trust10(
417
            elements: [new Policy(
418
                children: [
419
                    new MustSupportIssuedTokens(),
420
                    new RequireClientEntropy(),
421
                    new RequireServerEntropy(),
422
                ],
423
            )],
424
        );
425
426
        $usingAddressing = new UsingAddressing();
427
428
        return new Policy(
429
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'IssuedTokenWSTrustBinding_IWSTrustFeb2005Async_policy'),
430
            operatorContent: [new ExactlyOne(
431
                operatorContent: [new All(
432
                    children: [
433
                        $transportBinding,
434
                        $endorsingSupportingTokens,
435
                        $wss11,
436
                        $trust10,
437
                        $usingAddressing,
438
                    ],
439
                )],
440
            )],
441
        );
442
    }
443
444
445
    /**
446
     * This method builds the IssuedTokenWSTrustBinding1 policy.
447
     *
448
     * @param \SimpleSAML\WSSecurity\XML\wsp\Policy
449
     */
450
    private function getIssuedTokenWSTrustBinding1(): Policy
451
    {
452
        $transportBinding = new TransportBinding(
453
            elements: [new Policy(
454
                children: [
455
                    new TransportToken(
456
                        elements: [new Policy(
457
                            children: [new HttpsToken(false)],
458
                        )],
459
                    ),
460
                    new AlgorithmSuite(
461
                        elements: [new Policy(
462
                            children: [new Basic256()],
463
                        )],
464
                    ),
465
                    new Layout(
466
                        elements: [new Policy(
467
                            children: [new Strict()],
468
                        )],
469
                    ),
470
                    new IncludeTimestamp(),
471
                ],
472
            )],
473
        );
474
475
        $endorsingSupportingTokens = new EndorsingSupportingTokens(
476
            elements: [new Policy(
477
                children: [
478
                    new IssuedToken(
479
                        requestSecurityTokenTemplate: new RequestSecurityTokenTemplate(
480
                            elts: [
481
                                new KeyType([KeyTypeEnum::SymmetricKey]),
482
                                new KeySize('256'),
483
                                new EncryptWith(C::BLOCK_ENC_AES256),
484
                                new SignatureAlgorithm(C::SIG_HMAC_SHA1),
485
                                new CanonicalizationAlgorithm(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS),
486
                                new EncryptionAlgorithm(C::BLOCK_ENC_AES256),
487
                            ],
488
                        ),
489
                        elts: [
490
                            new Policy(
491
                                children: [
492
                                    new RequireInternalReference(),
493
                                ],
494
                            ),
495
                        ],
496
                        namespacedAttributes: [
497
                            new XMLAttribute(
498
                                C::NS_SEC_POLICY_11,
499
                                'sp',
500
                                'IncludeToken',
501
                                IncludeToken::AlwaysToRecipient->value,
502
                            ),
503
                        ],
504
                    ),
505
                    new RsaToken(
506
                        namespacedAttributes: [
507
                            new XMLAttribute(C::NS_SEC_POLICY_11, 'sp', 'IncludeToken', IncludeToken::Never->value),
508
                            new XMLAttribute(C::NS_POLICY, 'wsp', 'Optional', 'true'),
509
                        ],
510
                    ),
511
                    new SignedParts(
512
                        header: [
513
                            new Header(
514
                                namespace: C::NS_ADDR_200508,
515
                                name: 'To',
516
                            ),
517
                        ],
518
                    ),
519
                ],
520
            )],
521
        );
522
523
        $wss11 = new Wss11(
524
            elements: [new Policy(
525
            )],
526
        );
527
528
        $trust10 = new Trust10(
529
            elements: [new Policy(
530
                children: [
531
                    new MustSupportIssuedTokens(),
532
                    new RequireClientEntropy(),
533
                    new RequireServerEntropy(),
534
                ],
535
            )],
536
        );
537
538
        $usingAddressing = new UsingAddressing();
539
540
        return new Policy(
541
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'IssuedTokenWSTrustBinding_IWSTrustFeb2005Async1_policy'),
542
            operatorContent: [new ExactlyOne(
543
                operatorContent: [new All(
544
                    children: [
545
                        $transportBinding,
546
                        $endorsingSupportingTokens,
547
                        $wss11,
548
                        $trust10,
549
                        $usingAddressing,
550
                    ],
551
                )],
552
            )],
553
        );
554
    }
555
}
556