protected function findBestMatchingToken(TokenInterface $managerToken, array $sessionTokens): TokenInterface
    {
        $matchingSessionTokens = array_filter($sessionTokens, function (TokenInterface $sessionToken) use ($managerToken) {
            return ($sessionToken->getAuthenticationProviderName() === $managerToken->getAuthenticationProviderName());
        });

        if (empty($matchingSessionTokens)) {
            return $managerToken;
        }

        $matchingSessionToken = reset($matchingSessionTokens);

        $session = $this->sessionManager->getCurrentSession();
        $this->securityLogger->debug(
            sprintf(
                'Session %s contains auth token %s for provider %s. Status: %s',
                $session->getId(),
                get_class($matchingSessionToken),
                $matchingSessionToken->getAuthenticationProviderName(),
                $this->tokenStatusLabels[$matchingSessionToken->getAuthenticationStatus()]
            ), LogEnvironment::fromMethodName(__METHOD__)
        );

        return $matchingSessionToken;
    }