TemplatePreviewController   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 250
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 144
dl 0
loc 250
rs 10
c 1
b 0
f 0
wmc 15

15 Methods

Rating   Name   Duplication   Size   Complexity  
A verifySmsChallenge() 0 17 1
A createMockSecondFactors() 0 41 1
A gatewayUnprocessableResponse() 0 7 1
A samlRecoverableError() 0 7 1
A samlConsumeAssertion() 0 7 1
A adfsConsumeAssertion() 0 9 1
A error404() 0 6 1
A verifyYubikey() 0 15 1
A chooseSecondFactor() 0 20 1
A gatewayConsumeAssertion() 0 7 1
A index() 0 27 1
A adfsLogin() 0 9 1
A errorGeneral() 0 6 1
A verifySms() 0 18 1
A samlUnprocessableResponse() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Copyright 2025 SURFnet bv
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
20
namespace Surfnet\StepupGateway\Behat\Controller;
21
22
use Surfnet\StepupGateway\Behat\Mock\MockSecondFactor;
23
use Surfnet\StepupGateway\GatewayBundle\Command\ChooseSecondFactorCommand;
24
use Surfnet\StepupGateway\GatewayBundle\Command\SendSmsChallengeCommand;
25
use Surfnet\StepupGateway\GatewayBundle\Command\VerifyYubikeyOtpCommand;
26
use Surfnet\StepupGateway\GatewayBundle\Form\Type\CancelAuthenticationType;
27
use Surfnet\StepupGateway\GatewayBundle\Form\Type\ChooseSecondFactorType;
28
use Surfnet\StepupGateway\GatewayBundle\Form\Type\SendSmsChallengeType;
29
use Surfnet\StepupGateway\GatewayBundle\Form\Type\VerifySmsChallengeType;
30
use Surfnet\StepupGateway\GatewayBundle\Form\Type\VerifyYubikeyOtpType;
31
use Surfnet\StepupGateway\SecondFactorOnlyBundle\Adfs\ValueObject\Response as AdfsResponse;
32
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
33
use Symfony\Component\HttpFoundation\Response;
34
use Symfony\Component\Routing\Attribute\Route;
35
36
/**
37
 * Controller for previewing templates with mock data for frontend development
38
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
39
 */
