<commit_before><?php

/*
 * This file is part of the SensioLabs Connect package.
 *
 * (c) SensioLabs <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SensioLabs\Connect\Security\Authentication\Provider;

use SensioLabs\Connect\Security\Authentication\Token\ConnectToken;
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationServiceException;
use Symfony\Component\Security\Core\User\UserProviderInterface;

/**
 * ConnectAuthenticationProvider.
 *
 * @author <NAME> <<EMAIL>>
 */
class ConnectAuthenticationProvider implements AuthenticationProviderInterface
{
    private $userProvider;
    private $providerKey;

    public function __construct(UserProviderInterface $userProvider, $providerKey)
    {
        $this->userProvider = $userProvider;
        $this->providerKey = $providerKey;
    }

    public function authenticate(TokenInterface $token)
    {
        try {
            $localUser = $this->userProvider->loadUserByUsername($token->getUser());

            $authorizedToken = new ConnectToken($localUser, $token->getAccessToken(), $token->getApiUser(), $this->providerKey, $token->getScope(), $localUser->getRoles());
            $authorizedToken->setAttributes($token->getAttributes());

            return $authorizedToken;
        } catch (\Exception $repositoryProblem) {
            throw new AuthenticationServiceException($repositoryProblem->getMessage(), $token, 0, $repositoryProblem);
        }
    }

    public function supports(TokenInterface $token)
    {
        return $token instanceof ConnectToken;
    }
}<commit_msg>fixed compatibility with Symfony 2.2 (closes #22)<commit_after><?php

/*
 * This file is part of the SensioLabs Connect package.
 *
 * (c) SensioLabs <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SensioLabs\Connect\Security\Authentication\Provider;

use SensioLabs\Connect\Security\Authentication\Token\ConnectToken;
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationServiceException;
use Symfony\Component\Security\Core\User\UserProviderInterface;

/**
 * ConnectAuthenticationProvider.
 *
 * @author <NAME> <<EMAIL>>
 */
class ConnectAuthenticationProvider implements AuthenticationProviderInterface
{
    private $userProvider;
    private $providerKey;

    public function __construct(UserProviderInterface $userProvider, $providerKey)
    {
        $this->userProvider = $userProvider;
        $this->providerKey = $providerKey;
    }

    public function authenticate(TokenInterface $token)
    {
        try {
            $localUser = $this->userProvider->loadUserByUsername($token->getUser());

            $authorizedToken = new ConnectToken($localUser, $token->getAccessToken(), $token->getApiUser(), $this->providerKey, $token->getScope(), $localUser->getRoles());
            $authorizedToken->setAttributes($token->getAttributes());

            return $authorizedToken;
        } catch (\Exception $repositoryProblem) {
            if (!method_exists('Symfony\Component\Security\Core\Exception\AuthenticationServiceException', 'setToken')) {
                throw new AuthenticationServiceException($repositoryProblem->getMessage(), $token, 0, $repositoryProblem);
            } else {
                $e = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem);
                $e->setToken($token);

                throw $e;
            }
        }
    }

    public function supports(TokenInterface $token)
    {
        return $token instanceof ConnectToken;
    }
}
{'fraction_non_alphanumeric': 0.10866336633663366, 'fraction_numerical': 0.0017326732673267327, 'mean_word_length': 3.898181818181818, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4944834', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1002, 'n_words': 218}