Completed
Push — master ( 4712d7...c9edbb )
by Guillaume
02:15
created

OAuthStorage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 32
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkUserCredentials() 0 21 4
1
<?php
2
/**
3
 * File part of the Redmine User Provider bundle
4
 *
5
 * @category  SymfonyBundle
6
 * @package   GMaissa.RedmineUserProviderBundle
7
 * @author    Guillaume Maïssa <[email protected]>
8
 * @copyright 2017 Guillaume Maïssa
9
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
10
 */
11
12
namespace GMaissa\RedmineUserProviderBundle\Bridge\OAuthServer\Security\Storage;
13
14
use FOS\OAuthServerBundle\Model\ClientInterface;
15
use FOS\OAuthServerBundle\Storage\OAuthStorage as BaseOAuthStorage;
16
use GMaissa\RedmineUserProviderBundle\Security\Provider\CredentialsUserProviderInterface;
17
use OAuth2\Model\IOAuth2Client;
18
use Symfony\Component\Security\Core\Exception\AuthenticationException;
19
20
/**
21
 * OAuth server storage class retrieving user from given credentials
22
 */
23
class OAuthStorage extends BaseOAuthStorage
24
{
25
    /**
26
     * @var CredentialsUserProviderInterface
27
     */
28
    protected $userProvider;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 3
    public function checkUserCredentials(IOAuth2Client $client, $username, $password)
34
    {
35 3
        if (!$client instanceof ClientInterface) {
36 1
            throw new \InvalidArgumentException('Client has to implement the ClientInterface');
37
        }
38
39 2
        $result = false;
40
        try {
41 2
            $user = $this->userProvider->loadUserByCredentials($username, $password);
42
43 1
            if (null !== $user) {
44
                $result = array(
45 1
                    'data' => $user,
46
                );
47
            }
48 1
        } catch (AuthenticationException $e) {
49 1
            $result = false;
50
        }
51
52 2
        return $result;
53
    }
54
}
55