1 | <?php |
||
31 | class ResponseContext |
||
32 | { |
||
33 | /** |
||
34 | * @var IdentityProvider |
||
35 | */ |
||
36 | private $hostedIdentityProvider; |
||
37 | |||
38 | /** |
||
39 | * @var \Surfnet\StepupGateway\GatewayBundle\Service\SamlEntityService |
||
40 | */ |
||
41 | private $samlEntityService; |
||
42 | |||
43 | /** |
||
44 | * @var ProxyStateHandler |
||
45 | */ |
||
46 | private $stateHandler; |
||
47 | |||
48 | /** |
||
49 | * @var DateTime |
||
50 | */ |
||
51 | private $generationTime; |
||
52 | |||
53 | /** |
||
54 | * @var IdentityProvider|null |
||
55 | */ |
||
56 | private $authenticatingIdp; |
||
57 | |||
58 | /** |
||
59 | * @var ServiceProvider |
||
60 | */ |
||
61 | private $targetServiceProvider; |
||
62 | |||
63 | public function __construct( |
||
73 | |||
74 | /** |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getDestination() |
||
87 | |||
88 | /** |
||
89 | * @return null|string |
||
90 | */ |
||
91 | public function getIssuer() |
||
95 | |||
96 | /** |
||
97 | * @return int |
||
98 | */ |
||
99 | public function getIssueInstant() |
||
103 | |||
104 | /** |
||
105 | * @return null|string |
||
106 | */ |
||
107 | public function getInResponseTo() |
||
111 | |||
112 | /** |
||
113 | * @return null|string |
||
114 | */ |
||
115 | public function getExpectedInResponseTo() |
||
119 | |||
120 | /** |
||
121 | * @return null|string |
||
122 | */ |
||
123 | public function getRequiredLoa() |
||
127 | |||
128 | /** |
||
129 | * @return IdentityProvider |
||
130 | */ |
||
131 | public function getIdentityProvider() |
||
135 | |||
136 | /** |
||
137 | * @return null|ServiceProvider |
||
138 | */ |
||
139 | public function getServiceProvider() |
||
149 | |||
150 | /** |
||
151 | * @return null|string |
||
152 | */ |
||
153 | public function getRelayState() |
||
157 | |||
158 | /** |
||
159 | * @param SAML2_Assertion $assertion |
||
160 | */ |
||
161 | public function saveAssertion(SAML2_Assertion $assertion) |
||
162 | { |
||
163 | // we pluck the NameId to make it easier to access it without having to reconstitute the assertion |
||
164 | $nameId = $assertion->getNameId(); |
||
165 | if (!empty($nameId['Value'])) { |
||
166 | $this->stateHandler->saveIdentityNameId($nameId['Value']); |
||
167 | } |
||
168 | |||
169 | // same for the entityId of the authenticating Authority |
||
170 | $authenticatingAuthorities = $assertion->getAuthenticatingAuthority(); |
||
171 | if (!empty($authenticatingAuthorities)) { |
||
172 | $this->stateHandler->setAuthenticatingIdp(reset($authenticatingAuthorities)); |
||
173 | } |
||
174 | |||
175 | // And also attempt to save the user's schacHomeOrganization |
||
176 | $attributes = $assertion->getAttributes(); |
||
177 | if (array_key_exists('urn:mace:terena.org:attribute-def:schacHomeOrganization', $attributes) && |
||
178 | !empty($attributes['urn:mace:terena.org:attribute-def:schacHomeOrganization']) |
||
179 | ) { |
||
180 | $schacHomeOrganization = $attributes['urn:mace:terena.org:attribute-def:schacHomeOrganization']; |
||
181 | $this->stateHandler->setSchacHomeOrganization(reset($schacHomeOrganization)); |
||
182 | } |
||
183 | |||
184 | $this->stateHandler->saveAssertion($assertion->toXML()->ownerDocument->saveXML()); |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * @return SAML2_Assertion |
||
189 | */ |
||
190 | public function reconstituteAssertion() |
||
191 | { |
||
192 | $assertionAsXML = $this->stateHandler->getAssertion(); |
||
193 | $assertionDocument = new DOMDocument(); |
||
194 | $assertionDocument->loadXML($assertionAsXML); |
||
195 | |||
196 | return new SAML2_Assertion($assertionDocument->documentElement); |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @return null|string |
||
201 | */ |
||
202 | public function getIdentityNameId() |
||
203 | { |
||
204 | return $this->stateHandler->getIdentityNameId(); |
||
205 | } |
||
206 | |||
207 | public function getSchacHomeOrganization() |
||
208 | { |
||
209 | return $this->stateHandler->getSchacHomeOrganization(); |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * @return null|IdentityProvider |
||
214 | */ |
||
215 | public function getAuthenticatingIdp() |
||
233 | |||
234 | /** |
||
235 | * @param SecondFactor $secondFactor |
||
236 | */ |
||
237 | public function saveSelectedSecondFactor(SecondFactor $secondFactor) |
||
243 | |||
244 | /** |
||
245 | * @return null|string |
||
246 | */ |
||
247 | public function getSelectedSecondFactor() |
||
251 | |||
252 | public function markSecondFactorVerified() |
||
256 | |||
257 | /** |
||
258 | * @return bool |
||
259 | */ |
||
260 | public function isSecondFactorVerified() |
||
264 | |||
265 | public function getResponseAction() |
||
269 | |||
270 | /** |
||
271 | * Resets some state after the response is sent |
||
272 | * (e.g. resets which second factor was selected and whether it was verified). |
||
273 | */ |
||
274 | public function responseSent() |
||
279 | } |
||
280 |