mirror of
https://github.com/netzbegruenung/user_saml.git
synced 2024-05-04 01:53:42 +02:00
Add controller method to delete all idp config keys
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
8c3a4b83e4
commit
1b4b4ee188
|
@ -66,5 +66,13 @@ return [
|
|||
'providerId' => '1'
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'Settings#deleteSamlProviderSettings',
|
||||
'url' => '/settings/providerSettings/{providerId}',
|
||||
'verb' => 'DELETE',
|
||||
'defaults' => [
|
||||
'providerId' => '1'
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
@ -8,6 +8,12 @@
|
|||
cursor: pointer;
|
||||
}
|
||||
|
||||
#user-saml h3 .icon-delete {
|
||||
display: inline-block;
|
||||
padding: 5px;
|
||||
margin-bottom: -6px;
|
||||
}
|
||||
|
||||
#user-saml h4 {
|
||||
font-size: 14px;
|
||||
font-weight: 300;
|
||||
|
|
104
js/admin.js
104
js/admin.js
|
@ -14,10 +14,12 @@
|
|||
url: OC.linkToOCS('apps/provisioning_api/api/v1', 2) + 'config/apps' + '/user_saml/' + key + '?format=json'
|
||||
});
|
||||
},
|
||||
init: function() {
|
||||
init: function(callback) {
|
||||
this._getAppConfig('providerIds').done(function (data){
|
||||
if (data.ocs.data.data !== '') {
|
||||
OCA.User_SAML.Admin.providerIds = data.ocs.data.data;
|
||||
OCA.User_SAML.Admin.currentConfig = OCA.User_SAML.Admin.providerIds.split(',')[0];
|
||||
callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -52,11 +54,13 @@
|
|||
*/
|
||||
addProvider: function(callback) {
|
||||
var providerIds = OCA.User_SAML.Admin.providerIds.split(',');
|
||||
var nextId = 2;
|
||||
while($.inArray('' + nextId, providerIds) >= 0) {
|
||||
nextId++;
|
||||
var nextId = 1;
|
||||
if (providerIds.indexOf('1') >= 0) {
|
||||
nextId = 2;
|
||||
while ($.inArray('' + nextId, providerIds) >= 0) {
|
||||
nextId++;
|
||||
}
|
||||
}
|
||||
console.log(nextId);
|
||||
OCP.AppConfig.setValue('user_saml', 'providerIds', OCA.User_SAML.Admin.providerIds + ',' + nextId, {
|
||||
success: function () {
|
||||
OCA.User_SAML.Admin.providerIds += ',' + nextId;
|
||||
|
@ -65,14 +69,35 @@
|
|||
});
|
||||
},
|
||||
|
||||
setSamlConfigValue: function(category, setting, value) {
|
||||
removeProvider: function(callback) {
|
||||
var providerIds = OCA.User_SAML.Admin.providerIds.split(',');
|
||||
if (providerIds.length > 1) {
|
||||
var index = providerIds.indexOf(this.currentConfig);
|
||||
if (index > -1) {
|
||||
providerIds.splice(index, 1);
|
||||
}
|
||||
var config = this.currentConfig;
|
||||
$.ajax({ url: OC.generateUrl('/apps/user_saml/settings/providerSettings/' + this.currentConfig), type: 'DELETE'})
|
||||
.done(function(data) {
|
||||
OCP.AppConfig.setValue('user_saml', 'providerIds', providerIds.join(','), {
|
||||
success: function () {
|
||||
OCA.User_SAML.Admin.providerIds = providerIds.join(',');
|
||||
callback(config);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
setSamlConfigValue: function(category, setting, value, global) {
|
||||
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
|
||||
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.setSamlConfigValue, this, category, setting, value));
|
||||
return;
|
||||
}
|
||||
// store global config flags without idp prefix
|
||||
var configIdentifier = this.getConfigIdentifier();
|
||||
if (typeof global === 'undefined') {
|
||||
if (global === true) {
|
||||
configIdentifier = '';
|
||||
}
|
||||
OC.msg.startSaving('#user-saml-save-indicator');
|
||||
|
@ -83,32 +108,36 @@
|
|||
})(OCA);
|
||||
|
||||
$(function() {
|
||||
OCA.User_SAML.Admin.init();
|
||||
// Hide depending on the setup state
|
||||
var type = $('#user-saml').data('type');
|
||||
console.log(type);
|
||||
if(type === '') {
|
||||
$('#user-saml-choose-type').removeClass('hidden');
|
||||
} else {
|
||||
$('#user-saml-global').removeClass('hidden');
|
||||
$('#user-saml-warning-admin-user').removeClass('hidden');
|
||||
$('#user-saml-settings').removeClass('hidden');
|
||||
$('#user-saml-general').removeClass('hidden');
|
||||
}
|
||||
if(type === 'environment-variable') {
|
||||
// we need the settings div to be visible for require_providioned_account
|
||||
$('#user-saml-settings div').addClass('hidden');
|
||||
$('#user-saml-settings .button').addClass('hidden');
|
||||
}
|
||||
if (type === 'saml') {
|
||||
$('#user-saml .account-list').removeClass('hidden');
|
||||
}
|
||||
|
||||
if($('#user-saml-general-require_provisioned_account').val() === '0' && type !== '') {
|
||||
$('#user-saml-attribute-mapping').removeClass('hidden');
|
||||
} else {
|
||||
$('#user-saml-attribute-mapping').addClass('hidden');
|
||||
}
|
||||
var type = $('#user-saml').data('type');
|
||||
|
||||
OCA.User_SAML.Admin.init(function() {
|
||||
$('.account-list li[data-id="' + OCA.User_SAML.Admin.currentConfig + '"]').addClass('active');
|
||||
// Hide depending on the setup state
|
||||
if(type === '') {
|
||||
$('#user-saml-choose-type').removeClass('hidden');
|
||||
} else {
|
||||
$('#user-saml-global').removeClass('hidden');
|
||||
$('#user-saml-warning-admin-user').removeClass('hidden');
|
||||
$('#user-saml-settings').removeClass('hidden');
|
||||
}
|
||||
if(type === 'environment-variable') {
|
||||
// we need the settings div to be visible for require_providioned_account
|
||||
$('#user-saml-settings div').addClass('hidden');
|
||||
$('#user-saml-settings .button').addClass('hidden');
|
||||
$('#user-saml-general').removeClass('hidden');
|
||||
}
|
||||
if (type === 'saml') {
|
||||
$('#user-saml .account-list').removeClass('hidden');
|
||||
$('#user-saml-general').removeClass('hidden');
|
||||
}
|
||||
|
||||
if($('#user-saml-general-require_provisioned_account').val() === '0' && type !== '') {
|
||||
$('#user-saml-attribute-mapping').removeClass('hidden');
|
||||
} else {
|
||||
$('#user-saml-attribute-mapping').addClass('hidden');
|
||||
}
|
||||
});
|
||||
|
||||
$('#user-saml-choose-saml').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
@ -131,11 +160,11 @@ $(function() {
|
|||
Object.keys(data).forEach(function(category, index){
|
||||
var entries = data[category];
|
||||
Object.keys(entries).forEach(function (configKey) {
|
||||
var element = $('*[data-key="' + configKey + '"]');
|
||||
if ($('#user-saml-' + configKey).length) {
|
||||
var element = $('#user-saml-settings *[data-key="' + configKey + '"]');
|
||||
if ($('#user-saml-settings #user-saml-' + configKey).length) {
|
||||
element = $('#user-saml-' + configKey);
|
||||
}
|
||||
if ($('[name="' + configKey + '"]').length) {
|
||||
if ($('#user-saml-settings [name="' + configKey + '"]').length) {
|
||||
element = $('[name="' + configKey + '"]');
|
||||
}
|
||||
if(element.is('input') && element.prop('type') === 'text') {
|
||||
|
@ -170,7 +199,10 @@ $(function() {
|
|||
});
|
||||
|
||||
$('[data-js="remove-idp"]').on('click', function() {
|
||||
OCA.User_SAML.Admin.removeProvider();
|
||||
OCA.User_SAML.Admin.removeProvider(function(currentConfig) {
|
||||
$('.account-list li[data-id="' + currentConfig + '"]').remove();
|
||||
switchProvider(OCA.User_SAML.Admin.providerIds.split(',')[0]);
|
||||
});
|
||||
});
|
||||
|
||||
// Enable tabs
|
||||
|
|
|
@ -78,4 +78,31 @@ class SettingsController extends Controller {
|
|||
return $settings;
|
||||
}
|
||||
|
||||
public function deleteSamlProviderSettings($providerId) {
|
||||
$params = $this->admin->getForm()->getParams();
|
||||
$params['idp'] = [
|
||||
'singleLogoutService.url' => null,
|
||||
'singleSignOnService.url' => null,
|
||||
'idp-entityId' => null,
|
||||
];
|
||||
/* Fetch all config values for the given providerId */
|
||||
foreach ($params as $category => $content) {
|
||||
if (empty($content) || $category === 'providers') {
|
||||
continue;
|
||||
}
|
||||
foreach ($content as $setting => $details) {
|
||||
if ($details['global']) {
|
||||
continue;
|
||||
}
|
||||
$prefix = $providerId === '1' ? '' : $providerId . '-';
|
||||
$key = $prefix . $category . '-' . $setting;
|
||||
/* use security as category instead of security-* */
|
||||
if (strpos($category, 'security-') === 0) {
|
||||
$category = 'security';
|
||||
}
|
||||
$this->config->deleteAppValue('user_saml', $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@ style('user_saml', 'admin');
|
|||
title="<?php p($l->t('Open documentation'));?>"
|
||||
href="<?php p(link_to_docs('admin-sso')); ?>"></a>
|
||||
|
||||
<div id="user-saml-save-indicator" class="msg success inlineblock" style="display: none;"><?php p($l->t('Saved')); ?></div>
|
||||
|
||||
|
||||
|
||||
<div class="warning hidden" id="user-saml-warning-admin-user">
|
||||
<?php p(
|
||||
|
@ -31,8 +34,6 @@ style('user_saml', 'admin');
|
|||
<button id="user-saml-choose-env"><?php p($l->t('Use environment variable')) ?></button>
|
||||
</div>
|
||||
|
||||
<div id="user-saml-save-indicator" class="msg success inlineblock" style="display: none;"><?php p($l->t('Saved')); ?></div>
|
||||
|
||||
<div id="user-saml-global" class="hidden">
|
||||
<h3><?php p($l->t('Global settings')) ?></h3>
|
||||
<?php foreach($_['general'] as $key => $attribute): ?>
|
||||
|
@ -51,17 +52,20 @@ style('user_saml', 'admin');
|
|||
|
||||
<ul class="account-list hidden">
|
||||
<?php foreach ($_['providers'] as $id => $name) { ?>
|
||||
<li data-id="<?php p($id); ?>" class="<?php if ((string)$id === '1') { p('active'); } ?>">
|
||||
<li data-id="<?php p($id); ?>">
|
||||
<a href="#"><?php p($name); ?></a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
<li><a data-js="remove-idp" class="icon-delete"><span class="hidden-visually"><?php p($l->t('Remove identity provider')); ?></span></a></li>
|
||||
<li class="add-provider"><a href="#" class="button"><span class="icon-add"></span> <?php p($l->t('Add identity provider')); ?></a></li>
|
||||
</ul>
|
||||
|
||||
<div id="user-saml-settings" class="hidden">
|
||||
|
||||
<div id="user-saml-general" class="hidden">
|
||||
<h3><?php p($l->t('General')) ?></h3>
|
||||
<h3>
|
||||
<?php p($l->t('General')) ?>
|
||||
</h3>
|
||||
<?php foreach($_['general'] as $key => $attribute): ?>
|
||||
<?php if($attribute['type'] === 'checkbox' && !$attribute['global']): ?>
|
||||
<p>
|
||||
|
@ -158,7 +162,6 @@ style('user_saml', 'admin');
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<a data-js="remove-idp" class="button"><?php p($l->t('Remove identity provider')); ?></button>
|
||||
<a href="<?php p(\OC::$server->getURLGenerator()->linkToRoute('user_saml.SAML.getMetadata')) ?>" class="button"><?php p($l->t('Download metadata XML')) ?></a>
|
||||
<span class="warning hidden" id="user-saml-settings-incomplete"><?php p($l->t('Metadata invalid')) ?></span>
|
||||
<span class="success hidden" id="user-saml-settings-complete"><?php p($l->t('Metadata valid')) ?></span>
|
||||
|
|
Loading…
Reference in a new issue