<commit_before><?php

namespace Oro\Bundle\UserBundle\Security;

use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

use Escape\WSSEAuthenticationBundle\Security\Core\Authentication\Provider\Provider;
use Escape\WSSEAuthenticationBundle\Security\Core\Authentication\Token\Token;

class WsseUserProvider extends Provider
{
    /**
     * Need to override parent's "private" declaration
     *
     * @var UserProviderInterface
     */
    protected $userProvider;

    /**
     * Constructor.
     *
     * @param UserProviderInterface    $userProvider    An UserProviderInterface instance
     * @param PasswordEncoderInterface $encoder         A PasswordEncoderInterface instance
     * @param string                   $nonceDir        The nonce dir
     * @param int                      $lifetime        The lifetime, in seconds
     */
    public function __construct(
        UserProviderInterface $userProvider,
        PasswordEncoderInterface $encoder,
        $nonceDir = null,
        $lifetime = 300
    ) {
        parent::__construct($userProvider, $encoder, $nonceDir, $lifetime);

        $this->userProvider = $userProvider;
    }

    /**
     * Authenticate API user by API key
     *
     * @param  TokenInterface          $token
     * @return Token
     * @throws AuthenticationException
     */
    public function authenticate(TokenInterface $token)
    {
        $user = $this->userProvider->loadUserByUsername($token->getUsername());

        if ($user && $user->getApi()) {
            if ($this->validateDigest(
                $user,
                $token->getAttribute('digest'),
                $token->getAttribute('nonce'),
                $token->getAttribute('created'),
                $user->getApi()->getApiKey()
            )) {
                $authToken = new Token($user->getRoles());

                $authToken->setUser($user);
                $authToken->setAuthenticated(true);

                return $authToken;
            }
        }

        throw new AuthenticationException('WSSE authentication failed.');
    }
}
<commit_msg>PIM-1852 : update WsseUserProvider (come from master)<commit_after><?php

namespace Oro\Bundle\UserBundle\Security;

use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

use Doctrine\Common\Cache\Cache;

use Escape\WSSEAuthenticationBundle\Security\Core\Authentication\Provider\Provider;
use Escape\WSSEAuthenticationBundle\Security\Core\Authentication\Token\Token;

class WsseUserProvider extends Provider
{
    /**
     * Need to override parent's "private" declaration
     *
     * @var UserProviderInterface
     */
    protected $userProvider;

    /**
     * Constructor.
     *
     * @param UserProviderInterface    $userProvider    An UserProviderInterface instance
     * @param PasswordEncoderInterface $encoder         A PasswordEncoderInterface instance
     * @param Cache                    $nonceCache      Cache instance
     * @param int                      $lifetime        The lifetime, in seconds
     */
    public function __construct(
        UserProviderInterface $userProvider,
        PasswordEncoderInterface $encoder,
        Cache $nonceCache,
        $lifetime = 300
    ) {
        parent::__construct($userProvider, $encoder, $nonceCache, $lifetime);

        $this->userProvider = $userProvider;
    }

    /**
     * Authenticate API user by API key
     *
     * @param  TokenInterface          $token
     * @return Token
     * @throws AuthenticationException
     */
    public function authenticate(TokenInterface $token)
    {
        $user = $this->userProvider->loadUserByUsername($token->getUsername());

        if ($user && $user->getApi()) {
            if ($this->validateDigest(
                $token->getAttribute('digest'),
                $token->getAttribute('nonce'),
                $token->getAttribute('created'),
                $user->getApi()->getApiKey(),
                $user->getSalt()
            )) {
                $authToken = new Token($user->getRoles());

                $authToken->setUser($user);
                $authToken->setAuthenticated(true);

                return $authToken;
            }
        }

        throw new AuthenticationException('WSSE authentication failed.');
    }
}

{'fraction_non_alphanumeric': 0.10316953839608593, 'fraction_numerical': 0.0021272069772388853, 'mean_word_length': 2.417151162790698, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '5321720', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1169, 'n_words': 232}