diff --git a/core/src/main/java/org/keycloak/representations/idm/RoleRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/RoleRepresentation.java index 60fbc6b3e4..4a1610197a 100755 --- a/core/src/main/java/org/keycloak/representations/idm/RoleRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/RoleRepresentation.java @@ -5,6 +5,7 @@ package org.keycloak.representations.idm; * @version $Revision: 1 $ */ public class RoleRepresentation { + protected String id; protected String name; protected String description; @@ -16,6 +17,14 @@ public class RoleRepresentation { this.description = description; } + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + public String getName() { return name; } diff --git a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/app.js b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/app.js index 8e5a3c0081..ac6333a631 100755 --- a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/app.js +++ b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/app.js @@ -92,43 +92,42 @@ module.config([ '$routeProvider', function($routeProvider) { }, controller : 'UserListCtrl' }) - - .when('/realms/:realm/roles', { - templateUrl : 'partials/role-mapping.html', - resolve : { - realm : function(RealmLoader) { - return RealmLoader(); - }, - application : function() { - return null; - }, - users : function() { - return null; - }, - role : function() { - return null; - } - }, - controller : 'RoleMappingCtrl' - }).when('/realms/:realm/roles/:role', { - templateUrl : 'partials/role-mapping.html', - resolve : { - realm : function(RealmLoader) { - return RealmLoader(); - }, - application : function() { - return null; - }, - role : function($route) { - return $route.current.params.role; - }, - users : function(RoleMappingLoader) { - return RoleMappingLoader(); - } - }, - controller : 'RoleMappingCtrl' - }) - + + .when('/create/role/:realm', { + templateUrl : 'partials/role-detail.html', + resolve : { + realm : function(RealmLoader) { + return RealmLoader(); + }, + role : function() { + return {}; + } + }, + controller : 'RoleDetailCtrl' + }).when('/realms/:realm/roles/:role', { + templateUrl : 'partials/role-detail.html', + resolve : { + realm : function(RealmLoader) { + return RealmLoader(); + }, + role : function(RoleLoader) { + return RoleLoader(); + } + }, + controller : 'RoleDetailCtrl' + }).when('/realms/:realm/roles', { + templateUrl : 'partials/role-list.html', + resolve : { + realm : function(RealmLoader) { + return RealmLoader(); + }, + roles : function(RoleListLoader) { + return RoleListLoader(); + } + }, + controller : 'RoleListCtrl' + }) + .when('/applications/:application/roles', { templateUrl : 'partials/role-mapping.html', resolve : { diff --git a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/controllers.js b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/controllers.js index 8224fe426c..a3ed7c2dff 100755 --- a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/controllers.js +++ b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/controllers.js @@ -2,7 +2,9 @@ var module = angular.module('keycloak.controllers', [ 'keycloak.services' ]); -module.controller('GlobalCtrl', function($scope, Auth, $location, Notifications) { +var realmslist = {}; + +module.controller('GlobalCtrl', function($scope, $http, Auth, $location, Notifications) { $scope.addMessage = function() { Notifications.success("test"); }; @@ -14,6 +16,28 @@ module.controller('GlobalCtrl', function($scope, Auth, $location, Notifications) }, function() { $scope.path = $location.path().substring(1).split("/"); }); + + $http.get('/auth-server/rest/saas/admin/realms').success(function(data) { + var count = 0; + var showrealm = false; + var id = null; + for (var key in data) { + if (count > 0) { + showrealm = false; + break; + } + id = key; + showrealm = true; + count++; + } + + if (showrealm) { + console.log('redirecting'); + $location.url("/realms/" + id); + } else { + console.log('not redirecting'); + } + }); }); module.controller('ApplicationListCtrl', function($scope, Application) { @@ -130,13 +154,22 @@ module.controller('ApplicationDetailCtrl', function($scope, application, Applica module.controller('RealmListCtrl', function($scope, Realm) { $scope.realms = Realm.get(); + realmslist = $scope.realms; +}); + +module.controller('RealmDropdownCtrl', function($scope, Realm) { + console.log('test log writing'); + realmslist = Realm.get(); + $scope.realmslist = function() { + return realmslist; + }; }); module.controller('RealmDetailCtrl', function($scope, Realm, realm, $location, Dialog, Notifications) { $scope.realm = angular.copy(realm); - $scope.create = !realm.id; + $scope.createRealm = !realm.id; - if ($scope.create) { + if ($scope.createRealm) { $scope.realm.enabled = true; $scope.realm.requireSsl = true; $scope.realm.cookieLoginAllowed = true; @@ -223,15 +256,17 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realm, $location, D }; - if ($scope.create) { + if ($scope.createRealm) { Realm.save(realmCopy, function(data, headers) { var l = headers().location; var id = l.substring(l.lastIndexOf("/") + 1); + realmslist = Realm.get(); $location.url("/realms/" + id); Notifications.success("Created realm"); }); } else { Realm.update(realmCopy, function() { + realmslist = Realm.get(); $scope.changed = false; realm = angular.copy($scope.realm); Notifications.success("Saved changes to realm"); @@ -255,6 +290,7 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realm, $location, D $scope.remove = function() { Dialog.confirmDelete($scope.realm.name, 'realm', function() { Realm.remove($scope.realm, function() { + realmslist = Realm.get(); $location.url("/realms"); Notifications.success("Deleted realm"); }); @@ -283,6 +319,9 @@ module.controller('UserDetailCtrl', function($scope, realm, user, User, $locatio $scope.save = function() { if ($scope.userForm.$valid) { + + + User.save({ realm : realm.id }, $scope.user, function() { @@ -324,6 +363,79 @@ module.controller('UserDetailCtrl', function($scope, realm, user, User, $locatio }; }); +module.controller('RoleListCtrl', function($scope, realm, roles) { + $scope.realm = realm; + $scope.roles = roles; +}); + +module.controller('RoleDetailCtrl', function($scope, realm, role, Role, $location, Dialog, Notifications) { + $scope.realm = realm; + $scope.role = angular.copy(role); + $scope.create = !role.name; + + $scope.changed = $scope.create; + + $scope.$watch('role', function() { + if (!angular.equals($scope.role, role)) { + $scope.changed = true; + } + }, true); + + $scope.save = function() { + if ($scope.roleForm.$valid) { + + if ($scope.create) { + Role.save({ + realm: realm.id + }, $scope.role, function (data, headers) { + $scope.changed = false; + role = angular.copy($scope.role); + + var l = headers().location; + var id = l.substring(l.lastIndexOf("/") + 1); + $location.url("/realms/" + realm.id + "/roles/" + id); + Notifications.success("Created role"); + + }); + } else { + Role.update({ + realm : realm.id, + roleId : role.id + }, $scope.role, function() { + $scope.changed = false; + role = angular.copy($scope.role); + Notifications.success("Saved changes to role"); + }); + } + + } else { + $scope.roleForm.showErrors = true; + } + }; + + $scope.reset = function() { + $scope.role = angular.copy(user); + $scope.changed = false; + $scope.roleForm.showErrors = false; + }; + + $scope.cancel = function() { + $location.url("/realms/" + realm.id + "/roles"); + }; + + $scope.remove = function() { + Dialog.confirmDelete($scope.role.name, 'role', function() { + $scope.role.$remove({ + realm : realm.id, + role : $scope.role.name + }, function() { + $location.url("/realms/" + realm.id + "/roles"); + Notifications.success("Deleted role"); + }); + }); + }; +}); + module.controller('RoleMappingCtrl', function($scope, realm, User, users, role, RoleMapping, Notifications) { $scope.realm = realm; $scope.realmId = realm.realm || realm.id; diff --git a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/loaders.js b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/loaders.js index fae62e81c9..2b6f5bffd6 100755 --- a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/loaders.js +++ b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/loaders.js @@ -72,6 +72,24 @@ module.factory('UserLoader', function(Loader, User, $route, $q) { }); }); +module.factory('RoleLoader', function(Loader, Role, $route, $q) { + return Loader.get(Role, function() { + return { + realm : $route.current.params.realm, + roleId : $route.current.params.role + } + }); +}); + +module.factory('RoleListLoader', function(Loader, Role, $route, $q) { + return Loader.query(Role, function() { + return { + realm : $route.current.params.realm + } + }); +}); + + module.factory('RoleMappingLoader', function(Loader, RoleMapping, $route, $q) { var realm = $route.current.params.realm || $route.current.params.application; diff --git a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/services.js b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/services.js index 458981d0ad..ba3a26a9d7 100755 --- a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/services.js +++ b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/js/services.js @@ -146,4 +146,15 @@ module.factory('User', function($resource) { method : 'PUT' } }); +}); + +module.factory('Role', function($resource) { + return $resource('/auth-server/rest/saas/admin/realms/:realm/roles/:roleId', { + realm : '@realm', + roleId : '@roleId' + }, { + update : { + method : 'PUT' + } + }); }); \ No newline at end of file diff --git a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/partials/menu.html b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/partials/menu.html index c46189d3f9..effc324437 100755 --- a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/partials/menu.html +++ b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/partials/menu.html @@ -3,23 +3,29 @@