From 27bdc996e7339b4b08653654ae7ef3b07952d58e Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Mon, 23 May 2016 10:34:24 +0200 Subject: [PATCH] KEYCLOAK-3008 Upload Realm Keys doesn't work --- .../admin/resources/js/controllers/realm.js | 62 +++++++++++++--- .../admin/resources/partials/realm-keys.html | 71 +++++++++++++++---- 2 files changed, 107 insertions(+), 26 deletions(-) diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js index a8da2ac68a..54c8000e7a 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js @@ -1024,19 +1024,50 @@ module.controller('RealmKeysDetailCtrl', function($scope, Realm, realm, $http, $ $scope.generate = function() { Dialog.confirmGenerateKeys($scope.realm.realm, 'realm', function() { Realm.update({ realm: realm.realm, publicKey : 'GENERATE' }, function () { - Notifications.success('New keys generated for realm.'); - Realm.get({ id : realm.realm }, function(updated) { - $scope.realm = updated; - }) + $route.reload(); + Notifications.success('New keys generated for realm.'); }); }); }; - $scope.cancel = function() { + $scope.privateKeyUpload = function($files){ + var reader = new FileReader(); + reader.onload = function(e) { + $scope.$apply(function() { + $scope.privateKeyUploadContent = e.target.result; + }); + }; + reader.readAsText($files[0]); + $scope.privateKeyUploadName = $files[0].name; + }; + + $scope.publicKeyUpload = function($files){ + var reader = new FileReader(); + reader.onload = function(e) { + $scope.$apply(function() { + $scope.publicKeyUploadContent = e.target.result; + }); + }; + reader.readAsText($files[0]); + $scope.publicKeyUploadName = $files[0].name; + }; + + $scope.certificateUpload = function($files){ + var reader = new FileReader(); + reader.onload = function(e) { + $scope.$apply(function() { + $scope.certificateUploadContent = e.target.result; + }); + }; + reader.readAsText($files[0]); + $scope.certificateUploadName = $files[0].name; + }; + + $scope.clearImport = function() { $route.reload(); } - $scope.save = function() { + $scope.import = function() { var title = 'Upload keys for realm'; var msg = 'Are you sure you want to upload keys for ' + $scope.realm.realm + '?'; var btns = { @@ -1051,11 +1082,20 @@ module.controller('RealmKeysDetailCtrl', function($scope, Realm, realm, $http, $ }; Dialog.open(title, msg, btns, function() { - Realm.update($scope.realm, function () { - Notifications.success('Keys uploaded for realm.'); - Realm.get({ id : realm.realm }, function(updated) { - $scope.realm = updated; - }) + var upload = { realm : $scope.realm.realm }; + + if ($scope.privateKeyUploadContent && $scope.publicKeyUploadContent) { + upload.privateKey = $scope.privateKeyUploadContent; + upload.publicKey = $scope.publicKeyUploadContent; + } + + if ($scope.certificateUploadContent) { + upload.certificate = $scope.certificateUploadContent; + } + + Realm.update(upload, function () { + $route.reload(); + Notifications.success('Keys imported for realm.'); }); }); }; diff --git a/themes/src/main/resources/theme/base/admin/resources/partials/realm-keys.html b/themes/src/main/resources/theme/base/admin/resources/partials/realm-keys.html index 5133f378f9..7bebc3b650 100755 --- a/themes/src/main/resources/theme/base/admin/resources/partials/realm-keys.html +++ b/themes/src/main/resources/theme/base/admin/resources/partials/realm-keys.html @@ -6,42 +6,83 @@
-
- - -
- -
-
+ kc-select-action="click" data-ng-model="realm.publicKey" readonly>
- +
- +
-
-
- - + +
+ Import keys + +
+ +
+
+ + +
+ + {{privateKeyUploadName}} + +
-
+ +
+ +
+
+ + +
+ + {{publicKeyUploadName}} + +
+
+ +
+ +
+
+ + +
+ + {{certificateUploadName}} + +
+
+ +
+
+ + +
+
+ + + + +