ActiveDirectory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

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

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
    public const ERR_ACCOUNT_RESET = 'RESETACCOUNT';
18
    public const ERR_LOGON_RESTRICTION = 'LOGONRESTRICTION';
19
20
21
    /**
22
     * Resolves the bind exception
23
     *
24
     * @return string
25
     */
26
    protected function resolveBindException(): string
27
    {
28
        ldap_get_option(
29
            $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

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