AdldapFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAuthenticatedAdLdap() 0 11 2
A __construct() 0 5 1
1
<?php
2
3
4
namespace Riper\Security\ActiveDirectoryBundle\Security\Factory;
5
6
use Riper\Security\ActiveDirectoryBundle\Exception\WrongTokenException;
7
use Riper\Security\ActiveDirectoryBundle\Service\AdldapService;
8
use Riper\Security\ActiveDirectoryBundle\Security\Token\FaultyToken;
9
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
10
11
class AdldapFactory
12
{
13
14
    /**
15
     * @var TokenStorage
16
     */
17
    private $tokenStorage;
18
19
    /**
20
     * @var AdldapService
21
     */
22
    private $adldapService;
23
24
    public function __construct(TokenStorage $tokenStorage, AdldapService $adldapService)
25
    {
26
        $this->tokenStorage = $tokenStorage;
27
        $this->adldapService = $adldapService;
28
    }
29
30
31
    public function getAuthenticatedAdLdap()
32
    {
33
        $token = $this->tokenStorage->getToken();
34
        if ($token instanceof FaultyToken) {
35
            throw new WrongTokenException(
36
                'The token is not the right one. Did you forget to set "keep_password_in_token" to "true" in bundle configuration ?'
37
            );
38
        }
39
        $adldap = $this->adldapService->getInstance();
40
        $adldap->authenticate($token->getUsername(), $token->getCredentials());
41
    }
42
43
}
44