Skip to content

Commit

Permalink
Merge branch 'master' into feature/monitoring-restrictions-9009
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Meyer committed Jun 9, 2015
2 parents a4ad4e2 + eba862a commit d5dffe9
Show file tree
Hide file tree
Showing 34 changed files with 1,501 additions and 214 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Expand Up @@ -6,3 +6,6 @@ Vagrantfile export-ignore

# Normalize puppet manifests' line endings to LF on checkin and prevent conversion to CRLF when the files are checked out
.puppet* eol=lf

# Include version information on `git archive'
/application/VERSION export-subst
1 change: 1 addition & 0 deletions application/VERSION
@@ -0,0 +1 @@
$Format:%H%d %ci$
15 changes: 15 additions & 0 deletions application/controllers/AboutController.php
@@ -0,0 +1,15 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */

# namespace Icinga\Application\Controllers;

use Icinga\Web\Controller\ActionController;
use Icinga\Application\Version;

class AboutController extends ActionController
{
public function indexAction()
{
$this->view->version = Version::get();
}
}
5 changes: 5 additions & 0 deletions application/controllers/GroupController.php
Expand Up @@ -28,6 +28,10 @@ public function listAction()
function ($b) { return $b->getName(); },
$this->loadUserGroupBackends('Icinga\Data\Selectable')
);
if (empty($backendNames)) {
return;
}

$this->view->backendSelection = new Form();
$this->view->backendSelection->setAttrib('class', 'backend-selection');
$this->view->backendSelection->setUidDisabled();
Expand Down Expand Up @@ -100,6 +104,7 @@ public function showAction()

$filterEditor = Widget::create('filterEditor')
->setQuery($members)
->setSearchColumns(array('user'))
->preserveParams('limit', 'sort', 'dir', 'view', 'backend', 'group')
->ignoreParams('page')
->handleRequest($this->getRequest());
Expand Down
5 changes: 5 additions & 0 deletions application/controllers/UserController.php
Expand Up @@ -28,6 +28,10 @@ public function listAction()
function ($b) { return $b->getName(); },
$this->loadUserBackends('Icinga\Data\Selectable')
);
if (empty($backendNames)) {
return;
}

$this->view->backendSelection = new Form();
$this->view->backendSelection->setAttrib('class', 'backend-selection');
$this->view->backendSelection->setUidDisabled();
Expand Down Expand Up @@ -99,6 +103,7 @@ public function showAction()

