ACSUrlValidatorAction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 9
dl 0
loc 41
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A doExecute() 0 33 4
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-IDP package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the GPL-3 license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\Idp\Action\Profile\Inbound\AuthnRequest;
13
14
use LightSaml\Action\Profile\AbstractProfileAction;
15
use LightSaml\Context\Profile\Helper\LogHelper;
16
use LightSaml\Context\Profile\Helper\MessageContextHelper;
17
use LightSaml\Context\Profile\ProfileContext;
18
use LightSaml\Error\LightSamlValidationException;
19
20
class ACSUrlValidatorAction extends AbstractProfileAction
21
{
22
    /**
23
     * @param ProfileContext $context
24
     *
25
     * @return void
26
     */
27
    protected function doExecute(ProfileContext $context)
28
    {
29
        $authnRequest = MessageContextHelper::asAuthnRequest($context->getInboundContext());
0 ignored issues
show
Bug introduced by
It seems like $context->getInboundContext() can be null; however, asAuthnRequest() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
30
31
        if (false == $authnRequest->getAssertionConsumerServiceURL()) {
32
            return;
33
        }
34
35
        $spEntityDescriptor = $context->getPartyEntityDescriptor();
36
37
        foreach ($spEntityDescriptor->getAllSpSsoDescriptors() as $sp) {
38
            if ($sp->getAllAssertionConsumerServicesByUrl($authnRequest->getAssertionConsumerServiceURL())) {
39
                $this->logger->debug(
40
                    sprintf(
41
                        'AuthnRequest has assertion consumer url "%s" that belongs to entity "%s"',
42
                        $authnRequest->getAssertionConsumerServiceURL(),
43
                        $spEntityDescriptor->getEntityID()
44
                    ),
45
                    LogHelper::getActionContext($context, $this)
46
                );
47
48
                return;
49
            }
50
        }
51
52
        $message = sprintf(
53
            "Invalid ACS Url '%s' for '%s' entity",
54
            $authnRequest->getAssertionConsumerServiceURL(),
55
            $spEntityDescriptor->getEntityID()
56
        );
57
        $this->logger->emergency($message, LogHelper::getActionErrorContext($context, $this));
58
        throw new LightSamlValidationException($message);
59
    }
60
}
61