AdldapFactory::getAuthenticatedAdLdap()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 11
rs 9.4285
c 1
b 0
f 1
cc 2
eloc 7
nc 2
nop 0
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