$filterEditor = Widget::create('filterEditor')
->setQuery($memberships)
->setSearchColumns(array('group_name'))
->preserveParams('limit', 'sort', 'dir', 'view', 'backend', 'user')
->ignoreParams('page')
->handleRequest($this->getRequest());
Expand Down
9 changes: 7 additions & 2 deletions application/controllers/UsergroupbackendController.php
Expand Up @@ -52,7 +52,7 @@ public function createAction()
$form->setIniConfig(Config::app('groups'));
$form->setOnSuccess(function (UserGroupBackendForm $form) {
try {
$form->add($form->getValues());
$form->add(array_filter($form->getValues()));
} catch (Exception $e) {
$form->error($e->getMessage());
return false;
Expand Down Expand Up @@ -85,7 +85,12 @@ public function editAction()
$form->setIniConfig(Config::app('groups'));
$form->setOnSuccess(function (UserGroupBackendForm $form) use ($backendName) {
try {
$form->edit($backendName, $form->getValues());
$form->edit($backendName, array_map(
function ($v) {
return $v !== '' ? $v : null;
},
$form->getValues()
));
} catch (Exception $e) {
$form->error($e->getMessage());
return false;
Expand Down
33 changes: 21 additions & 12 deletions application/forms/Config/UserBackend/LdapBackendForm.php
Expand Up @@ -8,7 +8,7 @@
use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory;
use Icinga\Exception\AuthenticationException;
use Icinga\Authentication\User\LdapUserBackend;
use Icinga\Authentication\User\UserBackend;

/**
* Form class for adding/modifying LDAP user backends
Expand Down Expand Up @@ -48,6 +48,8 @@ public function setResources(array $resources)
*/
public function createElements(array $formData)
{
$isAd = isset($formData['type']) ? $formData['type'] === 'msldap' : false;

$this->addElement(
'text',
'name',
Expand Down Expand Up @@ -77,10 +79,13 @@ public function createElements(array $formData)
'text',
'user_class',
array(
'required' => true,
'label' => $this->translate('LDAP User Object Class'),
'description' => $this->translate('The object class used for storing users on the LDAP server.'),
'value' => 'inetOrgPerson'
'preserveDefault' => true,
'required' => ! $isAd,
'ignore' => $isAd,
'disabled' => $isAd ?: null,
'label' => $this->translate('LDAP User Object Class'),
'description' => $this->translate('The object class used for storing users on the LDAP server.'),
'value' => $isAd ? 'user' : 'inetOrgPerson'
)
);
$this->addElement(
Expand Down Expand Up @@ -117,20 +122,23 @@ public function createElements(array $formData)
'text',
'user_name_attribute',
array(
'required' => true,
'label' => $this->translate('LDAP User Name Attribute'),
'description' => $this->translate(
'preserveDefault' => true,
'required' => ! $isAd,
'ignore' => $isAd,
'disabled' => $isAd ?: null,
'label' => $this->translate('LDAP User Name Attribute'),
'description' => $this->translate(
'The attribute name used for storing the user name on the LDAP server.'
),
'value' => 'uid'
'value' => $isAd ? 'sAMAccountName' : 'uid'
)
);
$this->addElement(
'hidden',
'backend',
array(
'disabled' => true,
'value' => 'ldap'
'value' => $isAd ? 'msldap' : 'ldap'
)
);
$this->addElement(
Expand Down Expand Up @@ -170,8 +178,7 @@ public function onSuccess()
public static function isValidUserBackend(Form $form)
{
try {
$ldapUserBackend = new LdapUserBackend(ResourceFactory::createResource($form->getResourceConfig()));
$ldapUserBackend->setConfig(new ConfigObject($form->getValues()));
$ldapUserBackend = UserBackend::create(null, new ConfigObject($form->getValues()));
$ldapUserBackend->assertAuthenticationPossible();
} catch (AuthenticationException $e) {
if (($previous = $e->getPrevious()) !== null) {
Expand All @@ -193,6 +200,8 @@ public static function isValidUserBackend(Form $form)
* Return the configuration for the chosen resource
*
* @return ConfigObject
*
* @todo Check whether it's possible to drop this (Or even all occurences!)
*/
public function getResourceConfig()
{
Expand Down
29 changes: 19 additions & 10 deletions application/forms/Config/UserBackendConfigForm.php
Expand Up @@ -60,16 +60,24 @@ public function setResourceConfig(Config $resourceConfig)
*/
public function getBackendForm($type)
{
if ($type === 'db') {
$form = new DbBackendForm();
$form->setResources(isset($this->resources['db']) ? $this->resources['db'] : array());
} elseif ($type === 'ldap') {
$form = new LdapBackendForm();
$form->setResources(isset($this->resources['ldap']) ? $this->resources['ldap'] : array());
} elseif ($type === 'external') {
$form = new ExternalBackendForm();
} else {
throw new InvalidArgumentException(sprintf($this->translate('Invalid backend type "%s" provided'), $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;
Expand Down Expand Up @@ -296,6 +304,7 @@ public function createElements(array $formData)
}
if (isset($this->resources['ldap']) && ($backendType === 'ldap' || Platform::extensionLoaded('ldap'))) {
$backendTypes['ldap'] = 'LDAP';
$backendTypes['msldap'] = 'ActiveDirectory';
}

$externalBackends = array_filter(
Expand Down

0 comments on commit d5dffe9

Please sign in to comment.