Skip to content

Commit

Permalink
Allow to configure user group backends of type LDAP
Browse files Browse the repository at this point in the history
refs #7343
  • Loading branch information
Johannes Meyer committed Jun 5, 2015
1 parent 447088a commit 5688f0c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
41 changes: 31 additions & 10 deletions application/forms/Config/UserGroup/UserGroupBackendForm.php
Expand Up @@ -38,10 +38,17 @@ public function init()
*/
public function getBackendForm($type)
{
if ($type === 'db') {
return new DbUserGroupBackendForm();
} else {
throw new InvalidArgumentException(sprintf($this->translate('Invalid backend type "%s" provided'), $type));
switch ($type)
{
case 'db':
return new DbUserGroupBackendForm();
case 'ldap':
case 'msldap':
return new LdapUserGroupBackendForm();
default:
throw new InvalidArgumentException(
sprintf($this->translate('Invalid backend type "%s" provided'), $type)
);
}
}

Expand Down Expand Up @@ -165,7 +172,9 @@ public function createElements(array $formData)

// TODO(jom): We did not think about how to configure custom group backends yet!
$backendTypes = array(
'db' => $this->translate('Database')
'db' => $this->translate('Database'),
'ldap' => $this->translate('LDAP'),
'msldap' => $this->translate('ActiveDirectory')
);

$backendType = isset($formData['type']) ? $formData['type'] : null;
Expand All @@ -191,14 +200,11 @@ public function createElements(array $formData)
'autosubmit' => true,
'label' => $this->translate('Backend Type'),
'description' => $this->translate('The type of this user group backend'),
'multiOptions' => $backendTypes,
'value' => $backendType
'multiOptions' => $backendTypes
)
);

$backendForm = $this->getBackendForm($backendType);
$backendForm->createElements($formData);
$this->addElements($backendForm->getElements());
$this->addSubForm($this->getBackendForm($backendType)->create($formData), 'backend_form');
}

/**
Expand All @@ -213,4 +219,19 @@ public function onRequest()
$this->populate($data);
}
}

/**
* Retrieve all form element values
*
* @param bool $suppressArrayNotation Ignored
*
* @return array
*/
public function getValues($suppressArrayNotation = false)
{
$values = parent::getValues();
$values = array_merge($values, $values['backend_form']);
unset($values['backend_form']);
return $values;
}
}
Expand Up @@ -556,7 +556,7 @@ public function setConfig(ConfigObject $config)
$defaults = new ConfigObject();
}

if ($config->user_backend) {
if ($config->user_backend && $config->user_backend !== 'none') {
$userBackend = UserBackend::create($config->user_backend);
if (! $userBackend instanceof LdapUserBackend) {
throw new ConfigurationError('User backend "%s" is not of type LDAP', $config->user_backend);
Expand Down

0 comments on commit 5688f0c

Please sign in to comment.