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 (!empty($attributes['urn:mace:terena.org:attribute-def:schacHomeOrganization'])) { |
||
178 | $schacHomeOrganization = $attributes['urn:mace:terena.org:attribute-def:schacHomeOrganization']; |
||
179 | $this->stateHandler->setSchacHomeOrganization(reset($schacHomeOrganization)); |
||
180 | } |
||
181 | |||
182 | $this->stateHandler->saveAssertion($assertion->toXML()->ownerDocument->saveXML()); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @return SAML2_Assertion |
||
187 | */ |
||
188 | public function reconstituteAssertion() |
||
196 | |||
197 | /** |
||
198 | * @return null|string |
||
199 | */ |
||
200 | public function getIdentityNameId() |
||
204 | |||
205 | /** |
||
206 | * Return the lower-cased schacHomeOrganization value from the assertion. |
||
207 | * |
||
208 | * Comparisons on SHO values should always be case insensitive. Stepup |
||
209 | * configuration always contains SHO values lower-cased, so this getter |
||
210 | * can be used to compare the SHO with configured values. |
||
211 | * |
||
212 | * @see StepUpAuthenticationService::resolveHighestRequiredLoa() |
||
213 | * |
||
214 | * @return null|string |
||
215 | */ |
||
216 | public function getNormalizedSchacHomeOrganization() |
||
222 | |||
223 | /** |
||
224 | * @return null|IdentityProvider |
||
225 | */ |
||
226 | public function getAuthenticatingIdp() |
||
244 | |||
245 | /** |
||
246 | * @param SecondFactor $secondFactor |
||
247 | */ |
||
248 | public function saveSelectedSecondFactor(SecondFactor $secondFactor) |
||
254 | |||
255 | /** |
||
256 | * @return null|string |
||
257 | */ |
||
258 | public function getSelectedSecondFactor() |
||
262 | |||
263 | public function markSecondFactorVerified() |
||
267 | |||
268 | /** |
||
269 | * @return bool |
||
270 | */ |
||
271 | public function isSecondFactorVerified() |
||
275 | |||
276 | public function getResponseAction() |
||
280 | |||
281 | /** |
||
282 | * Resets some state after the response is sent |
||
283 | * (e.g. resets which second factor was selected and whether it was verified). |
||
284 | */ |
||
285 | public function responseSent() |
||
290 | } |
||
291 |