1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace flipbox\saml\core\services\messages; |
8
|
|
|
|
9
|
|
|
use craft\base\Component; |
10
|
|
|
use flipbox\saml\core\models\SettingsInterface; |
11
|
|
|
use flipbox\saml\core\records\AbstractProvider; |
12
|
|
|
use SAML2\Constants; |
13
|
|
|
use SAML2\LogoutRequest; |
|
|
|
|
14
|
|
|
use SAML2\LogoutResponse as SamlLogoutResponse; |
15
|
|
|
use SAML2\XML\saml\Issuer; |
16
|
|
|
use yii\base\Event; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class AbstractLogoutResponse |
20
|
|
|
* @package flipbox\saml\core\services\messages |
21
|
|
|
*/ |
22
|
|
|
class LogoutResponse extends Component |
23
|
|
|
{ |
24
|
|
|
const EVENT_AFTER_MESSAGE_CREATED = 'eventAfterMessageCreated'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritdoc |
28
|
|
|
*/ |
29
|
|
|
public function create( |
30
|
|
|
LogoutRequest $request, |
31
|
|
|
AbstractProvider $theirProvider, |
32
|
|
|
AbstractProvider $ourProvider |
33
|
|
|
) { |
34
|
|
|
$logout = new SamlLogoutResponse(); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Set remote destination |
38
|
|
|
*/ |
39
|
|
|
$logout->setDestination( |
40
|
|
|
$theirProvider->getType() === SettingsInterface::SP ? |
41
|
|
|
$theirProvider->firstSpSloService( |
42
|
|
|
)->getLocation() : |
43
|
|
|
$theirProvider->firstIdpSloService( |
44
|
|
|
)->getLocation() |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Set session id |
49
|
|
|
*/ |
50
|
|
|
$logout->setInResponseTo( |
51
|
|
|
$request->getSessionIndex() |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$logout->setRelayState( |
55
|
|
|
$request->getRelayState() |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Set issuer |
60
|
|
|
*/ |
61
|
|
|
$logout->setIssuer( |
62
|
|
|
$issuer = new Issuer() |
63
|
|
|
); |
64
|
|
|
$issuer->setValue( |
65
|
|
|
$ourProvider->getEntityId() |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Sign the message |
70
|
|
|
*/ |
71
|
|
|
if ($ourProvider->keychain) { |
72
|
|
|
$logout->setSignatureKey( |
73
|
|
|
$ourProvider->keychainPrivateXmlSecurityKey() |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Kick off event here so people can manipulate this object if needed |
79
|
|
|
*/ |
80
|
|
|
$event = new Event(); |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* request |
84
|
|
|
*/ |
85
|
|
|
$event->sender = $request; |
86
|
|
|
/** |
87
|
|
|
* response |
88
|
|
|
*/ |
89
|
|
|
$event->data = $logout; |
90
|
|
|
$this->trigger(static::EVENT_AFTER_MESSAGE_CREATED, $event); |
91
|
|
|
|
92
|
|
|
return $logout; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: