Completed
Push — feature/refactor-gateway-contr... ( 4996d0...48680d )
by
unknown
02:33
created

sendSecondFactorVerificationAuthnRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 9.44
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Surfnet\StepupGateway\SamlStepupProviderBundle\Service;
4
5
use Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger;
6
use Surfnet\SamlBundle\SAML2\AuthnRequest;
7
use Surfnet\SamlBundle\SAML2\AuthnRequestFactory;
8
use Surfnet\StepupGateway\GatewayBundle\Saml\ResponseContext;
9
use Surfnet\StepupGateway\SamlStepupProviderBundle\Provider\Provider;
10
11
class SecondFactorVerificationService
12
{
13
    /** @var SamlAuthenticationLogger */
14
    private $samlLogger;
15
16
    /** @var ResponseContext */
17
    private $responseContext;
18
19
    /**
20
     * SecondFactorVerificationService constructor.
21
     * @param SamlAuthenticationLogger $samlLogger
22
     * @param ResponseContext $responseContext
23
     */
24
    public function __construct(SamlAuthenticationLogger $samlLogger, ResponseContext $responseContext)
25
    {
26
        $this->samlLogger = $samlLogger;
27
        $this->responseContext = $responseContext;
28
    }
29
30
    /**
31
     * Proxy a GSSP authentication request to the remote GSSP SSO endpoint.
32
     *
33
     * The user is about to be sent to the remote GSSP application for
34
     * registration. Verification is not initiated with a SAML AUthnRequest,
35
     * see sendSecondFactorVerificationAuthnRequestAction().
36
     *
37
     * The service provider in this context is SelfService (when registering
38
     * a token) or RA (when vetting a token).
39
     *
40
     * @param Provider $provider
41
     * @param ResponseContext $responseContext
0 ignored issues
show
Bug introduced by
There is no parameter named $responseContext. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
42
     * @param string $subjectNameId
43
     * @return AuthnRequest
44
     */
45
    public function sendSecondFactorVerificationAuthnRequest(Provider $provider, $subjectNameId)
46
    {
47
        $stateHandler = $provider->getStateHandler();
48
49
        $originalRequestId = $this->responseContext->getInResponseTo();
50
51
        $authnRequest = AuthnRequestFactory::createNewRequest(
52
            $provider->getServiceProvider(),
53
            $provider->getRemoteIdentityProvider()
54
        );
55
        $authnRequest->setSubject($subjectNameId);
56
57
        $stateHandler
58
            ->setRequestId($originalRequestId)
59
            ->setGatewayRequestId($authnRequest->getRequestId())
60
            ->setSubject($subjectNameId)
61
            ->markRequestAsSecondFactorVerification();
62
63
        /** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */
64
        $logger = $this->samlLogger->forAuthentication($originalRequestId);
65
        $logger->notice(sprintf(
66
            'Sending AuthnRequest to verify Second Factor with request ID: "%s" to GSSP "%s" at "%s" for subject "%s"',
67
            $authnRequest->getRequestId(),
68
            $provider->getName(),
69
            $provider->getRemoteIdentityProvider()->getSsoUrl(),
70
            $subjectNameId
71
        ));
72
73
        return $authnRequest;
74
    }
75
}
76