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 f1befd7ec2..211ed20369 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 @@ -59,6 +59,9 @@ module.config([ '$routeProvider', function($routeProvider) { user : function(UserLoader) { return UserLoader(); }, + applications : function(ApplicationListLoader) { + return ApplicationListLoader(); + }, roles : function(RoleListLoader) { return RoleListLoader(); } 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 5f76681c67..3dedcb065c 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 @@ -198,13 +198,20 @@ Array.prototype.remove = function(from, to) { return this.push.apply(this, rest); }; -module.controller('UserRoleMappingCtrl', function($scope, $http, realm, user, roles, RealmRoleMapping) { +module.controller('UserRoleMappingCtrl', function($scope, $http, realm, user, roles, applications, RealmRoleMapping, ApplicationRoleMapping, ApplicationRole) { $scope.realm = realm; $scope.user = user; $scope.realmRoles = angular.copy(roles); $scope.selectedRealmRoles = []; $scope.selectedRealmMappings = []; $scope.realmMappings = []; + $scope.applications = applications; + $scope.applicationRoles = []; + $scope.selectedApplicationRoles = []; + $scope.selectedApplicationMappings = []; + $scope.applicationMappings = []; + + $scope.realmMappings = RealmRoleMapping.query({realm : realm.id, userId : user.username}, function(){ for (var i = 0; i < $scope.realmMappings.length; i++) { @@ -238,7 +245,6 @@ module.controller('UserRoleMappingCtrl', function($scope, $http, realm, user, ro }; $scope.deleteRealmRole = function() { - console.log('deleteRealmRole'); $http.delete('/auth-server/rest/saas/admin/realms/' + realm.id + '/users/' + user.username + '/role-mappings/realm', {data : $scope.selectedRealmMappings, headers : {"content-type" : "application/json"}}).success(function() { for (var i = 0; i < $scope.selectedRealmMappings.length; i++) { @@ -253,6 +259,59 @@ module.controller('UserRoleMappingCtrl', function($scope, $http, realm, user, ro }); }; + $scope.addApplicationRole = function() { + $http.post('/auth-server/rest/saas/admin/realms/' + realm.id + '/users/' + user.username + '/role-mappings/applications/' + $scope.application.id, + $scope.selectedApplicationRoles).success(function() { + for (var i = 0; i < $scope.selectedApplicationRoles.length; i++) { + var role = $scope.selectedApplicationRoles[i]; + var idx = $scope.applicationRoles.indexOf($scope.selectedApplicationRoles[i]); + if (idx != -1) { + $scope.applicationRoles.splice(idx, 1); + $scope.applicationMappings.push(role); + } + } + $scope.selectedApplicationRoles = []; + }); + }; + + $scope.deleteApplicationRole = function() { + $http.delete('/auth-server/rest/saas/admin/realms/' + realm.id + '/users/' + user.username + '/role-mappings/applications/' + $scope.application.id, + {data : $scope.selectedApplicationMappings, headers : {"content-type" : "application/json"}}).success(function() { + for (var i = 0; i < $scope.selectedApplicationMappings.length; i++) { + var role = $scope.selectedApplicationMappings[i]; + var idx = $scope.applicationMappings.indexOf($scope.selectedApplicationMappings[i]); + if (idx != -1) { + $scope.applicationMappings.splice(idx, 1); + $scope.applicationRoles.push(role); + } + } + $scope.selectedApplicationMappings = []; + }); + }; + + + $scope.changeApplication = function() { + $scope.applicationRoles = ApplicationRole.query({realm : realm.id, userId : user.username, application : $scope.application.id}, function() { + $scope.applicationMappings = ApplicationRoleMapping.query({realm : realm.id, userId : user.username, application : $scope.application.id}, function(){ + for (var i = 0; i < $scope.applicationMappings.length; i++) { + var role = $scope.applicationMappings[i]; + for (var j = 0; j < $scope.applicationRoles.length; j++) { + var realmRole = $scope.applicationRoles[j]; + if (realmRole.id == role.id) { + var idx = $scope.applicationRoles.indexOf(realmRole); + if (idx != -1) { + $scope.applicationRoles.splice(idx, 1); + break; + } + } + } + } + }); + + } + ); + }; + }); @@ -372,7 +431,7 @@ module.controller('ApplicationRoleDetailCtrl', function($scope, realm, applicati var l = headers().location; var id = l.substring(l.lastIndexOf("/") + 1); - $location.url("/realms/" + realm.id + "/roles/" + id); + $location.url("/realms/" + realm.id + "/applications/" + application.id + "/roles/" + id); Notifications.success("Created role"); }); 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 e8c352662a..9636d46f11 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 @@ -111,6 +111,16 @@ module.factory('RealmRoleMapping', function($resource) { }); }); +module.factory('ApplicationRoleMapping', function($resource) { + return $resource('/auth-server/rest/saas/admin/realms/:realm/users/:userId/role-mappings/applications/:application', { + realm : '@realm', + userId : '@userId', + application : "@application" + }); +}); + + + module.factory('RealmRoles', function($resource) { return $resource('/auth-server/rest/saas/admin/realms/:realm/roles', { realm : '@realm' diff --git a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/partials/role-mappings.html b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/partials/role-mappings.html index d0cb06ae55..d4ffcceb35 100755 --- a/examples/as7-eap-demo/server/src/main/webapp/saas/admin/partials/role-mappings.html +++ b/examples/as7-eap-demo/server/src/main/webapp/saas/admin/partials/role-mappings.html @@ -6,13 +6,13 @@