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;
    }
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;
    }
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 ; }
Tries to find a token matchting the given manager token in the session tokens, will return that or the manager token.

@param TokenInterface $managerToken
@param TokenInterface[] $sessionTokens
@return TokenInterface
@throws \Neos\Flow\Session\Exception\SessionNotStartedException
Tries to find a token matchting the given manager token in the session tokens will return that or the manager token .