ActiveDirectory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 17
c 0
b 0
f 0
dl 0
loc 35
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolveBindException() 0 21 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\ldap\Connector;
6
7
use SimpleSAML\Module\ldap\Auth\InvalidCredentialResult;
8
9
use function ldap_get_option;
10
11
/**
12
 * Extends Ldap so that we can diagnose error messages from MS Active Directory
13
 */
14
class ActiveDirectory extends Ldap
15
{
16
    public const ERR_PASSWORD_RESET = 'RESETPASSWORD';
17
18
    public const ERR_ACCOUNT_RESET = 'RESETACCOUNT';
19
20
    public const ERR_LOGON_RESTRICTION = 'LOGONRESTRICTION';
21
22
23
    /**
24
     * Resolves the bind exception
25
     *
26
     * @return string
27
     */
28
    protected function resolveBindException(): string
29
    {
30
        ldap_get_option(
31
            $this->adapter->getConnection()->getResource(),
0 ignored issues
show
Bug introduced by
The method getResource() does not exist on Symfony\Component\Ldap\Adapter\ConnectionInterface. It seems like you code against a sub-type of Symfony\Component\Ldap\Adapter\ConnectionInterface such as Symfony\Component\Ldap\Adapter\ExtLdap\Connection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
            $this->adapter->getConnection()->/** @scrutinizer ignore-call */ getResource(),
Loading history...
32
            LDAP_OPT_DIAGNOSTIC_MESSAGE,
33
            $message,
34
        );
35
36
        $result  = InvalidCredentialResult::fromDiagnosticMessage($message);
37
        if ($result->isInvalidCredential()) {
38
            return self::ERR_WRONG_PASS;
39
        } elseif ($result->isPasswordError()) {
40
            return self::ERR_PASSWORD_RESET;
41
        } elseif ($result->isAccountError()) {
42
            return self::ERR_ACCOUNT_RESET;
43
        } elseif ($result->isRestricted()) {
44
            return self::ERR_LOGON_RESTRICTION;
45
        }
46
47
        // default to the wrong user pass
48
        return self::ERR_WRONG_PASS;
49
    }
50
}
51