/** * Checks for User's cat_username in his libCards to see, if provided $cat_username * matches the libCard's cat_username unless the prefix of cat_username doesn't match. * * If the provided $cat_username differs from libCard's cat_username, it is than updated. * * @param UserRow $user * @param string $prefix * @param string $cat_username * * @return void */ protected function updateIdentityCatUsername(UserRow $user, $prefix, $cat_username) { $resultSet = $user->getLibraryCards(); $libCardToSave = false; foreach ($resultSet as $libraryCard) { $libCard_cat_username = $libraryCard->cat_username; $libCard_prefix = explode(static::SEPARATOR, $libCard_cat_username)[0]; // We are performing the check of corresponding institutions by comparing the prefix // from shibboleth.ini config section name with MultiBackend's source from cat_username if ($libCard_prefix === $prefix) { // now check if the cat_username matches .. if ($libCard_cat_username !== $cat_username) { // else update it $libraryCard->cat_username = $cat_username; if (!$libCardToSave) { $libCardToSave = $libraryCard; } else { // There can be more matches due to possibility of having different accounts with identical cat_username throw new AuthException('Cannot update cat_username provided by IdP while you have more identities with identical cat_username. Please disconnect one of these identities and try it again.'); } } } } // It is instanceof UserCard only it there was a cat_username mismatch .. if ($libCardToSave instanceof UserCard) { $libCardToSave->save(); // We need to update user table with the new cat_username $user->activateLibraryCardRow($libCardToSave); } }