LdapUserChecker::checkLdapErrorCode()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 20
Code Lines 13

Duplication

Lines 15
Ratio 75 %

Importance

Changes 0
Metric Value
dl 15
loc 20
c 0
b 0
f 0
rs 8.2222
cc 7
eloc 13
nc 4
nop 3
1
<?php
2
/**
3
 * This file is part of the LdapToolsBundle package.
4
 *
5
 * (c) Chad Sikorra <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LdapTools\Bundle\LdapToolsBundle\Security\User;
12
13
use LdapTools\Enums\AD\ResponseCode;
14
use LdapTools\Connection\LdapConnection;
15
use Symfony\Component\Security\Core\Exception\CredentialsExpiredException;
16
use Symfony\Component\Security\Core\Exception\DisabledException;
17
use Symfony\Component\Security\Core\Exception\LockedException;
18
use Symfony\Component\Security\Core\User\UserChecker;
19
use Symfony\Component\Security\Core\User\UserInterface;
20
21
/**
22
 * Interpret extended LDAP codes from authentication to determine the state of the LDAP account.
23
 *
24
 * @author Chad Sikorra <[email protected]>
25
 */
26
class LdapUserChecker extends UserChecker
27
{
28
    /**
29
     * Based on the LDAP error code and the LDAP type, throw any specific exceptions detected.
30
     *
31
     * @param UserInterface $user The user object.
32
     * @param int $code The extended LDAP error code.
33
     * @param string $ldapType The LDAP type used for authentication.
34
     */
35
    public function checkLdapErrorCode(UserInterface $user, $code, $ldapType)
36
    {
37 View Code Duplication
        if ($ldapType == LdapConnection::TYPE_AD && $code == ResponseCode::AccountLocked) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
            $ex = new LockedException('User account is locked.');
39
            $ex->setUser($user);
40
            throw $ex;
41
        }
42
43 View Code Duplication
        if ($ldapType == LdapConnection::TYPE_AD && $code == ResponseCode::AccountPasswordMustChange) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
            $ex = new CredentialsExpiredException('User credentials have expired.');
45
            $ex->setUser($user);
46
            throw $ex;
47
        }
48
49 View Code Duplication
        if ($ldapType == LdapConnection::TYPE_AD && $code == ResponseCode::AccountDisabled) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
            $ex = new DisabledException('User account is disabled.');
51
            $ex->setUser($user);
52
            throw $ex;
53
        }
54
    }
55
}
56