Passed
Push — master ( c4afc2...9cde23 )
by Pieter van der
27:49 queued 12:42
created

AuthenticationRequestFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 31
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createSecondFactorRequest() 0 11 1
A __construct() 0 6 1
1
<?php
2
3
/**
4
 * Copyright 2022 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens;
20
21
use Surfnet\SamlBundle\Entity\IdentityProvider;
22
use Surfnet\SamlBundle\Entity\ServiceProvider;
23
use Surfnet\SamlBundle\SAML2\AuthnRequest;
24
use Surfnet\SamlBundle\SAML2\AuthnRequestFactory;
25
use Surfnet\StepupBundle\Value\Loa;
26
27
class AuthenticationRequestFactory
28
{
29
    /**
30
     * @var ServiceProvider
31
     */
32
    private $serviceProvider;
33
34
    /**
35
     * @var IdentityProvider
36
     */
37
    private $identityProvider;
38
39
    public function __construct(
40
        ServiceProvider $serviceProvider,
41
        IdentityProvider $identityProvider
42
    ) {
43
        $this->serviceProvider = $serviceProvider;
44
        $this->identityProvider = $identityProvider;
45
    }
46
47
    public function createSecondFactorRequest(string $nameId, Loa $loa): AuthnRequest
48
    {
49
        $authenticationRequest = AuthnRequestFactory::createNewRequest(
50
            $this->serviceProvider,
51
            $this->identityProvider
52
        );
53
54
        $authenticationRequest->setSubject($nameId);
55
        $authenticationRequest->setAuthenticationContextClassRef((string) $loa);
56
57
        return $authenticationRequest;
58
    }
59
}
60