40
#[Route('/preview', name: 'preview_')]
41
class TemplatePreviewController extends AbstractController
42
{
43
    #[Route('/', name: 'index')]
44
    public function index(): Response
45
    {
46
        return $this->render('@test_resources/preview_index.html.twig', [
47
            'templates' => [
48
                'Second Factor' => [
49
                    'choose_second_factor' => 'Choose Second Factor (WAYG)',
50
                    'verify_yubikey' => 'Verify Yubikey',
51
                    'verify_sms' => 'Send SMS Challenge',
52
                    'verify_sms_challenge' => 'Verify SMS Challenge',
53
                ],
54
                'SAML Proxy' => [
55
                    'saml_consume_assertion' => 'SAML Consume Assertion',
56
                    'saml_recoverable_error' => 'SAML Recoverable Error',
57
                    'saml_unprocessable_response' => 'SAML Unprocessable Response',
58
                ],
59
                'Gateway' => [
60
                    'gateway_consume_assertion' => 'Gateway Consume Assertion',
61
                    'gateway_unprocessable_response' => 'Gateway Unprocessable Response',
62
                ],
63
                'ADFS' => [
64
                    'adfs_consume_assertion' => 'ADFS Consume Assertion',
65
                    'adfs_login' => 'ADFS Login Form',
66
                ],
67
                'Errors' => [
68
                    'error_404' => 'Error 404',
69
                    'error_general' => 'General Error',
70
                ],
71
            ],
72
        ]);
73
    }
74
75
    #[Route('/choose-second-factor', name: 'choose_second_factor')]
76
    public function chooseSecondFactor(): Response
77
    {
78
        $secondFactors = $this->createMockSecondFactors();
79
80
        $command = new ChooseSecondFactorCommand();
81
        $command->secondFactors = $secondFactors;
0 ignored issues
show
Documentation Bug introduced by
It seems like $secondFactors of type Surfnet\StepupGateway\Be...Mock\MockSecondFactor[] is incompatible with the declared type Surfnet\StepupGateway\Ga...e\Entity\SecondFactor[] of property $secondFactors.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
82
83
        $form = $this->createForm(ChooseSecondFactorType::class, $command, [
84
            'action' => '#',
85
        ]);
86
87
        $cancelForm = $this->createForm(CancelAuthenticationType::class, null, [
88
            'action' => '#',
89
        ]);
90
91
        return $this->render('@default/second_factor/choose_second_factor.html.twig', [
92
            'form' => $form->createView(),
93
            'cancelForm' => $cancelForm->createView(),
94
            'secondFactors' => $secondFactors,
95
        ]);
96
    }
97
98
    #[Route('/verify-yubikey', name: 'verify_yubikey')]
99
    public function verifyYubikey(): Response
100
    {
101
        $command = new VerifyYubikeyOtpCommand();
102
        $form = $this->createForm(VerifyYubikeyOtpType::class, $command, [
103
            'action' => '#',
104
        ]);
105
106
        $cancelForm = $this->createForm(CancelAuthenticationType::class, null, [
107
            'action' => '#',
108
        ]);
109
110
        return $this->render('@default/second_factor/verify_yubikey_second_factor.html.twig', [
111
            'form' => $form->createView(),
112
            'cancelForm' => $cancelForm->createView(),
113
        ]);
114
    }
115
116
    #[Route('/verify-sms', name: 'verify_sms')]
117
    public function verifySms(): Response
118
    {
119
        $command = new SendSmsChallengeCommand();
120
        $form = $this->createForm(SendSmsChallengeType::class, $command, [
121
            'action' => '#',
122
        ]);
123
124
        $cancelForm = $this->createForm(CancelAuthenticationType::class, null, [
125
            'action' => '#',
126
        ]);
127
128
        return $this->render('@default/second_factor/verify_sms_second_factor.html.twig', [
129
            'form' => $form->createView(),
130
            'cancelForm' => $cancelForm->createView(),
131
            'phoneNumber' => '+31612345678',
132
            'otpRequestsRemaining' => 3,
133
            'maximumOtpRequests' => 3,
134
        ]);
135
    }
136
137
    #[Route('/verify-sms-challenge', name: 'verify_sms_challenge')]
138
    public function verifySmsChallenge(): Response
139
    {
140
        $form = $this->createForm(VerifySmsChallengeType::class, null, [
141
            'action' => '#',
142
        ]);
143
144
        $cancelForm = $this->createForm(CancelAuthenticationType::class, null, [
145
            'action' => '#',
146
        ]);
147
148
        return $this->render('@default/second_factor/verify_sms_second_factor_challenge.html.twig', [
149
            'form' => $form->createView(),
150
            'cancelForm' => $cancelForm->createView(),
151
            'phoneNumber' => '+31612345678',
152
            'otpRequestsRemaining' => 2,
153
            'maximumOtpRequests' => 3,
154
        ]);
155
    }
156
157
    #[Route('/saml-consume-assertion', name: 'saml_consume_assertion')]
158
    public function samlConsumeAssertion(): Response
159
    {
160
        return $this->render('@default/saml_proxy/consume_assertion.html.twig', [
161
            'acu' => 'https://service-provider.example.org/acs',
162
            'response' => base64_encode('<samlp:Response>Mock SAML Response</samlp:Response>'),
163
            'relayState' => 'mock-relay-state-12345',
164
        ]);
165
    }
166
167
    #[Route('/saml-recoverable-error', name: 'saml_recoverable_error')]
168
    public function samlRecoverableError(): Response
169
    {
170
        return $this->render('@default/saml_proxy/recoverable_error.html.twig', [
171
            'acu' => 'https://service-provider.example.org/acs',
172
            'response' => base64_encode('<samlp:Response>Mock Error Response</samlp:Response>'),
173
            'relayState' => 'mock-relay-state-12345',
174
        ]);
175
    }
176
177
    #[Route('/saml-unprocessable-response', name: 'saml_unprocessable_response')]
178
    public function samlUnprocessableResponse(): Response
179
    {
180
        return $this->render('@default/saml_proxy/unprocessable_response.html.twig', [
181
            'acu' => 'https://service-provider.example.org/acs',
182
            'response' => base64_encode('<samlp:Response>Mock Error Response</samlp:Response>'),
183
            'relayState' => 'mock-relay-state-12345',
184
        ]);
185
    }
186
187
    #[Route('/gateway-consume-assertion', name: 'gateway_consume_assertion')]
188
    public function gatewayConsumeAssertion(): Response
189
    {
190
        return $this->render('@default/gateway/consume_assertion.html.twig', [
191
            'acu' => 'https://service-provider.example.org/acs',
192
            'response' => base64_encode('<samlp:Response>Mock SAML Response</samlp:Response>'),
193
            'relayState' => 'mock-relay-state-12345',
194
        ]);
195
    }
196
197
    #[Route('/gateway-unprocessable-response', name: 'gateway_unprocessable_response')]
198
    public function gatewayUnprocessableResponse(): Response
199
    {
200
        return $this->render('@default/gateway/unprocessable_response.html.twig', [
201
            'acu' => 'https://service-provider.example.org/acs',
202
            'response' => base64_encode('<samlp:Response>Mock Error Response</samlp:Response>'),
203
            'relayState' => 'mock-relay-state-12345',
204
        ]);
205
    }
206
207
    #[Route('/adfs-consume-assertion', name: 'adfs_consume_assertion')]
208
    public function adfsConsumeAssertion(): Response
209
    {
210
        $adfs = AdfsResponse::fromValues('ADFS.SCSA', '<EncryptedData>Mock Context</EncryptedData>');
211
212
        return $this->render('@default/adfs/consume_assertion.html.twig', [
213
            'acu' => 'https://adfs.example.org/adfs/ls/',
214
            'samlResponse' => base64_encode('<samlp:Response>Mock ADFS SAML Response</samlp:Response>'),
215
            'adfs' => $adfs,
216
        ]);
217
    }
218
219
    #[Route('/adfs-login', name: 'adfs_login')]
220
    public function adfsLogin(): Response
221
    {
222
        $adfs = AdfsResponse::fromValues('ADFS.SCSA', '<EncryptedData>Mock Context</EncryptedData>');
223
224
        return $this->render('@test_resources/adfs_login.html.twig', [
225
            'ssoUrl' => 'https://gateway.example.org/second-factor-only/single-sign-on',
226
            'authNRequest' => base64_encode('<samlp:AuthnRequest>Mock AuthN Request</samlp:AuthnRequest>'),
227
            'adfs' => $adfs,
228
        ]);
229
    }
230
231
    #[Route('/error-404', name: 'error_404')]
232
    public function error404(): Response
233
    {
234
        return $this->render('@Twig/Exception/error404.html.twig', [
235
            'status_code' => 404,
236
            'status_text' => 'Not Found',
237
        ]);
238
    }
239
240
    #[Route('/error-general', name: 'error_general')]
241
    public function errorGeneral(): Response
242
    {
243
        return $this->render('@Twig/Exception/error.html.twig', [
244
            'status_code' => 500,
245
            'status_text' => 'Internal Server Error',
246
        ]);
247
    }
248
249
    private function createMockSecondFactors(): array
250
    {
251
        $factors = [];
252
253
        $factors[] = new MockSecondFactor(
254
            id: 'mock-sf-id-yubikey',
255
            identityId: 'mock-identity-id-1',
256
            nameId: 'urn:collab:person:example.org:jdoe',
257
            institution: 'example.org',
258
            displayLocale: 'en_GB',
259
            secondFactorId: 'mock-yubikey-sf-id',
260
            secondFactorType: 'yubikey',
261
            secondFactorIdentifier: 'ccccccbcgujh',
262
            identityVetted: true,
263
        );
264
265
        $factors[] = new MockSecondFactor(
266
            id: 'mock-sf-id-sms',
267
            identityId: 'mock-identity-id-1',
268
            nameId: 'urn:collab:person:example.org:jdoe',
269
            institution: 'example.org',
270
            displayLocale: 'en_GB',
271
            secondFactorId: 'mock-sms-sf-id',
272
            secondFactorType: 'sms',
273
            secondFactorIdentifier: '+31612345678',
274
            identityVetted: true,
275
        );
276
277
        $factors[] = new MockSecondFactor(
278
            id: 'mock-sf-id-tiqr',
279
            identityId: 'mock-identity-id-1',
280
            nameId: 'urn:collab:person:example.org:jdoe',
281
            institution: 'example.org',
282
            displayLocale: 'en_GB',
283
            secondFactorId: 'mock-tiqr-sf-id',
284
            secondFactorType: 'tiqr',
285
            secondFactorIdentifier: 'jdoe-tiqr-account',
286
            identityVetted: true,
287
        );
288
289
        return $factors;
290
    }
291
}
292