2013-08-16 16:24:12 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Icinga\Form\Config\Authentication;
|
|
|
|
|
2014-04-16 11:50:58 +02:00
|
|
|
use Icinga\Web\Form;
|
2013-08-16 16:24:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base form for authentication backend forms
|
|
|
|
*/
|
|
|
|
abstract class BaseBackendForm extends Form
|
|
|
|
{
|
2014-07-24 08:49:47 +02:00
|
|
|
/**
|
|
|
|
* @see Form::addSubmitButton()
|
|
|
|
*/
|
|
|
|
public function addSubmitButton()
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'submit',
|
|
|
|
'btn_submit',
|
|
|
|
array(
|
|
|
|
'label' => t('Save Changes')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-26 16:56:23 +02:00
|
|
|
/**
|
2013-08-27 14:37:22 +02:00
|
|
|
* Validate this form with the Zend validation mechanism and perform a logic validation of the connection.
|
2013-08-26 16:56:23 +02:00
|
|
|
*
|
|
|
|
* If logic validation fails, the 'backend_force_creation' checkbox is prepended to the form to allow users to
|
|
|
|
* skip the logic connection validation.
|
|
|
|
*
|
2014-04-16 11:50:58 +02:00
|
|
|
* @param array $data The form input to validate
|
2013-08-26 16:56:23 +02:00
|
|
|
*
|
2014-04-16 11:50:58 +02:00
|
|
|
* @return bool Whether validation succeeded or not
|
2013-08-26 16:56:23 +02:00
|
|
|
*/
|
|
|
|
public function isValid($data)
|
|
|
|
{
|
|
|
|
if (!parent::isValid($data)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-16 11:50:58 +02:00
|
|
|
if (isset($data['backend_force_creation']) && $data['backend_force_creation']) {
|
2013-08-26 16:56:23 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-08-27 14:37:22 +02:00
|
|
|
if (!$this->isValidAuthenticationBackend()) {
|
2013-08-26 16:56:23 +02:00
|
|
|
$this->addForceCreationCheckbox();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate the configuration state of this backend with the concrete authentication backend.
|
|
|
|
*
|
|
|
|
* An implementation should not throw any exception, but use the add/setErrorMessages method of
|
|
|
|
* Zend_Form. If the 'backend_force_creation' checkbox is set, this method won't be called.
|
|
|
|
*
|
2014-04-16 11:50:58 +02:00
|
|
|
* @return bool Whether validation succeeded or not
|
2013-08-26 16:56:23 +02:00
|
|
|
*/
|
2013-08-27 14:37:22 +02:00
|
|
|
abstract public function isValidAuthenticationBackend();
|
2014-07-24 08:47:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the backend's configuration values and its name
|
|
|
|
*
|
|
|
|
* The first value is the name and the second one the values as array.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getBackendConfig()
|
|
|
|
{
|
|
|
|
$values = $this->getValues();
|
|
|
|
$name = $values['name'];
|
|
|
|
unset($values['name']);
|
|
|
|
unset($values['btn_submit']);
|
|
|
|
unset($values['force_creation']);
|
|
|
|
unset($values[$this->getTokenElementName()]);
|
|
|
|
return array($name, $values);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate the form with the given configuration values
|
|
|
|
*
|
|
|
|
* @param string $name The name of the backend
|
|
|
|
* @param array $config The configuration values
|
|
|
|
*/
|
|
|
|
public function setBackendConfig($name, array $config)
|
|
|
|
{
|
|
|
|
$config['name'] = $name;
|
|
|
|
$this->populate($config);
|
|
|
|
}
|
2014-07-24 08:57:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a checkbox to be displayed at the beginning of the form
|
|
|
|
* which allows the user to skip the connection validation
|
|
|
|
*/
|
|
|
|
protected function addForceCreationCheckbox()
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'force_creation',
|
|
|
|
array(
|
|
|
|
'order' => 0,
|
|
|
|
'label' => t('Force Changes'),
|
|
|
|
'helptext' => t('Check this box to enforce changes without connectivity validation')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2013-08-16 16:24:12 +02:00
|
|
|
}
|