ldap-contacts-suggestions: Allow anonymous ldap_bind() if bind DN is not filled up in plugin config

This commit is contained in:
imt-mines-albi 2018-11-30 12:54:28 +00:00
parent 495fb486e1
commit bb602a52a3
3 changed files with 16 additions and 9 deletions

View file

@ -15,12 +15,12 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
/** /**
* @var string * @var string
*/ */
private $sAccessDn = ''; private $sAccessDn = NULL;
/** /**
* @var string * @var string
*/ */
private $sAccessPassword = ''; private $sAccessPassword = NULL;
/** /**
* @var string * @var string
@ -68,8 +68,11 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
{ {
$this->sHostName = $sHostName; $this->sHostName = $sHostName;
$this->iHostPort = $iHostPort; $this->iHostPort = $iHostPort;
$this->sAccessDn = $sAccessDn; if (0 < \strlen($sAccessDn))
$this->sAccessPassword = $sAccessPassword; {
$this->sAccessDn = $sAccessDn;
$this->sAccessPassword = $sAccessPassword;
}
$this->sUsersDn = $sUsersDn; $this->sUsersDn = $sUsersDn;
$this->sObjectClass = $sObjectClass; $this->sObjectClass = $sObjectClass;
$this->sNameField = $sNameField; $this->sNameField = $sNameField;
@ -181,7 +184,11 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
if (!@\ldap_bind($oCon, $this->sAccessDn, $this->sAccessPassword)) if (!@\ldap_bind($oCon, $this->sAccessDn, $this->sAccessPassword))
{ {
$this->logLdapError($oCon, 'ldap_bind'); if ( is_null($this->sAccessDn) ) {
$this->logLdapError($oCon, 'ldap_bind (anonymous)');
} else {
$this->logLdapError($oCon, 'ldap_bind');
}
return $aResult; return $aResult;
} }

View file

@ -1 +1 @@
1.0 1.1

View file

@ -44,8 +44,7 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin
$sNameField = \trim($this->Config()->Get('plugin', 'name_field', '')); $sNameField = \trim($this->Config()->Get('plugin', 'name_field', ''));
$sEmailField = \trim($this->Config()->Get('plugin', 'mail_field', '')); $sEmailField = \trim($this->Config()->Get('plugin', 'mail_field', ''));
if (0 < \strlen($sAccessDn) && 0 < \strlen($sAccessPassword) && 0 < \strlen($sUsersDn) && if (0 < \strlen($sUsersDn) && 0 < \strlen($sObjectClass) && 0 < \strlen($sEmailField))
0 < \strlen($sObjectClass) && 0 < \strlen($sEmailField))
{ {
include_once __DIR__.'/LdapContactsSuggestions.php'; include_once __DIR__.'/LdapContactsSuggestions.php';
@ -71,6 +70,7 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT) ->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
->SetDefaultValue(389), ->SetDefaultValue(389),
\RainLoop\Plugins\Property::NewInstance('access_dn')->SetLabel('Access dn (login)') \RainLoop\Plugins\Property::NewInstance('access_dn')->SetLabel('Access dn (login)')
->SetDescription('LDAP bind DN to authentifcate with. If left blank, anonymous bind will be tried and Access password will be ignored')
->SetDefaultValue(''), ->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('access_password')->SetLabel('Access password') \RainLoop\Plugins\Property::NewInstance('access_password')->SetLabel('Access password')
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD) ->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)