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()); |
|
|
|
|
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
|
|
|
|
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: