136 $this->hostname =
$config->getString(
'hostname');
137 $this->enableTLS =
$config->getBoolean(
'enable_tls',
false);
138 $this->debug =
$config->getBoolean(
'debug',
false);
139 $this->timeout =
$config->getInteger(
'timeout', 0);
140 $this->port =
$config->getInteger(
'port', 389);
141 $this->referrals =
$config->getBoolean(
'referrals',
true);
142 $this->searchEnable =
$config->getBoolean(
'search.enable',
false);
143 $this->privRead =
$config->getBoolean(
'priv.read',
false);
145 if ($this->searchEnable) {
146 $this->searchUsername =
$config->getString(
'search.username', null);
147 if ($this->searchUsername !== null) {
148 $this->searchPassword =
$config->getString(
'search.password');
151 $this->searchBase =
$config->getArrayizeString(
'search.base');
152 $this->searchScope =
$config->getString(
'search.scope',
'subtree');
153 $this->searchFilter =
$config->getString(
'search.filter', null);
154 $this->searchAttributes =
$config->getArray(
'search.attributes');
157 $this->dnPattern =
$config->getString(
'dnpattern');
161 if ($this->privRead) {
162 $this->privUsername =
$config->getString(
'priv.username');
163 $this->privPassword =
$config->getString(
'priv.password');
166 $this->attributes =
$config->getArray(
'attributes', null);
183 assert(is_string($username));
191 $ldap =
new SimpleSAML_Auth_LDAP($this->hostname, $this->enableTLS, $this->debug, $this->timeout, $this->port, $this->referrals);
193 if (!$this->searchEnable) {
194 $ldapusername = addcslashes($username,
',+"\\<>;*');
195 $dn = str_replace(
'%username%', $ldapusername, $this->dnPattern);
197 if ($this->searchUsername !== null) {
198 if (!$ldap->bind($this->searchUsername, $this->searchPassword)) {
199 throw new Exception(
'Error authenticating using search username & password.');
203 $dn = $ldap->searchfordn($this->searchBase, $this->searchAttributes, $username,
true, $this->searchFilter, $this->searchScope);
211 if (!$ldap->bind($dn,
$password, $sasl_args)) {
217 if (isset($sasl_args)) {
218 $dn = $ldap->whoami($this->searchBase, $this->searchAttributes);
222 if ($this->privRead) {
224 if (!$ldap->bind($this->privUsername, $this->privPassword)) {
225 throw new Exception(
'Error authenticating using privileged DN & password.');
229 return $ldap->getAttributes($dn, $this->attributes);
264 if ($attribute == null) {
268 if ($this->searchUsername !== null) {
269 if (!$ldap->bind($this->searchUsername, $this->searchPassword)) {
270 throw new Exception(
'Error authenticating using search username & password.');
274 return $ldap->searchfordn($this->searchBase, $attribute,
275 $value, $allowZeroHits, $this->searchFilter, $this->searchScope);
292 if ($this->privRead) {
294 if (!$ldap->bind($this->privUsername, $this->privPassword)) {
295 throw new Exception(
'Error authenticating using privileged DN & password.');
getAttributes($dn, $attributes=null)
login($username, $password, array $sasl_args=null)
Attempt to log in using the given username and password.
$searchScope
The scope of the search.
$privUsername
The DN we should bind with before we can get the attributes.
$searchBase
Array with the base DN(s) for the search.
$searchAttributes
The attributes which should match the username.
$searchUsername
The username we should bind with before we can search for the user.
$dnPattern
The DN pattern we should use to create the DN from the username.
$enableTLS
Whether we should use TLS/SSL when contacting the LDAP server.
__construct($config, $location)
Constructor for this configuration parser.
$searchEnable
Whether we need to search for the users DN.
$searchFilter
Additional LDAP filter fields for the search.
$privPassword
The password we should bind with before we can get the attributes.
searchfordn($attribute, $value, $allowZeroHits)
Search for a DN.
$referrals
Whether to follow referrals.
$attributes
The attributes we should fetch.
$location
String with the location of this configuration.
$privRead
The user cannot get all attributes, privileged reader required.
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.
$searchPassword
The password we should bind with before we can search for the user.
$hostname
The hostname of the LDAP server.