Any backend is responsible for at most one domain

refs #2153
This commit is contained in:
Alexander A. Klimov 2017-05-31 18:11:38 +02:00
parent 8359771271
commit 1a5e64eda9

View File

@ -221,11 +221,11 @@ class LdapBackendForm extends Form
$this->addElement( $this->addElement(
'text', 'text',
'domains', 'domain',
array( array(
'label' => $this->translate('Domains'), 'label' => $this->translate('Domain'),
'description' => $this->translate( 'description' => $this->translate(
'The comma-separated domains the LDAP server is responsible for.' 'The domain the LDAP server is responsible for.'
), ),
'decorators' => array( 'decorators' => array(
array('Label', array('tag'=>'span', 'separator' => '', 'class' => 'control-label')), array('Label', array('tag'=>'span', 'separator' => '', 'class' => 'control-label')),
@ -240,13 +240,13 @@ class LdapBackendForm extends Form
$this->addElement( $this->addElement(
'button', 'button',
'btn_discover_domains', 'btn_discover_domain',
array( array(
'escape' => false, 'escape' => false,
'ignore' => true, 'ignore' => true,
'label' => $this->getView()->icon('binoculars'), 'label' => $this->getView()->icon('binoculars'),
'type' => 'submit', 'type' => 'submit',
'title' => $this->translate('Discover the domains'), 'title' => $this->translate('Discover the domain'),
'value' => $this->translate('Discover'), 'value' => $this->translate('Discover'),
'decorators' => array( 'decorators' => array(
array('Help', array('placement' => 'APPEND')), array('Help', array('placement' => 'APPEND')),
@ -263,58 +263,52 @@ class LdapBackendForm extends Form
*/ */
public function isValidPartial(array $formData) public function isValidPartial(array $formData)
{ {
if (isset($formData['btn_discover_domains']) && parent::isValid($formData)) { if (isset($formData['btn_discover_domain']) && parent::isValid($formData)) {
return $this->populateDomains(ResourceFactory::create($this->getElement('resource')->getValue())); return $this->populateDomain(ResourceFactory::create($this->getElement('resource')->getValue()));
} }
return true; return true;
} }
/** /**
* Discover the domains the LDAP server is responsible for and fill them in the form * Discover the domain the LDAP server is responsible for and fill it in the form
* *
* @param LdapConnection $connection * @param LdapConnection $connection
* *
* @return bool Whether the discovery succeeded * @return bool Whether the discovery succeeded
*/ */
public function populateDomains(LdapConnection $connection) public function populateDomain(LdapConnection $connection)
{ {
try { try {
$domains = $this->discoverDomains($connection); $domain = $this->discoverDomain($connection);
} catch (LdapException $e) { } catch (LdapException $e) {
$this->_elements['btn_discover_domains']->addError($e->getMessage()); $this->_elements['btn_discover_domain']->addError($e->getMessage());
return false; return false;
} }
$this->_elements['domains']->setValue(implode(',', $domains)); $this->_elements['domain']->setValue($domain);
return true; return true;
} }
/** /**
* Discover the domains the LDAP server is responsible for * Discover the domain the LDAP server is responsible for
* *
* @param LdapConnection $connection * @param LdapConnection $connection
* *
* @return string[] * @return string
*/ */
protected function discoverDomains(LdapConnection $connection) protected function discoverDomain(LdapConnection $connection)
{ {
$domains = array();
$cap = LdapCapabilities::discoverCapabilities($connection); $cap = LdapCapabilities::discoverCapabilities($connection);
if ($cap->isActiveDirectory()) { if ($cap->isActiveDirectory()) {
$netBiosName = $cap->getNetBiosName(); $netBiosName = $cap->getNetBiosName();
if ($netBiosName !== null) { if ($netBiosName !== null) {
$domains[] = $netBiosName; return $netBiosName;
} }
} }
$fqdn = $this->defaultNamingContextToFQDN($cap); return $this->defaultNamingContextToFQDN($cap);
if ($fqdn !== null) {
$domains[] = $fqdn;
}
return $domains;
} }
/** /**