From 167d4319b58b0ddb57779a0762c4a9fb058d9c54 Mon Sep 17 00:00:00 2001 From: William Date: Thu, 6 Feb 2020 09:06:22 +1300 Subject: [PATCH] fix(authentication): frontend changes (#3456) * fix(authentication): frontend changes * fix(authentication): suggested changes * fix(authentication): support AnonymousMode boolean * feat(authentication): support empty vals + move from scope to formValues * feat(authentication): allow test of TLS & anon * feat(authentication): remove unneeded whitespace * feat(authentication): remove un-needed whitespace * feat(refactor): rebase + cleanup logic --- .../settingsAuthentication.html | 75 ++++++++++++------- .../settingsAuthenticationController.js | 59 ++++++++++++--- 2 files changed, 93 insertions(+), 41 deletions(-) diff --git a/app/portainer/views/settings/authentication/settingsAuthentication.html b/app/portainer/views/settings/authentication/settingsAuthentication.html index cddc54848..679b4d016 100644 --- a/app/portainer/views/settings/authentication/settingsAuthentication.html +++ b/app/portainer/views/settings/authentication/settingsAuthentication.html @@ -90,37 +90,54 @@
- +
+
- -
- +
+ +
+ -
- -
- +
+
+ +
+ +
+
+ +
+ +
+ +
- -
+ +
- @@ -132,28 +149,28 @@
-
+
-
+
@@ -167,22 +184,22 @@
-
+
-
+
{{ formValues.TLSCACert.name }} - + @@ -192,14 +209,14 @@
-
+
- +
@@ -218,7 +235,7 @@ Automatic user provisioning
@@ -228,7 +245,7 @@
-
+
@@ -282,7 +299,7 @@
-
+
diff --git a/app/portainer/views/settings/authentication/settingsAuthenticationController.js b/app/portainer/views/settings/authentication/settingsAuthenticationController.js index 9daa8265b..3e8786da0 100644 --- a/app/portainer/views/settings/authentication/settingsAuthenticationController.js +++ b/app/portainer/views/settings/authentication/settingsAuthenticationController.js @@ -11,7 +11,32 @@ function($q, $scope, $state, Notifications, SettingsService, FileUploadService, }; $scope.formValues = { - TLSCACert: '' + TLSCACert: '', + LDAPSettings: { + AnonymousMode: true, + ReaderDN: '', + URL: '', + TLSConfig: { + TLS: false, + TLSSkipVerify: false + }, + StartTLS: false, + SearchSettings: [ + { + BaseDN: '', + Filter: '', + UserNameAttribute: '' + } + ], + GroupSearchSettings: [ + { + GroupBaseDN: '', + GroupFilter: '', + GroupAttribute: '' + } + ], + AutoCreateUsers: true + } }; $scope.goToOAuthExtensionView = function() { @@ -23,32 +48,37 @@ function($q, $scope, $state, Notifications, SettingsService, FileUploadService, }; $scope.addSearchConfiguration = function() { - $scope.LDAPSettings.SearchSettings.push({ BaseDN: '', UserNameAttribute: '', Filter: '' }); + $scope.formValues.LDAPSettings.SearchSettings.push({ BaseDN: '', UserNameAttribute: '', Filter: '' }); }; $scope.removeSearchConfiguration = function(index) { - $scope.LDAPSettings.SearchSettings.splice(index, 1); + $scope.formValues.LDAPSettings.SearchSettings.splice(index, 1); }; $scope.addGroupSearchConfiguration = function() { - $scope.LDAPSettings.GroupSearchSettings.push({ GroupBaseDN: '', GroupAttribute: '', GroupFilter: '' }); + $scope.formValues.LDAPSettings.GroupSearchSettings.push({ GroupBaseDN: '', GroupAttribute: '', GroupFilter: '' }); }; $scope.removeGroupSearchConfiguration = function(index) { - $scope.LDAPSettings.GroupSearchSettings.splice(index, 1); + $scope.formValues.LDAPSettings.GroupSearchSettings.splice(index, 1); }; $scope.LDAPConnectivityCheck = function() { - var settings = $scope.settings; + var settings = angular.copy($scope.settings); var TLSCAFile = $scope.formValues.TLSCACert !== settings.LDAPSettings.TLSConfig.TLSCACert ? $scope.formValues.TLSCACert : null; - var uploadRequired = ($scope.LDAPSettings.TLSConfig.TLS || $scope.LDAPSettings.StartTLS) && !$scope.LDAPSettings.TLSConfig.TLSSkipVerify; + if ($scope.formValues.LDAPSettings.AnonymousMode){ + settings.LDAPSettings['ReaderDN'] = ''; + settings.LDAPSettings['Password'] = ''; + } + + var uploadRequired = ($scope.formValues.LDAPSettings.TLSConfig.TLS || $scope.formValues.LDAPSettings.StartTLS) && !$scope.formValues.LDAPSettings.TLSConfig.TLSSkipVerify; $scope.state.uploadInProgress = uploadRequired; $scope.state.connectivityCheckInProgress = true; $q.when(!uploadRequired || FileUploadService.uploadLDAPTLSFiles(TLSCAFile, null, null)) .then(function success() { - addLDAPDefaultPort(settings, $scope.LDAPSettings.TLSConfig.TLS); + addLDAPDefaultPort(settings, $scope.formValues.LDAPSettings.TLSConfig.TLS); return SettingsService.checkLDAPConnectivity(settings); }) .then(function success() { @@ -68,16 +98,21 @@ function($q, $scope, $state, Notifications, SettingsService, FileUploadService, }; $scope.saveSettings = function() { - var settings = $scope.settings; + var settings = angular.copy($scope.settings); var TLSCAFile = $scope.formValues.TLSCACert !== settings.LDAPSettings.TLSConfig.TLSCACert ? $scope.formValues.TLSCACert : null; - var uploadRequired = ($scope.LDAPSettings.TLSConfig.TLS || $scope.LDAPSettings.StartTLS) && !$scope.LDAPSettings.TLSConfig.TLSSkipVerify; + if ($scope.formValues.LDAPSettings.AnonymousMode){ + settings.LDAPSettings['ReaderDN'] = ''; + settings.LDAPSettings['Password'] = ''; + } + + var uploadRequired = ($scope.formValues.LDAPSettings.TLSConfig.TLS || $scope.formValues.LDAPSettings.StartTLS) && !$scope.formValues.LDAPSettings.TLSConfig.TLSSkipVerify; $scope.state.uploadInProgress = uploadRequired; $scope.state.actionInProgress = true; $q.when(!uploadRequired || FileUploadService.uploadLDAPTLSFiles(TLSCAFile, null, null)) .then(function success() { - addLDAPDefaultPort(settings, $scope.LDAPSettings.TLSConfig.TLS); + addLDAPDefaultPort(settings, $scope.formValues.LDAPSettings.TLSConfig.TLS); return SettingsService.update(settings); }) .then(function success() { @@ -109,7 +144,7 @@ function($q, $scope, $state, Notifications, SettingsService, FileUploadService, var settings = data.settings; $scope.teams = data.teams; $scope.settings = settings; - $scope.LDAPSettings = settings.LDAPSettings; + $scope.formValues.LDAPSettings = settings.LDAPSettings; $scope.OAuthSettings = settings.OAuthSettings; $scope.formValues.TLSCACert = settings.LDAPSettings.TLSConfig.TLSCACert; $scope.oauthAuthenticationAvailable = data.oauthAuthentication;