From 716972347d012fe31ab307bd8ff295748e762886 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Mon, 3 Mar 2014 15:50:10 -0500 Subject: [PATCH] revocation --- .../META-INF/resources/admin/js/app.js | 24 ++++++++++ .../admin/js/controllers/applications.js | 45 +++++++++++++++++++ .../admin/js/controllers/oauth-clients.js | 40 +++++++++++++++++ .../resources/admin/js/controllers/realm.js | 26 +++++------ .../META-INF/resources/admin/js/services.js | 8 ++++ .../admin/partials/application-claims.html | 1 + .../partials/application-credentials.html | 1 + .../admin/partials/application-detail.html | 1 + .../partials/application-installation.html | 1 + .../partials/application-revocation.html | 37 +++++++++++++++ .../partials/application-role-detail.html | 1 + .../admin/partials/application-role-list.html | 1 + .../partials/application-scope-mappings.html | 1 + .../admin/partials/oauth-client-claims.html | 1 + .../partials/oauth-client-credentials.html | 1 + .../admin/partials/oauth-client-detail.html | 1 + .../partials/oauth-client-installation.html | 1 + .../partials/oauth-client-revocation.html | 36 +++++++++++++++ .../partials/oauth-client-scope-mappings.html | 1 + .../idm/ApplicationRepresentation.java | 22 ++++++--- .../idm/OAuthClientRepresentation.java | 16 +++++-- .../java/org/keycloak/models/ClientModel.java | 10 +++++ .../org/keycloak/models/OAuthClientModel.java | 1 + .../keycloak/models/jpa/ClientAdapter.java | 10 +++++ .../models/jpa/OAuthClientAdapter.java | 5 ++- .../models/jpa/entities/ClientEntity.java | 9 ++++ .../keycloak/adapters/ApplicationAdapter.java | 9 ++++ .../keycloak/adapters/OAuthClientAdapter.java | 15 +++++++ .../keycloak/entities/ApplicationEntity.java | 10 +++++ .../keycloak/entities/OAuthClientEntity.java | 9 +++- .../services/managers/ApplicationManager.java | 22 ++++++--- .../services/managers/OAuthClientManager.java | 15 ++++++- .../services/managers/RealmManager.java | 13 +++--- .../managers/ResourceAdminManager.java | 21 +++++++-- .../services/managers/TokenManager.java | 16 ++++--- .../resources/admin/ApplicationResource.java | 9 ++++ .../resources/admin/RealmAdminResource.java | 5 +-- 37 files changed, 389 insertions(+), 56 deletions(-) create mode 100755 admin-ui/src/main/resources/META-INF/resources/admin/partials/application-revocation.html create mode 100755 admin-ui/src/main/resources/META-INF/resources/admin/partials/oauth-client-revocation.html diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js index 17cbe664ef..e6fc2d7388 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js +++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js @@ -319,6 +319,18 @@ module.config([ '$routeProvider', function($routeProvider) { }, controller : 'ApplicationRoleListCtrl' }) + .when('/realms/:realm/applications/:application/revocation', { + templateUrl : 'partials/application-revocation.html', + resolve : { + realm : function(RealmLoader) { + return RealmLoader(); + }, + application : function(ApplicationLoader) { + return ApplicationLoader(); + } + }, + controller : 'ApplicationRevocationCtrl' + }) .when('/realms/:realm/applications/:application/scope-mappings', { templateUrl : 'partials/application-scope-mappings.html', resolve : { @@ -409,6 +421,18 @@ module.config([ '$routeProvider', function($routeProvider) { }, controller : 'OAuthClientClaimsCtrl' }) + .when('/realms/:realm/oauth-clients/:oauth/revocation', { + templateUrl : 'partials/oauth-client-revocation.html', + resolve : { + realm : function(RealmLoader) { + return RealmLoader(); + }, + oauth : function(OAuthClientLoader) { + return OAuthClientLoader(); + } + }, + controller : 'OAuthClientRevocationCtrl' + }) .when('/realms/:realm/oauth-clients/:oauth/credentials', { templateUrl : 'partials/oauth-client-credentials.html', resolve : { diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/applications.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/applications.js index 5bfb651767..29d1113edb 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/applications.js +++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/applications.js @@ -384,3 +384,48 @@ module.controller('ApplicationScopeMappingCtrl', function($scope, $http, realm, }); + +module.controller('ApplicationRevocationCtrl', function($scope, realm, application, Application, ApplicationPushRevocation, $location, Dialog, Notifications) { + $scope.application = application; + + var setNotBefore = function() { + if ($scope.application.notBefore == 0) { + $scope.notBefore = "None"; + } else { + $scope.notBefore = new Date($scope.application.notBefore * 1000); + } + }; + + setNotBefore(); + + var refresh = function() { + Application.get({ realm : realm.realm, application: $scope.application.name }, function(updated) { + $scope.application = updated; + setNotBefore(); + }) + + }; + + $scope.clear = function() { + $scope.application.notBefore = 0; + Application.update({ realm : realm.realm, application: application.name}, $scope.application, function () { + $scope.notBefore = "None"; + Notifications.success('Not Before cleared for application.'); + refresh(); + }); + } + $scope.setNotBeforeNow = function() { + $scope.application.notBefore = new Date().getTime()/1000; + Realm.update({ realm : realm.realm, application: $scope.application.name}, $scope.application, function () { + Notifications.success('Not Before cleared for application.'); + refresh(); + }); + } + $scope.pushRevocation = function() { + ApplicationPushRevocation.save({realm : realm.realm, application: $scope.application.name}, function () { + Notifications.success('Push sent for application.'); + }); + } + +}); + diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/oauth-clients.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/oauth-clients.js index 542d5e18c2..ae9477772f 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/oauth-clients.js +++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/oauth-clients.js @@ -287,3 +287,43 @@ module.controller('OAuthClientInstallationCtrl', function($scope, realm, install $scope.installation = installation; $scope.download = OAuthClientInstallation.url({ realm: $routeParams.realm, oauth: $routeParams.oauth }); }); + +module.controller('OAuthClientRevocationCtrl', function($scope, realm, oauth, OAuthClient, $location, Dialog, Notifications) { + $scope.oauth = oauth; + + var setNotBefore = function() { + if ($scope.oauth.notBefore == 0) { + $scope.notBefore = "None"; + } else { + $scope.notBefore = new Date($scope.oauth.notBefore * 1000); + } + }; + + setNotBefore(); + + var refresh = function() { + OAuthClient.get({ realm : realm.realm, id: $scope.oauth.id }, function(updated) { + $scope.oauth = updated; + setNotBefore(); + }) + + }; + + $scope.clear = function() { + $scope.oauth.notBefore = 0; + OAuthClient.update({ realm : realm.realm, id: $scope.oauth.id}, $scope.oauth, function () { + $scope.notBefore = "None"; + Notifications.success('Not Before cleared for application.'); + refresh(); + }); + } + $scope.setNotBeforeNow = function() { + $scope.oauth.notBefore = new Date().getTime()/1000; + OAuthClient.update({ realm : realm.realm, id: $scope.oauth.id}, $scope.oauth, function () { + Notifications.success('Not Before cleared for application.'); + refresh(); + }); + } +}); + + diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js index c83ddbc245..cb0fa24800 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js +++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js @@ -691,7 +691,7 @@ module.controller('RealmKeysDetailCtrl', function($scope, Realm, realm, $http, $ }); module.controller('RealmRevocationCtrl', function($scope, Realm, RealmPushRevocation, realm, $http, $location, Dialog, Notifications) { - $scope.realm = realm; + $scope.realm = angular.copy(realm); var setNotBefore = function() { if ($scope.realm.notBefore == 0) { @@ -701,29 +701,27 @@ module.controller('RealmRevocationCtrl', function($scope, Realm, RealmPushRevoca } }; - if (realm.notBefore == 0) { - $scope.notBefore = "None"; - } else { - $scope.notBefore = new Date(realm.notBefore); - } + setNotBefore(); + + var reset = function() { + Realm.get({ id : realm.realm }, function(updated) { + $scope.realm = updated; + setNotBefore(); + }) + + }; $scope.clear = function() { Realm.update({ realm: realm.realm, notBefore : 0 }, function () { $scope.notBefore = "None"; Notifications.success('Not Before cleared for realm.'); - Realm.get({ id : realm.realm }, function(updated) { - $scope.realm = updated; - setNotBefore(); - }) + reset(); }); } $scope.setNotBeforeNow = function() { Realm.update({ realm: realm.realm, notBefore : new Date().getTime()/1000}, function () { Notifications.success('Not Before cleared for realm.'); - Realm.get({ id : realm.realm }, function(updated) { - $scope.realm = updated; - setNotBefore(); - }) + reset(); }); } $scope.pushRevocation = function() { diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/services.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/services.js index 0aac008a66..a7342347ea 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/js/services.js +++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/services.js @@ -467,6 +467,14 @@ module.factory('ApplicationClaims', function($resource) { }); }); +module.factory('ApplicationPushRevocation', function($resource) { + return $resource('//auth/rest/admin/realms/:realm/applications/:application/push-revocation', { + realm : '@realm', + application : "@application" + }); +}); + + module.factory('Application', function($resource) { return $resource('/auth/rest/admin/realms/:realm/applications/:application', { diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-claims.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-claims.html index 72ba62f22f..2b2e34bf61 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-claims.html +++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-claims.html @@ -7,6 +7,7 @@
  • Roles
  • Claims
  • Scope
  • +
  • Revocation