|
17 | 17 | use OCA\User_SAML\Exceptions\UserFilterViolationException; |
18 | 18 | use OCA\User_SAML\Helper\TXmlHelper; |
19 | 19 | use OCA\User_SAML\SAMLSettings; |
| 20 | +use OCA\User_SAML\Service\SessionService; |
20 | 21 | use OCA\User_SAML\UserBackend; |
21 | 22 | use OCA\User_SAML\UserData; |
22 | 23 | use OCA\User_SAML\UserResolver; |
@@ -57,6 +58,7 @@ public function __construct( |
57 | 58 | private UserData $userData, |
58 | 59 | private ICrypto $crypto, |
59 | 60 | private ITrustedDomainHelper $trustedDomainHelper, |
| 61 | + private SessionService $sessionService, |
60 | 62 | ) { |
61 | 63 | parent::__construct($appName, $request); |
62 | 64 | } |
@@ -232,7 +234,7 @@ public function login(int $idp = 1): Http\RedirectResponse|Http\TemplateResponse |
232 | 234 | if (empty($ssoUrl)) { |
233 | 235 | $ssoUrl = $this->urlGenerator->getAbsoluteURL('/'); |
234 | 236 | } |
235 | | - $this->session->set('user_saml.samlUserData', $_SERVER); |
| 237 | + $this->sessionService->prepareEnvironmentBasedSession($_SERVER); |
236 | 238 | try { |
237 | 239 | $this->userData->setAttributes($this->session->get('user_saml.samlUserData')); |
238 | 240 | $this->autoprovisionIfPossible(); |
@@ -335,8 +337,8 @@ public function assertionConsumerService(): Http\RedirectResponse { |
335 | 337 | $AuthNRequestID = $data['AuthNRequestID']; |
336 | 338 | $idp = $data['Idp']; |
337 | 339 | // need to keep the IdP config ID during session lifetime (SAMLSettings::getPrefix) |
338 | | - $this->session->set('user_saml.Idp', $idp); |
339 | | - if (is_null($AuthNRequestID) || $AuthNRequestID === '' || is_null($idp)) { |
| 340 | + $this->sessionService->storeIdentityProviderInSession($idp); |
| 341 | + if (is_null($AuthNRequestID) || $AuthNRequestID === '') { |
340 | 342 | $this->logger->debug('Invalid auth payload', ['app' => 'user_saml']); |
341 | 343 | return new Http\RedirectResponse($this->urlGenerator->getAbsoluteURL('/')); |
342 | 344 | } |
@@ -383,14 +385,8 @@ public function assertionConsumerService(): Http\RedirectResponse { |
383 | 385 | return $response; |
384 | 386 | } |
385 | 387 |
|
386 | | - $this->session->set('user_saml.samlUserData', $auth->getAttributes()); |
387 | | - $this->session->set('user_saml.samlNameId', $auth->getNameId()); |
388 | | - $this->session->set('user_saml.samlNameIdFormat', $auth->getNameIdFormat()); |
389 | | - $this->session->set('user_saml.samlNameIdNameQualifier', $auth->getNameIdNameQualifier()); |
390 | | - $this->session->set('user_saml.samlNameIdSPNameQualifier', $auth->getNameIdSPNameQualifier()); |
391 | | - $this->session->set('user_saml.samlSessionIndex', $auth->getSessionIndex()); |
392 | | - $this->session->set('user_saml.samlSessionExpiration', $auth->getSessionExpiration()); |
393 | | - $this->logger->debug('Session values set', ['app' => 'user_saml']); |
| 388 | + $this->sessionService->prepareSession($auth); |
| 389 | + |
394 | 390 | try { |
395 | 391 | $user = $this->userResolver->findExistingUser($this->userBackend->getCurrentUserId()); |
396 | 392 | $firstLogin = $user->updateLastLoginTimestamp(); |
@@ -510,14 +506,14 @@ public function singleLogoutService(): Http\RedirectResponse { |
510 | 506 | */ |
511 | 507 | private function tryProcessSLOResponse(?int $idp): array { |
512 | 508 | $idps = ($idp !== null) ? [$idp] : array_keys($this->samlSettings->getListOfIdps()); |
513 | | - foreach ($idps as $idp) { |
| 509 | + foreach ($idps as $identityProviderId) { |
514 | 510 | try { |
515 | | - $auth = new Auth($this->samlSettings->getOneLoginSettingsArray($idp)); |
| 511 | + $auth = new Auth($this->samlSettings->getOneLoginSettingsArray($identityProviderId)); |
516 | 512 | // validator (called with processSLO()) needs an XML entity loader |
517 | 513 | $targetUrl = $this->callWithXmlEntityLoader(fn (): string => $auth->processSLO( |
518 | 514 | true, // do not let processSLO to delete the entire session. Let userSession->logout do the job |
519 | 515 | null, |
520 | | - $this->samlSettings->usesSloWebServerDecode($idp), |
| 516 | + $this->samlSettings->usesSloWebServerDecode($identityProviderId), |
521 | 517 | null, |
522 | 518 | true |
523 | 519 | )); |
|
0 commit comments