|
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\HTTPRedirect; |
|
15
|
|
|
use SAML2\LogoutRequest as SamlLogoutRequest; |
|
16
|
|
|
use SAML2\XML\saml\Issuer; |
|
17
|
|
|
use SAML2\XML\saml\NameID; |
|
18
|
|
|
use yii\base\Event; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class LogoutRequest |
|
22
|
|
|
* @package flipbox\saml\core\services\messages |
|
23
|
|
|
*/ |
|
24
|
|
|
class LogoutRequest extends Component |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
const EVENT_AFTER_MESSAGE_CREATED = 'eventAfterMessageCreated'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param AbstractProvider $theirProvider |
|
32
|
|
|
* @param AbstractProvider $ourProvider |
|
33
|
|
|
* @param AbstractProviderIdentity $identity |
|
34
|
|
|
* @return SamlLogoutRequest |
|
35
|
|
|
* @throws \Exception |
|
36
|
|
|
*/ |
|
37
|
|
|
public function create( |
|
38
|
|
|
AbstractProvider $theirProvider, |
|
39
|
|
|
AbstractProvider $ourProvider, |
|
40
|
|
|
AbstractProviderIdentity $identity, |
|
41
|
|
|
string $relayState = null |
|
42
|
|
|
) { |
|
43
|
|
|
|
|
44
|
|
|
$logout = new SamlLogoutRequest(); |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Set remote destination |
|
48
|
|
|
*/ |
|
49
|
|
|
$logout->setDestination( |
|
50
|
|
|
$theirProvider->getType() === SettingsInterface::SP ? |
|
51
|
|
|
$theirProvider->firstSpSloService()->getLocation() : |
|
52
|
|
|
$theirProvider->firstIdpSloService()->getLocation() |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Set session id |
|
57
|
|
|
*/ |
|
58
|
|
|
$logout->setSessionIndex($identity->sessionId); |
|
59
|
|
|
|
|
60
|
|
|
$logout->setNotOnOrAfter( |
|
61
|
|
|
(new \DateTime('+5 minutes'))->getTimestamp() |
|
62
|
|
|
); |
|
63
|
|
|
$logout->setIssueInstant( |
|
64
|
|
|
(new \DateTime())->getTimestamp() |
|
65
|
|
|
); |
|
66
|
|
|
$logout->setConsent( |
|
67
|
|
|
Constants::CONSENT_UNSPECIFIED |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
$logout->setRelayState( |
|
71
|
|
|
$relayState |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Set NameId |
|
76
|
|
|
*/ |
|
77
|
|
|
$logout->setNameID( |
|
78
|
|
|
$nameId = new NameID() |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
$nameId->setValue($identity->nameId); |
|
|
|
|
|
|
82
|
|
|
$nameId->setFormat(Constants::NAMEID_EMAIL_ADDRESS); |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Set issuer |
|
86
|
|
|
*/ |
|
87
|
|
|
$logout->setIssuer( |
|
88
|
|
|
$issuer = new Issuer() |
|
89
|
|
|
); |
|
90
|
|
|
$issuer->setValue( |
|
91
|
|
|
$ourProvider->getEntityId() |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Sign the message |
|
96
|
|
|
*/ |
|
97
|
|
|
if ($ourProvider->keychain) { |
|
98
|
|
|
$logout->setSignatureKey( |
|
99
|
|
|
$ourProvider->keychainPrivateXmlSecurityKey() |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
$logout->setCertificates([ |
|
103
|
|
|
$ourProvider->keychain->certificate |
|
104
|
|
|
]); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Kick off event here so people can manipulate this object if needed |
|
109
|
|
|
*/ |
|
110
|
|
|
$event = new Event(); |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* response |
|
114
|
|
|
*/ |
|
115
|
|
|
$event->data = $logout; |
|
116
|
|
|
$this->trigger(static::EVENT_AFTER_MESSAGE_CREATED, $event); |
|
117
|
|
|
|
|
118
|
|
|
return $logout; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function createRedirectUrl( |
|
122
|
|
|
AbstractProvider $theirProvider, |
|
123
|
|
|
AbstractProvider $ourProvider, |
|
124
|
|
|
AbstractProviderIdentity $identity, |
|
125
|
|
|
string $relayState = null |
|
126
|
|
|
) { |
|
127
|
|
|
return (new HTTPRedirect())->getRedirectURL( |
|
128
|
|
|
$this->create( |
|
129
|
|
|
$theirProvider, |
|
130
|
|
|
$ourProvider, |
|
131
|
|
|
$identity, |
|
132
|
|
|
$relayState |
|
133
|
|
|
) |
|
134
|
|
|
); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
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@propertyannotation 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.