Completed
Push — ezp27996-repository_remember_m... ( da1efc...c2e2a1 )
by
unknown
14:05
created

authenticate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 13
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the RememberMeRepositoryAuthenticationProvider class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\MVC\Symfony\Security\Authentication;
10
11
use eZ\Publish\API\Repository\Repository;
12
use Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider;
13
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
14
15
class RememberMeRepositoryAuthenticationProvider extends RememberMeAuthenticationProvider
16
{
17
    /**
18
     * @var \eZ\Publish\API\Repository\Repository
19
     */
20
    private $repository;
21
22
    public function setRepository(Repository $repository)
23
    {
24
        $this->repository = $repository;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function authenticate(TokenInterface $token)
31
    {
32
        $authenticatedToken = parent::authenticate($token);
33
        if (empty($authenticatedToken)) {
34
            return;
35
        }
36
37
        $this->repository->getPermissionResolver()->setCurrentUserReference(
38
            $authenticatedToken->getUser()->getAPIUser()
39
        );
40
41
        return $authenticatedToken;
42
    }
43
}
44