Example #1
0
 /**
  * Create and add elements to this form
  *
  * @param   array   $formData
  */
 public function createElements(array $formData)
 {
     if (isset($formData['skip_validation']) && $formData['skip_validation']) {
         $this->addSkipValidationCheckbox();
     }
     if ($this->config['type'] === 'db') {
         $this->setRequiredCue(null);
         $backendForm = new DbBackendForm();
         $backendForm->setRequiredCue(null);
         $backendForm->create($formData)->removeElement('resource');
         $this->addDescription($this->translate('As you\'ve chosen to use a database for authentication all you need ' . 'to do now is defining a name for your first authentication backend.'));
     } elseif ($this->config['type'] === 'ldap') {
         $type = null;
         if (!isset($formData['type']) && isset($formData['backend'])) {
             $type = $formData['backend'];
             $formData['type'] = $type;
         }
         $backendForm = new LdapBackendForm();
         $backendForm->setResources(array($this->config['name']));
         $backendForm->create($formData);
         $backendForm->getElement('resource')->setIgnore(true);
         $this->addDescription($this->translate('Before you are able to authenticate using the LDAP connection defined earlier you need to' . ' provide some more information so that Icinga Web 2 is able to locate account details.'));
         $this->addElement('select', 'type', array('ignore' => true, 'required' => true, 'autosubmit' => true, 'label' => $this->translate('Backend Type'), 'description' => $this->translate('The type of the resource being used for this authenticaton provider'), 'multiOptions' => array('ldap' => 'LDAP', 'msldap' => 'ActiveDirectory'), 'value' => $type));
     } else {
         // $this->config['type'] === 'external'
         $backendForm = new ExternalBackendForm();
         $backendForm->create($formData);
         $this->addDescription($this->translate('You\'ve chosen to authenticate using a web server\'s mechanism so it may be necessary' . ' to adjust usernames before any permissions, restrictions, etc. are being applied.'));
     }
     $backendForm->getElement('name')->setValue('icingaweb2');
     $this->addSubForm($backendForm, 'backend_form');
 }
 /**
  * Return a form object for the given backend type
  *
  * @param   string      $type   The backend type for which to return a form
  *
  * @return  Form
  */
 public function getBackendForm($type)
 {
     switch ($type) {
         case 'db':
             $form = new DbBackendForm();
             $form->setResources(isset($this->resources['db']) ? $this->resources['db'] : array());
             break;
         case 'ldap':
         case 'msldap':
             $form = new LdapBackendForm();
             $form->setResources(isset($this->resources['ldap']) ? $this->resources['ldap'] : array());
             break;
         case 'external':
             $form = new ExternalBackendForm();
             break;
         default:
             throw new InvalidArgumentException(sprintf($this->translate('Invalid backend type "%s" provided'), $type));
     }
     return $form;
 }
 /**
  * @runInSeparateProcess
  * @preserveGlobalState disabled
  */
 public function testInvalidBackendIsNotValid()
 {
     $this->setUpResourceFactoryMock();
     Mockery::mock('overload:Icinga\\Authentication\\User\\DbUserBackend')->shouldReceive('count')->andReturn(0);
     // Passing array(null) is required to make Mockery call the constructor...
     $form = Mockery::mock('Icinga\\Forms\\Config\\UserBackend\\DbBackendForm[getView]', array(null));
     $form->shouldReceive('getView->escape')->with(Mockery::type('string'))->andReturnUsing(function ($s) {
         return $s;
     });
     $form->setTokenDisabled();
     $form->setResources(array('test_db_backend'));
     $form->populate(array('resource' => 'test_db_backend'));
     $this->assertFalse(DbBackendForm::isValidUserBackend($form), 'DbBackendForm claims that an invalid user backend without users is valid');
 }