Completed
Push — 6.7 ( 730fb7...a124d5 )
by André
39:46 queued 26:19
created

RememberMeRepositoryAuthenticationProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setRepository() 0 4 1
A authenticate() 0 13 2
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
use Symfony\Component\Security\Core\Exception\AuthenticationException;
15
16
class RememberMeRepositoryAuthenticationProvider extends RememberMeAuthenticationProvider
17
{
18
    /**
19
     * @var \eZ\Publish\API\Repository\Repository
20
     */
21
    private $repository;
22
23
    public function setRepository(Repository $repository)
24
    {
25
        $this->repository = $repository;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function authenticate(TokenInterface $token)
32
    {
33
        $authenticatedToken = parent::authenticate($token);
34
        if (empty($authenticatedToken)) {
35
            throw new AuthenticationException('The token is not supported by this authentication provider.');
36
        }
37
38
        $this->repository->getPermissionResolver()->setCurrentUserReference(
39
            $authenticatedToken->getUser()->getAPIUser()
40
        );
41
42
        return $authenticatedToken;
43
    }
44
}
45