Merge pull request #5568 from nextcloud/ldap-agent-credentials-safe

Ldap agent credentials save
This commit is contained in:
Lukas Reschke 2017-11-09 09:26:51 +01:00 committed by GitHub
commit 2bfa1ce5c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 20 deletions

View File

@ -209,11 +209,6 @@ select[multiple=multiple] + button {
color: #777;
}
.outoftheway {
position: absolute;
left: -2000px;
}
#ldapSettings {
background-color: white;
padding: 0;

View File

@ -43,11 +43,15 @@ OCA = OCA || {};
},
ldap_dn: {
$element: $('#ldap_dn'),
setMethod: 'setAgentDN'
setMethod: 'setAgentDN',
preventAutoSave: true,
$saveButton: $('.ldapSaveAgentCredentials')
},
ldap_agent_password: {
$element: $('#ldap_agent_password'),
setMethod: 'setAgentPwd'
setMethod: 'setAgentPwd',
preventAutoSave: true,
$saveButton: $('.ldapSaveAgentCredentials')
},
ldap_base: {
$element: $('#ldap_base'),
@ -65,7 +69,11 @@ OCA = OCA || {};
}
};
this.setManagedItems(items);
_.bindAll(this, 'onPortButtonClick', 'onBaseDNButtonClick', 'onBaseDNTestButtonClick');
_.bindAll(this,
'onPortButtonClick',
'onBaseDNButtonClick',
'onBaseDNTestButtonClick'
);
this.managedItems.ldap_port.$relatedElements.click(this.onPortButtonClick);
this.managedItems.ldap_base.$detectButton.click(this.onBaseDNButtonClick);
this.managedItems.ldap_base.$testButton.click(this.onBaseDNTestButtonClick);

View File

@ -53,6 +53,7 @@ OCA = OCA || {};
setManagedItems: function(managedItems) {
this.managedItems = managedItems;
this._enableAutoSave();
this._enableSaveButton();
},
/**
@ -319,7 +320,10 @@ OCA = OCA || {};
for(var id in this.managedItems) {
if(_.isUndefined(this.managedItems[id].$element)
|| _.isUndefined(this.managedItems[id].setMethod)) {
|| _.isUndefined(this.managedItems[id].setMethod)
|| (!_.isUndefined(this.managedItems[id].preventAutoSave)
&& this.managedItems[id].preventAutoSave === true)
) {
continue;
}
var $element = this.managedItems[id].$element;
@ -331,6 +335,35 @@ OCA = OCA || {};
}
},
/**
* set's up save-button behavior (essentially used for agent dn and pwd)
*
* @private
*/
_enableSaveButton: function() {
var view = this;
// TODO: this is not nice, because it fires one request per change
// in the scenario this happens twice, causes detectors to run
// duplicated etc. To have this work properly, the wizard endpoint
// must accept setting multiple changes. Instead of messing around
// with old ajax/wizard.php use this opportunity and create a
// Controller
for(var id in this.managedItems) {
if(_.isUndefined(this.managedItems[id].$element)
|| _.isUndefined(this.managedItems[id].$saveButton)
) {
continue;
}
(function (item) {
item.$saveButton.click(function(event) {
event.preventDefault();
view._requestSave(item.$element);
});
})(this.managedItems[id]);
}
},
/**
* initializes a multiSelect element
*

View File

@ -37,9 +37,13 @@ namespace OCA\User_LDAP;
* @property int ldapPagingSize holds an integer
*/
class Configuration {
protected $configPrefix = null;
protected $configRead = false;
/**
* @var string[] pre-filled with one reference key so that at least one entry is written on save request and
* the config ID is registered
*/
protected $unsavedChanges = ['ldapConfigurationActive' => 'ldapConfigurationActive'];
//settings
protected $config = array(
@ -187,7 +191,9 @@ class Configuration {
$this->$setMethod($key, $val);
if(is_array($applied)) {
$applied[] = $inputKey;
// storing key as index avoids duplication, and as value for simplicity
}
$this->unsavedChanges[$key] = $key;
}
return null;
}
@ -240,11 +246,12 @@ class Configuration {
}
/**
* saves the current Configuration in the database
* saves the current config changes in the database
*/
public function saveConfiguration() {
$cta = array_flip($this->getConfigTranslationArray());
foreach($this->config as $key => $value) {
foreach($this->unsavedChanges as $key) {
$value = $this->config[$key];
switch ($key) {
case 'ldapAgentPassword':
$value = base64_encode($value);
@ -275,6 +282,7 @@ class Configuration {
}
$this->saveValue($cta[$key], $value);
}
$this->unsavedChanges = [];
}
/**

View File

@ -150,7 +150,7 @@ class Connection extends LDAPUtility {
$this->configuration->$name = $value;
$after = $this->configuration->$name;
if($before !== $after) {
if ($this->configID !== '') {
if ($this->configID !== '' && $this->configID !== null) {
$this->configuration->saveConfiguration();
}
$this->validateConfiguration();

View File

@ -1,10 +1,3 @@
<div class="outoftheway">
<!-- Hack for Safari and Chromium/Chrome which ignore autocomplete="off" -->
<input type="text" id="fake_user" name="fake_user" autocomplete="off" />
<input type="password" id="fake_password" name="fake_password"
autocomplete="off" />
</div>
<fieldset id="ldapWizard1">
<p>
<select id="ldap_serverconfig_chooser" name="ldap_serverconfig_chooser">
@ -54,6 +47,7 @@
</div>
</div>
</div>
<div class="tablerow">&nbsp;</div>
<div class="tablerow">
<input type="text" id="ldap_dn" name="ldap_dn"
class="tablecell"
@ -68,7 +62,11 @@
placeholder="<?php p($l->t('Password'));?>" autocomplete="off"
title="<?php p($l->t('For anonymous access, leave DN and Password empty.'));?>"
/>
<button class="ldapSaveAgentCredentials" name="ldapSaveAgentCredentials" type="button">
<?php p($l->t('Save Credentials'));?>
</button>
</div>
<div class="tablerow">&nbsp;</div>
<div class="tablerow">
<textarea id="ldap_base" name="ldap_base"