1 | <?php |
||
32 | class ResponseContext |
||
33 | { |
||
34 | /** |
||
35 | * @var IdentityProvider |
||
36 | */ |
||
37 | private $hostedIdentityProvider; |
||
38 | |||
39 | /** |
||
40 | * @var \Surfnet\StepupGateway\GatewayBundle\Service\SamlEntityService |
||
41 | */ |
||
42 | private $samlEntityService; |
||
43 | |||
44 | /** |
||
45 | * @var ProxyStateHandler |
||
46 | */ |
||
47 | private $stateHandler; |
||
48 | |||
49 | /** |
||
50 | * @var LoggerInterface |
||
51 | */ |
||
52 | private $logger; |
||
53 | |||
54 | /** |
||
55 | * @var DateTime |
||
56 | */ |
||
57 | private $generationTime; |
||
58 | |||
59 | /** |
||
60 | * @var IdentityProvider|null |
||
61 | */ |
||
62 | private $authenticatingIdp; |
||
63 | |||
64 | /** |
||
65 | * @var ServiceProvider |
||
66 | */ |
||
67 | private $targetServiceProvider; |
||
68 | |||
69 | public function __construct( |
||
81 | |||
82 | /** |
||
83 | * @return string |
||
84 | */ |
||
85 | public function getDestination() |
||
91 | |||
92 | /** |
||
93 | * @return string |
||
94 | */ |
||
95 | public function getDestinationForAdfs() |
||
101 | |||
102 | /** |
||
103 | * @return null|string |
||
104 | */ |
||
105 | public function getIssuer() |
||
109 | |||
110 | /** |
||
111 | * @return int |
||
112 | */ |
||
113 | public function getIssueInstant() |
||
117 | |||
118 | /** |
||
119 | * @return null|string |
||
120 | */ |
||
121 | public function getInResponseTo() |
||
125 | |||
126 | /** |
||
127 | * @return null|string |
||
128 | */ |
||
129 | public function getExpectedInResponseTo() |
||
133 | |||
134 | /** |
||
135 | * @return null|string |
||
136 | */ |
||
137 | public function getRequiredLoa() |
||
141 | |||
142 | /** |
||
143 | * @return IdentityProvider |
||
144 | */ |
||
145 | public function getIdentityProvider() |
||
149 | |||
150 | /** |
||
151 | * @return null|ServiceProvider |
||
152 | */ |
||
153 | public function getServiceProvider() |
||
163 | |||
164 | /** |
||
165 | * @return null|string |
||
166 | */ |
||
167 | public function getRelayState() |
||
171 | |||
172 | /** |
||
173 | * @param Assertion $assertion |
||
174 | */ |
||
175 | public function saveAssertion(Assertion $assertion) |
||
176 | { |
||
177 | // we pluck the NameId to make it easier to access it without having to reconstitute the assertion |
||
178 | $nameId = $assertion->getNameId(); |
||
179 | if (!is_null($nameId->value)) { |
||
180 | $this->stateHandler->saveIdentityNameId($nameId->value); |
||
181 | } |
||
182 | |||
183 | // same for the entityId of the authenticating Authority |
||
184 | $authenticatingAuthorities = $assertion->getAuthenticatingAuthority(); |
||
185 | if (!empty($authenticatingAuthorities)) { |
||
186 | $this->stateHandler->setAuthenticatingIdp(reset($authenticatingAuthorities)); |
||
187 | } |
||
188 | |||
189 | // And also attempt to save the user's schacHomeOrganization |
||
190 | $attributes = $assertion->getAttributes(); |
||
191 | if (!empty($attributes['urn:mace:terena.org:attribute-def:schacHomeOrganization'])) { |
||
192 | $schacHomeOrganization = $attributes['urn:mace:terena.org:attribute-def:schacHomeOrganization']; |
||
193 | $this->stateHandler->setSchacHomeOrganization(reset($schacHomeOrganization)); |
||
194 | } |
||
195 | |||
196 | $this->stateHandler->saveAssertion($assertion->toXML()->ownerDocument->saveXML()); |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @return Assertion |
||
201 | */ |
||
202 | public function reconstituteAssertion() |
||
210 | |||
211 | /** |
||
212 | * @return null|string |
||
213 | */ |
||
214 | public function getIdentityNameId() |
||
218 | |||
219 | /** |
||
220 | * Return the lower-cased schacHomeOrganization value from the assertion. |
||
221 | * |
||
222 | * Comparisons on SHO values should always be case insensitive. Stepup |
||
223 | * configuration always contains SHO values lower-cased, so this getter |
||
224 | * can be used to compare the SHO with configured values. |
||
225 | * |
||
226 | * @see StepUpAuthenticationService::resolveHighestRequiredLoa() |
||
227 | * |
||
228 | * @return null|string |
||
229 | */ |
||
230 | public function getNormalizedSchacHomeOrganization() |
||
236 | |||
237 | /** |
||
238 | * @return null|IdentityProvider |
||
239 | */ |
||
240 | public function getAuthenticatingIdp() |
||
258 | |||
259 | /** |
||
260 | * @param SecondFactor $secondFactor |
||
261 | */ |
||
262 | public function saveSelectedSecondFactor(SecondFactor $secondFactor) |
||
268 | |||
269 | /** |
||
270 | * @return null|string |
||
271 | */ |
||
272 | public function getSelectedSecondFactor() |
||
276 | |||
277 | public function markSecondFactorVerified() |
||
281 | |||
282 | /** |
||
283 | * @return bool |
||
284 | */ |
||
285 | public function isSecondFactorVerified() |
||
289 | |||
290 | public function getResponseAction() |
||
294 | |||
295 | /** |
||
296 | * Resets some state after the response is sent |
||
297 | * (e.g. resets which second factor was selected and whether it was verified). |
||
298 | */ |
||
299 | public function responseSent() |
||
304 | } |
||
305 |