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 flipbox\saml\core\records\AbstractProviderIdentity; |
13
|
|
|
use SAML2\Constants; |
14
|
|
|
use SAML2\XML\saml\NameID; |
15
|
|
|
use yii\base\Event; |
16
|
|
|
use SAML2\LogoutRequest as SamlLogoutRequest; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class LogoutRequest |
20
|
|
|
* @package flipbox\saml\core\services\messages |
21
|
|
|
*/ |
22
|
|
|
class LogoutRequest extends Component |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
const EVENT_AFTER_MESSAGE_CREATED = 'eventAfterMessageCreated'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param AbstractProvider $theirProvider |
30
|
|
|
* @param AbstractProvider $ourProvider |
31
|
|
|
* @param AbstractProviderIdentity $identity |
32
|
|
|
* @return SamlLogoutRequest |
33
|
|
|
* @throws \Exception |
34
|
|
|
*/ |
35
|
|
|
public function create( |
36
|
|
|
AbstractProvider $theirProvider, |
37
|
|
|
AbstractProvider $ourProvider, |
38
|
|
|
AbstractProviderIdentity $identity, |
39
|
|
|
string $relayState = '' |
40
|
|
|
) |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
$logout = new SamlLogoutRequest(); |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Set remote destination |
47
|
|
|
*/ |
48
|
|
|
$logout->setDestination( |
49
|
|
|
$theirProvider->getType() === SettingsInterface::SP ? |
50
|
|
|
$theirProvider->firstSpSloService(Constants::BINDING_HTTP_POST)->getResponseLocation() : |
51
|
|
|
$theirProvider->firstIdpSloService(Constants::BINDING_HTTP_POST)->getResponseLocation() |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set session id |
56
|
|
|
*/ |
57
|
|
|
$logout->setSessionIndex($identity->sessionId); |
58
|
|
|
|
59
|
|
|
$logout->setNotOnOrAfter( |
60
|
|
|
(new \DateTime('+5 minutes'))->getTimestamp() |
61
|
|
|
); |
62
|
|
|
$logout->setIssueInstant( |
63
|
|
|
(new \DateTime())->getTimestamp() |
64
|
|
|
); |
65
|
|
|
$logout->setConsent( |
66
|
|
|
Constants::CONSENT_UNSPECIFIED |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$logout->setRelayState( |
70
|
|
|
$relayState |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Set NameId |
75
|
|
|
*/ |
76
|
|
|
$logout->setNameID( |
77
|
|
|
$nameId = new NameID() |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$nameId->setValue($identity->nameId); |
|
|
|
|
81
|
|
|
$nameId->setFormat(Constants::NAMEID_EMAIL_ADDRESS); |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Set issuer |
85
|
|
|
*/ |
86
|
|
|
$logout->setIssuer( |
87
|
|
|
$ourProvider->getEntityId() |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Sign the message |
92
|
|
|
*/ |
93
|
|
|
if ($ourProvider->keychain) { |
94
|
|
|
$logout->setSignatureKey( |
95
|
|
|
$ourProvider->keychainPrivateXmlSecurityKey() |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Kick off event here so people can manipulate this object if needed |
102
|
|
|
*/ |
103
|
|
|
$event = new Event(); |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* response |
107
|
|
|
*/ |
108
|
|
|
$event->data = $logout; |
109
|
|
|
$this->trigger(static::EVENT_AFTER_MESSAGE_CREATED, $event); |
110
|
|
|
|
111
|
|
|
return $logout; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.