1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Ldap\Symfony\LdapClient |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/appserver |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Appserver\Ldap\Symfony; |
22
|
|
|
|
23
|
|
|
use Symfony\Component\Ldap\LdapInterface; |
24
|
|
|
use AppserverIo\Ldap\LdapClientInterface; |
25
|
|
|
use Symfony\Component\Ldap\Entry; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Symfony based LDAP client implementation. |
29
|
|
|
* |
30
|
|
|
* @author Tim Wagner <[email protected]> |
31
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
33
|
|
|
* @link https://github.com/appserver-io/appserver |
34
|
|
|
* @link http://www.appserver.io |
35
|
|
|
*/ |
36
|
|
|
class LdapClient implements LdapClientInterface, LdapInterface |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The Symfony LDAP client instance. |
41
|
|
|
* |
42
|
|
|
* @var \Symfony\Component\Ldap\LdapClientInterface |
43
|
|
|
*/ |
44
|
|
|
protected $ldapClient; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Initializes the Entity Manager with the Symfony LDAP client instance. |
48
|
|
|
* |
49
|
|
|
* @param \Symfony\Component\Ldap\LdapInterface $ldapClient The LDAP client instance |
50
|
|
|
*/ |
51
|
|
|
public function __construct(LdapInterface $ldapClient) |
52
|
|
|
{ |
53
|
|
|
$this->ldapClient = $ldapClient; |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Return a connection bound to the ldap. |
58
|
|
|
* |
59
|
|
|
* @param string $dn A LDAP dn |
60
|
|
|
* @param string $password A password |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
* @throws \Symfony\Component\Ldap\Exception\ConnectionException if dn / password could not be bound |
64
|
|
|
*/ |
65
|
|
|
public function bind($dn = null, $password = null) |
66
|
|
|
{ |
67
|
|
|
return $this->ldapClient->bind($dn, $password); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Queries a ldap server for entries matching the given criteria. |
72
|
|
|
* |
73
|
|
|
* @param string $dn The DN to query |
74
|
|
|
* @param string $query The query itself |
75
|
|
|
* @param array $options The query options |
76
|
|
|
* |
77
|
|
|
* @return \Symfony\Component\Ldap\Adapter\CollectionInterface|\Symfony\Component\Ldap\Entry[] The query result |
78
|
|
|
* @throws \Symfony\Component\Ldap\Exception\ConnectionException |
79
|
|
|
*/ |
80
|
|
|
public function query($dn, $query, array $options = array()) |
81
|
|
|
{ |
82
|
|
|
return $this->ldapClient->query($dn, $query, $options); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return \Symfony\Component\Ldap\Adapter\EntryManagerInterface |
87
|
|
|
*/ |
88
|
|
|
public function getEntryManager() |
89
|
|
|
{ |
90
|
|
|
return $this->ldapClient->getEntryManager(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Escape a string for use in an LDAP filter or DN. |
95
|
|
|
* |
96
|
|
|
* @param string $subject The subject to escape |
97
|
|
|
* @param string $ignore Do not ignore |
98
|
|
|
* @param int $flags The flags |
99
|
|
|
* |
100
|
|
|
* @return string The escaped string |
101
|
|
|
*/ |
102
|
|
|
public function escape($subject, $ignore = '', $flags = 0) |
103
|
|
|
{ |
104
|
|
|
return $this->ldapClient->escape($subject, $ignore, $flags); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.