Add mapping editor

Fixes https://github.com/nextcloud/user_saml/issues/4
This commit is contained in:
Lukas Reschke 2016-06-29 10:25:09 +02:00
parent c942f6826b
commit 99bbde20dc
No known key found for this signature in database
GPG key ID: 9AB0ADB949B6898C
5 changed files with 44 additions and 6 deletions

View file

@ -34,6 +34,18 @@ $(function() {
}
});
$('#user-saml-general input[type="text"], #user-saml-general textarea').change(function(e) {
var el = $(this);
$.when(el.focusout()).then(function() {
var key = $(this).attr('name');
setSAMLConfigValue('general', key, $(this).val());
});
if (e.keyCode === 13) {
var key = $(this).attr('name');
setSAMLConfigValue('general', key, $(this).val());
}
});
$('#user-saml-security input[type="checkbox"]').change(function(e) {
var el = $(this);
$.when(el.focusout()).then(function() {

View file

@ -64,10 +64,20 @@ class SettingsController extends Controller {
'wantNameIdEncrypted' => $this->l10n->t('Indicates a requirement for the NameID received by this SP to be encrypted.'),
'wantXMLValidation' => $this->l10n->t('Indicates if the SP will validate all received XMLs.'),
];
$generalSettings = [
'uid_mapping' => [
'text' => $this->l10n->t('Attribute to map the UID to.'),
'type' => 'line',
'required' => true,
],
];
$params = [
'sp' => $serviceProviderFields,
'security-offer' => $securityOfferFields,
'security-required' => $securityRequiredFields,
'general' => $generalSettings,
];
return new Http\TemplateResponse($this->appName, 'settings', $params, 'blank');

View file

@ -43,8 +43,8 @@ class SAMLSettings {
public function getOneLoginSettingsArray() {
$settings = [
//'debug' => true,
'strict' => true,
// 'debug' => true,
// 'strict' => true,
'security' => [
'nameIdEncrypted' => ($this->config->getAppValue('user_saml', 'security-nameIdEncrypted', '0') === '1') ? true : false,
'authnRequestsSigned' => ($this->config->getAppValue('user_saml', 'security-authnRequestsSigned', '0') === '1') ? true : false,
@ -94,6 +94,8 @@ class SAMLSettings {
}
return $settings;
}
}

View file

@ -140,7 +140,7 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend {
* @since 6.0.0
*/
public function isSessionActive() {
if($this->session->exists('user_saml.samlUserData')) {
if($this->getCurrentUserId() !== '') {
return true;
}
return false;
@ -164,8 +164,14 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend {
* @since 6.0.0
*/
public function getCurrentUserId() {
// FIXME: Don't harcode
return $this->session->get('user_saml.samlUserData')['urn:oid:0.9.2342.19200300.100.1.1'][0];
$samlData = $this->session->get('user_saml.samlUserData');
$uidMapping = $this->config->getAppValue('user_saml', 'general-uid_mapping', '');
if($uidMapping !== '' && isset($samlData[$uidMapping])) {
return $samlData[$uidMapping][0];
}
return '';
}

View file

@ -43,7 +43,15 @@ style('user_saml', 'settings');
<?php endforeach; ?>
</div>
<div id="user-saml-general">
<!-- FIXME: Add mapping editor -->
<?php foreach($_['general'] as $key => $attribute): ?>
<?php if($attribute['type'] === 'checkbox'): ?>
<input type="checkbox" id="user-saml-general-<?php p($key)?>" name="<?php p($key)?>" value="<?php p(\OC::$server->getConfig()->getAppValue('user_saml', 'general-'.$key, '0')) ?>">
<label for="user-saml-general-<?php p($key)?>"><?php p($attribute['text']) ?></label><br/>
<?php elseif($attribute['type'] === 'line'): ?>
<input name="<?php p($key) ?>" value="<?php p(\OC::$server->getConfig()->getAppValue('user_saml', 'general-'.$key, '')) ?>" type="text" <?php if(isset($attribute['required']) && $attribute['required'] === true): ?>class="required"<?php endif;?> placeholder="<?php p($attribute['text']) ?>"/>
<?php endif; ?>
<?php endforeach; ?>
<!-- FIXME: Add "Disable timeout from SAML" switch (checked by default)-->
</div>