Allow to configure user group backends of type LDAP

refs #7343
This commit is contained in:
Johannes Meyer 2015-06-05 14:53:29 +02:00
parent 447088af22
commit 5688f0cb85
2 changed files with 32 additions and 11 deletions

View File

@ -38,10 +38,17 @@ class UserGroupBackendForm extends ConfigForm
*/ */
public function getBackendForm($type) public function getBackendForm($type)
{ {
if ($type === 'db') { switch ($type)
return new DbUserGroupBackendForm(); {
} else { case 'db':
throw new InvalidArgumentException(sprintf($this->translate('Invalid backend type "%s" provided'), $type)); return new DbUserGroupBackendForm();
case 'ldap':
case 'msldap':
return new LdapUserGroupBackendForm();
default:
throw new InvalidArgumentException(
sprintf($this->translate('Invalid backend type "%s" provided'), $type)
);
} }
} }
@ -165,7 +172,9 @@ class UserGroupBackendForm extends ConfigForm
// TODO(jom): We did not think about how to configure custom group backends yet! // TODO(jom): We did not think about how to configure custom group backends yet!
$backendTypes = array( $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; $backendType = isset($formData['type']) ? $formData['type'] : null;
@ -191,14 +200,11 @@ class UserGroupBackendForm extends ConfigForm
'autosubmit' => true, 'autosubmit' => true,
'label' => $this->translate('Backend Type'), 'label' => $this->translate('Backend Type'),
'description' => $this->translate('The type of this user group backend'), 'description' => $this->translate('The type of this user group backend'),
'multiOptions' => $backendTypes, 'multiOptions' => $backendTypes
'value' => $backendType
) )
); );
$backendForm = $this->getBackendForm($backendType); $this->addSubForm($this->getBackendForm($backendType)->create($formData), 'backend_form');
$backendForm->createElements($formData);
$this->addElements($backendForm->getElements());
} }
/** /**
@ -213,4 +219,19 @@ class UserGroupBackendForm extends ConfigForm
$this->populate($data); $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;
}
} }

View File

@ -556,7 +556,7 @@ class LdapUserGroupBackend /*extends LdapRepository*/ implements UserGroupBacken
$defaults = new ConfigObject(); $defaults = new ConfigObject();
} }
if ($config->user_backend) { if ($config->user_backend && $config->user_backend !== 'none') {
$userBackend = UserBackend::create($config->user_backend); $userBackend = UserBackend::create($config->user_backend);
if (! $userBackend instanceof LdapUserBackend) { if (! $userBackend instanceof LdapUserBackend) {
throw new ConfigurationError('User backend "%s" is not of type LDAP', $config->user_backend); throw new ConfigurationError('User backend "%s" is not of type LDAP', $config->user_backend);