mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
WIP develop ldap fixes (errors, check if disabled, parsing in one place) (#6500)
* Fix errors and exception when ldap settings are empty (even with ldap disabled) * Re-add newline at the end of file
This commit is contained in:
parent
93947b09c5
commit
28edf13457
|
@ -54,9 +54,10 @@ class LdapAd extends LdapAdConfiguration
|
|||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->ldap = new Adldap();
|
||||
$this->ldap->addProvider($this->ldapConfig);
|
||||
if($this->isLdapEnabled()) {
|
||||
$this->ldap = new Adldap();
|
||||
$this->ldap->addProvider($this->ldapConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,14 +43,16 @@ class LdapAdConfiguration
|
|||
public function __construct()
|
||||
{
|
||||
$this->ldapSettings = $this->getSnipeItLdapSettings();
|
||||
$this->setSnipeItConfig();
|
||||
if ($this->isLdapEnabled()) {
|
||||
$this->setSnipeItConfig();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the default Adlap config with the SnipeIT config.
|
||||
*
|
||||
*
|
||||
* @author Wes Hulette <jwhulette@gmail.com>
|
||||
*
|
||||
*
|
||||
* @since 5.0.0
|
||||
*/
|
||||
private function setSnipeItConfig()
|
||||
|
@ -65,7 +67,7 @@ class LdapAdConfiguration
|
|||
* @author Wes Hulette <jwhulette@gmail.com>
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
private function getSnipeItLdapSettings(): Collection
|
||||
|
@ -80,8 +82,9 @@ class LdapAdConfiguration
|
|||
if (in_array($key, self::LDAP_BOOLEAN_SETTINGS)) {
|
||||
return boolval($item);
|
||||
}
|
||||
|
||||
// Decrypt the admin password
|
||||
if (('ldap_pword' === $key) && ($item!='')) {
|
||||
if ('ldap_pword' === $key && !empty($item)) {
|
||||
try {
|
||||
return decrypt($item);
|
||||
} catch (Exception $e) {
|
||||
|
@ -89,6 +92,10 @@ class LdapAdConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
if ('ldap_server' === $key) {
|
||||
return collect(parse_url($item));
|
||||
}
|
||||
|
||||
return $item;
|
||||
});
|
||||
|
||||
|
@ -122,7 +129,7 @@ class LdapAdConfiguration
|
|||
* @author Wes Hulette <jwhulette@gmail.com>
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function setLdapConnectionConfiguration(): array
|
||||
|
@ -184,15 +191,10 @@ class LdapAdConfiguration
|
|||
*/
|
||||
private function getPort(): int
|
||||
{
|
||||
$ldapUrl = $this->ldapSettings['ldap_server'];
|
||||
if ($ldapUrl) {
|
||||
$port = parse_url($ldapUrl, PHP_URL_PORT);
|
||||
|
||||
if (is_int($port)) {
|
||||
return $port;
|
||||
}
|
||||
$port = $this->getLdapServerData('port');
|
||||
if ($port && is_int($port)) {
|
||||
return $port;
|
||||
}
|
||||
|
||||
return self::LDAP_PORT;
|
||||
}
|
||||
|
||||
|
@ -207,15 +209,10 @@ class LdapAdConfiguration
|
|||
*/
|
||||
private function isSsl(): bool
|
||||
{
|
||||
if ($this->ldapSettings['ldap_server']) {
|
||||
$scheme = explode('://', $this->ldapSettings['ldap_server']);
|
||||
if ('ldap' === strtolower($scheme[0])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$scheme = $this->getLdapServerData('scheme');
|
||||
if ($scheme && 'ldaps' === strtolower($scheme)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -236,13 +233,43 @@ class LdapAdConfiguration
|
|||
})->toArray();
|
||||
}
|
||||
|
||||
if ($this->ldapSettings['ldap_server']) {
|
||||
$parts = explode('//', $this->ldapSettings['ldap_server']);
|
||||
return [
|
||||
$parts[1],
|
||||
];
|
||||
$url = $this->getLdapServerData('host');
|
||||
return $url ? [$url] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ldap enabled setting
|
||||
*
|
||||
* @author Steffen Buehl <sb@sbuehl.com>
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isLdapEnabled(): bool
|
||||
{
|
||||
return $this->ldapSettings && $this->ldapSettings->get('ldap_enabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parsed ldap server information
|
||||
*
|
||||
* @author Steffen Buehl <sb@sbuehl.com>
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $key
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected function getLdapServerData($key)
|
||||
{
|
||||
if ($this->ldapSettings) {
|
||||
$ldapServer = $this->ldapSettings->get('ldap_server');
|
||||
if ($ldapServer && $ldapServer instanceof Collection) {
|
||||
return $ldapServer->get($key);
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue