12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035 |
- module.controller('ResourceServerCtrl', function($scope, realm, ResourceServer) {
- $scope.realm = realm;
- ResourceServer.query({realm : realm.realm}, function (data) {
- $scope.servers = data;
- });
- });
- module.controller('ResourceServerDetailCtrl', function($scope, $http, $route, $location, $upload, $modal, realm, ResourceServer, client, AuthzDialog, Notifications) {
- $scope.realm = realm;
- $scope.client = client;
- ResourceServer.get({
- realm : $route.current.params.realm,
- client : client.id
- }, function(data) {
- $scope.server = angular.copy(data);
- $scope.changed = false;
- $scope.$watch('server', function() {
- if (!angular.equals($scope.server, data)) {
- $scope.changed = true;
- }
- }, true);
- $scope.save = function() {
- ResourceServer.update({realm : realm.realm, client : $scope.server.clientId}, $scope.server, function() {
- $route.reload();
- Notifications.success("The resource server has been created.");
- });
- }
- $scope.reset = function() {
- $route.reload();
- }
- $scope.export = function() {
- $scope.exportSettings = true;
- ResourceServer.settings({
- realm : $route.current.params.realm,
- client : client.id
- }, function(data) {
- var tmp = angular.fromJson(data);
- $scope.settings = angular.toJson(tmp, true);
- })
- }
- $scope.downloadSettings = function() {
- saveAs(new Blob([$scope.settings], { type: 'application/json' }), $scope.server.name + "-authz-config.json");
- }
- $scope.cancelExport = function() {
- delete $scope.settings
- }
- $scope.onFileSelect = function($fileContent) {
- $scope.server = angular.copy(JSON.parse($fileContent));
- $scope.importing = true;
- };
- $scope.viewImportDetails = function() {
- $modal.open({
- templateUrl: resourceUrl + '/partials/modal/view-object.html',
- controller: 'ObjectModalCtrl',
- resolve: {
- object: function () {
- return $scope.server;
- }
- }
- })
- };
- $scope.import = function () {
- ResourceServer.import({realm : realm.realm, client : client.id}, $scope.server, function() {
- $route.reload();
- Notifications.success("The resource server has been updated.");
- });
- }
- });
- });
- var Resources = {
- delete: function(ResourceServerResource, realm, client, $scope, AuthzDialog, $location, Notifications, $route) {
- ResourceServerResource.permissions({
- realm : realm,
- client : client.id,
- rsrid : $scope.resource._id
- }, function (permissions) {
- var msg = "";
- if (permissions.length > 0 && !$scope.deleteConsent) {
- msg = "<p>This resource is referenced in some permissions:</p>";
- msg += "<ul>";
- for (i = 0; i < permissions.length; i++) {
- msg+= "<li><strong>" + permissions[i].name + "</strong></li>";
- }
- msg += "</ul>";
- msg += "<p>If you remove this resource, the permissions above will be affected and will not be associated with this resource anymore.</p>";
- }
- AuthzDialog.confirmDeleteWithMsg($scope.resource.name, "Resource", msg, function() {
- ResourceServerResource.delete({realm : realm, client : $scope.client.id, rsrid : $scope.resource._id}, null, function() {
- $location.url("/realms/" + realm + "/clients/" + $scope.client.id + "/authz/resource-server/resource");
- $route.reload();
- Notifications.success("The resource has been deleted.");
- });
- });
- });
- }
- }
- var Policies = {
- delete: function(service, realm, client, $scope, AuthzDialog, $location, Notifications, $route, isPermission) {
- var msg = "";
- service.dependentPolicies({
- realm : realm,
- client : client.id,
- id : $scope.policy.id
- }, function (dependentPolicies) {
- if (dependentPolicies.length > 0 && !$scope.deleteConsent) {
- msg = "<p>This policy is being used by other policies:</p>";
- msg += "<ul>";
- for (i = 0; i < dependentPolicies.length; i++) {
- msg+= "<li><strong>" + dependentPolicies[i].name + "</strong></li>";
- }
- msg += "</ul>";
- msg += "<p>If you remove this policy, the policies above will be affected and will not be associated with this policy anymore.</p>";
- }
- AuthzDialog.confirmDeleteWithMsg($scope.policy.name, isPermission ? "Permission" : "Policy", msg, function() {
- service.delete({realm : realm, client : $scope.client.id, id : $scope.policy.id}, null, function() {
- if (isPermission) {
- $location.url("/realms/" + realm + "/clients/" + $scope.client.id + "/authz/resource-server/permission");
- Notifications.success("The permission has been deleted.");
- } else {
- $location.url("/realms/" + realm + "/clients/" + $scope.client.id + "/authz/resource-server/policy");
- Notifications.success("The policy has been deleted.");
- }
- $route.reload();
- });
- });
- });
- }
- }
- module.controller('ResourceServerResourceCtrl', function($scope, $http, $route, $location, realm, ResourceServer, ResourceServerResource, client, AuthzDialog, Notifications, viewState) {
- $scope.realm = realm;
- $scope.client = client;
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- deep: false,
- max : 20,
- first : 0
- };
- $scope.listSizes = [5, 10, 20];
- ResourceServer.get({
- realm : $route.current.params.realm,
- client : client.id
- }, function(data) {
- $scope.server = data;
- $scope.createPolicy = function(resource) {
- viewState.state = {};
- viewState.state.previousUrl = '/realms/' + $route.current.params.realm + '/clients/' + client.id + '/authz/resource-server/resource';
- $location.path('/realms/' + $route.current.params.realm + '/clients/' + client.id + '/authz/resource-server/permission/resource/create').search({rsrid: resource._id});
- }
- $scope.searchQuery();
- });
- $scope.firstPage = function() {
- $scope.query.first = 0;
- $scope.searchQuery();
- }
- $scope.previousPage = function() {
- $scope.query.first -= parseInt($scope.query.max);
- if ($scope.query.first < 0) {
- $scope.query.first = 0;
- }
- $scope.searchQuery();
- }
- $scope.nextPage = function() {
- $scope.query.first += parseInt($scope.query.max);
- $scope.searchQuery();
- }
- $scope.searchQuery = function() {
- $scope.searchLoaded = false;
- ResourceServerResource.query($scope.query, function(response) {
- $scope.searchLoaded = true;
- $scope.lastSearch = $scope.query.search;
- $scope.resources = response;
- if ($scope.detailsFilter) {
- $scope.showDetails();
- }
- });
- };
- $scope.loadDetails = function (resource) {
- if (resource.details) {
- resource.details.loaded = !resource.details.loaded;
- return;
- }
- resource.details = {loaded: false};
- ResourceServerResource.scopes({
- realm : $route.current.params.realm,
- client : client.id,
- rsrid : resource._id
- }, function(response) {
- resource.scopes = response;
- ResourceServerResource.permissions({
- realm : $route.current.params.realm,
- client : client.id,
- rsrid : resource._id
- }, function(response) {
- resource.policies = response;
- resource.details.loaded = true;
- });
- });
- }
- $scope.showDetails = function(item, event) {
- if (event.target.localName == 'a' || event.target.localName == 'button') {
- return;
- }
- if (item) {
- $scope.loadDetails(item);
- } else {
- for (i = 0; i < $scope.resources.length; i++) {
- $scope.loadDetails($scope.resources[i]);
- }
- }
- };
- $scope.delete = function(resource) {
- $scope.resource = resource;
- Resources.delete(ResourceServerResource, $route.current.params.realm, client, $scope, AuthzDialog, $location, Notifications, $route);
- };
- });
- module.controller('ResourceServerResourceDetailCtrl', function($scope, $http, $route, $location, realm, ResourceServer, client, ResourceServerResource, ResourceServerScope, AuthzDialog, Notifications) {
- $scope.realm = realm;
- $scope.client = client;
- $scope.scopesUiSelect = {
- minimumInputLength: 1,
- delay: 500,
- allowClear: true,
- query: function (query) {
- var data = {results: []};
- if ('' == query.term.trim()) {
- query.callback(data);
- return;
- }
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- name: query.term.trim(),
- deep: false,
- max : 20,
- first : 0
- };
- ResourceServerScope.query($scope.query, function(response) {
- data.results = response;
- query.callback(data);
- });
- },
- formatResult: function(object, container, query) {
- return object.name;
- },
- formatSelection: function(object, container, query) {
- return object.name;
- }
- };
- var $instance = this;
- ResourceServer.get({
- realm : $route.current.params.realm,
- client : client.id
- }, function(data) {
- $scope.server = data;
- var resourceId = $route.current.params.rsrid;
- if (!resourceId) {
- $scope.create = true;
- $scope.changed = false;
- var resource = {};
- resource.scopes = [];
- resource.attributes = {};
- resource.uris = [];
- $scope.resource = angular.copy(resource);
- $scope.$watch('resource', function() {
- if (!angular.equals($scope.resource, resource)) {
- $scope.changed = true;
- }
- }, true);
- $scope.$watch('newUri', function() {
- if ($scope.newUri && $scope.newUri.length > 0) {
- $scope.changed = true;
- }
- }, true);
- $scope.save = function() {
- if ($scope.newUri && $scope.newUri.length > 0) {
- $scope.addUri();
- }
- for (i = 0; i < $scope.resource.scopes.length; i++) {
- delete $scope.resource.scopes[i].text;
- }
- $instance.checkNameAvailability(function () {
- ResourceServerResource.save({realm : realm.realm, client : $scope.client.id}, $scope.resource, function(data) {
- $location.url("/realms/" + realm.realm + "/clients/" + $scope.client.id + "/authz/resource-server/resource/" + data._id);
- Notifications.success("The resource has been created.");
- });
- });
- }
- $scope.reset = function() {
- $location.url("/realms/" + realm.realm + "/clients/" + $scope.client.id + "/authz/resource-server/resource/");
- }
- } else {
- ResourceServerResource.get({
- realm : $route.current.params.realm,
- client : client.id,
- rsrid : $route.current.params.rsrid,
- }, function(data) {
- if (!data.scopes) {
- data.scopes = [];
- }
- if (!data.attributes) {
- data.attributes = {};
- }
- $scope.resource = angular.copy(data);
- $scope.changed = false;
- $scope.originalResource = angular.copy($scope.resource);
- $scope.$watch('resource', function() {
- if (!angular.equals($scope.resource, data)) {
- $scope.changed = true;
- }
- }, true);
- $scope.$watch('newUri', function() {
- if ($scope.newUri && $scope.newUri.length > 0) {
- $scope.changed = true;
- }
- }, true);
- $scope.save = function() {
- if ($scope.newUri && $scope.newUri.length > 0) {
- $scope.addUri();
- }
- for (i = 0; i < $scope.resource.scopes.length; i++) {
- delete $scope.resource.scopes[i].text;
- }
- var keys = Object.keys($scope.resource.attributes);
- for (var k = 0; k < keys.length; k++) {
- var key = keys[k];
- var value = $scope.resource.attributes[key];
- var values = value.toString().split(',');
- $scope.resource.attributes[key] = [];
- for (j = 0; j < values.length; j++) {
- $scope.resource.attributes[key].push(values[j]);
- }
- }
- $instance.checkNameAvailability(function () {
- ResourceServerResource.update({realm : realm.realm, client : $scope.client.id, rsrid : $scope.resource._id}, $scope.resource, function() {
- $route.reload();
- Notifications.success("The resource has been updated.");
- });
- });
- }
- $scope.remove = function() {
- Resources.delete(ResourceServerResource, $route.current.params.realm, client, $scope, AuthzDialog, $location, Notifications, $route);
- }
- $scope.reset = function() {
- $route.reload();
- }
- });
- }
- });
- $scope.checkNewNameAvailability = function () {
- $instance.checkNameAvailability(function () {});
- }
- this.checkNameAvailability = function (onSuccess) {
- if (!$scope.resource.name || $scope.resource.name.trim().length == 0) {
- return;
- }
- ResourceServerResource.search({
- realm : $route.current.params.realm,
- client : client.id,
- rsrid : $route.current.params.rsrid,
- name: $scope.resource.name
- }, function(data) {
- if (data && data._id && data._id != $scope.resource._id) {
- Notifications.error("Name already in use by another resource, please choose another one.");
- } else {
- onSuccess();
- }
- });
- }
- $scope.addAttribute = function() {
- $scope.resource.attributes[$scope.newAttribute.key] = $scope.newAttribute.value;
- delete $scope.newAttribute;
- }
- $scope.removeAttribute = function(key) {
- delete $scope.resource.attributes[key];
- }
- $scope.addUri = function() {
- $scope.resource.uris.push($scope.newUri);
- $scope.newUri = "";
- }
- $scope.deleteUri = function(index) {
- $scope.resource.uris.splice(index, 1);
- }
- });
- var Scopes = {
- delete: function(ResourceServerScope, realm, client, $scope, AuthzDialog, $location, Notifications, $route) {
- ResourceServerScope.permissions({
- realm : realm,
- client : client.id,
- id : $scope.scope.id
- }, function (permissions) {
- var msg = "";
- if (permissions.length > 0 && !$scope.deleteConsent) {
- msg = "<p>This scope is referenced in some permissions:</p>";
- msg += "<ul>";
- for (i = 0; i < permissions.length; i++) {
- msg+= "<li><strong>" + permissions[i].name + "</strong></li>";
- }
- msg += "</ul>";
- msg += "<p>If you remove this scope, the permissions above will be affected and will not be associated with this scope anymore.</p>";
- }
- AuthzDialog.confirmDeleteWithMsg($scope.scope.name, "Scope", msg, function() {
- ResourceServerScope.delete({realm : realm, client : $scope.client.id, id : $scope.scope.id}, null, function() {
- $location.url("/realms/" + realm + "/clients/" + $scope.client.id + "/authz/resource-server/scope");
- $route.reload();
- Notifications.success("The scope has been deleted.");
- });
- });
- });
- }
- }
- module.controller('ResourceServerScopeCtrl', function($scope, $http, $route, $location, realm, ResourceServer, ResourceServerScope,client, AuthzDialog, Notifications, viewState) {
- $scope.realm = realm;
- $scope.client = client;
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- deep: false,
- max : 20,
- first : 0
- };
- $scope.listSizes = [5, 10, 20];
- ResourceServer.get({
- realm : $route.current.params.realm,
- client : client.id
- }, function(data) {
- $scope.server = data;
- $scope.createPolicy = function(scope) {
- viewState.state = {};
- viewState.state.previousUrl = '/realms/' + $route.current.params.realm + '/clients/' + client.id + '/authz/resource-server/scope';
- $location.path('/realms/' + $route.current.params.realm + '/clients/' + client.id + '/authz/resource-server/permission/scope/create').search({scpid: scope.id});
- }
- $scope.searchQuery();
- });
- $scope.firstPage = function() {
- $scope.query.first = 0;
- $scope.searchQuery();
- }
- $scope.previousPage = function() {
- $scope.query.first -= parseInt($scope.query.max);
- if ($scope.query.first < 0) {
- $scope.query.first = 0;
- }
- $scope.searchQuery();
- }
- $scope.nextPage = function() {
- $scope.query.first += parseInt($scope.query.max);
- $scope.searchQuery();
- }
- $scope.searchQuery = function(detailsFilter) {
- $scope.searchLoaded = false;
- ResourceServerScope.query($scope.query, function(response) {
- $scope.scopes = response;
- $scope.searchLoaded = true;
- $scope.lastSearch = $scope.query.search;
- if ($scope.detailsFilter) {
- $scope.showDetails();
- }
- });
- };
- $scope.loadDetails = function (scope) {
- if (scope.details) {
- scope.details.loaded = !scope.details.loaded;
- return;
- }
- scope.details = {loaded: false};
- ResourceServerScope.resources({
- realm : $route.current.params.realm,
- client : client.id,
- id : scope.id
- }, function(response) {
- scope.resources = response;
- ResourceServerScope.permissions({
- realm : $route.current.params.realm,
- client : client.id,
- id : scope.id
- }, function(response) {
- scope.policies = response;
- scope.details.loaded = true;
- });
- });
- }
- $scope.showDetails = function(item, event) {
- if (event.target.localName == 'a' || event.target.localName == 'button') {
- return;
- }
- if (item) {
- $scope.loadDetails(item);
- } else {
- for (i = 0; i < $scope.scopes.length; i++) {
- $scope.loadDetails($scope.scopes[i]);
- }
- }
- };
- $scope.delete = function(scope) {
- $scope.scope = scope;
- Scopes.delete(ResourceServerScope, $route.current.params.realm, client, $scope, AuthzDialog, $location, Notifications, $route);
- };
- });
- module.controller('ResourceServerScopeDetailCtrl', function($scope, $http, $route, $location, realm, ResourceServer, client, ResourceServerScope, AuthzDialog, Notifications) {
- $scope.realm = realm;
- $scope.client = client;
- var $instance = this;
- ResourceServer.get({
- realm : $route.current.params.realm,
- client : client.id
- }, function(data) {
- $scope.server = data;
- var scopeId = $route.current.params.id;
- if (!scopeId) {
- $scope.create = true;
- $scope.changed = false;
- var scope = {};
- $scope.scope = angular.copy(scope);
- $scope.$watch('scope', function() {
- if (!angular.equals($scope.scope, scope)) {
- $scope.changed = true;
- }
- }, true);
- $scope.save = function() {
- $instance.checkNameAvailability(function () {
- ResourceServerScope.save({realm : realm.realm, client : $scope.client.id}, $scope.scope, function(data) {
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/scope/" + data.id);
- Notifications.success("The scope has been created.");
- });
- });
- }
- $scope.reset = function() {
- $location.url("/realms/" + realm.realm + "/clients/" + $scope.client.id + "/authz/resource-server/scope/");
- }
- } else {
- ResourceServerScope.get({
- realm : $route.current.params.realm,
- client : client.id,
- id : $route.current.params.id,
- }, function(data) {
- $scope.scope = angular.copy(data);
- $scope.changed = false;
- $scope.$watch('scope', function() {
- if (!angular.equals($scope.scope, data)) {
- $scope.changed = true;
- }
- }, true);
- $scope.originalScope = angular.copy($scope.scope);
- $scope.save = function() {
- $instance.checkNameAvailability(function () {
- ResourceServerScope.update({realm : realm.realm, client : $scope.client.id, id : $scope.scope.id}, $scope.scope, function() {
- $scope.changed = false;
- Notifications.success("The scope has been updated.");
- });
- });
- }
- $scope.remove = function() {
- Scopes.delete(ResourceServerScope, $route.current.params.realm, client, $scope, AuthzDialog, $location, Notifications, $route);
- }
- $scope.reset = function() {
- $route.reload();
- }
- });
- }
- });
- $scope.checkNewNameAvailability = function () {
- $instance.checkNameAvailability(function () {});
- }
- this.checkNameAvailability = function (onSuccess) {
- if (!$scope.scope.name || $scope.scope.name.trim().length == 0) {
- return;
- }
- ResourceServerScope.search({
- realm : $route.current.params.realm,
- client : client.id,
- name: $scope.scope.name
- }, function(data) {
- if (data && data.id && data.id != $scope.scope.id) {
- Notifications.error("Name already in use by another scope, please choose another one.");
- } else {
- onSuccess();
- }
- });
- }
- });
- module.controller('ResourceServerPolicyCtrl', function($scope, $http, $route, $location, realm, ResourceServer, ResourceServerPolicy, PolicyProvider, client, AuthzDialog, Notifications, KcStrings) {
- $scope.realm = realm;
- $scope.client = client;
- $scope.policyProviders = [];
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- permission: false,
- max: 20,
- first : 0
- };
- $scope.listSizes = [5, 10, 20];
- PolicyProvider.query({
- realm : $route.current.params.realm,
- client : client.id
- }, function (data) {
- for (i = 0; i < data.length; i++) {
- if (data[i].type != 'resource' && data[i].type != 'scope') {
- $scope.policyProviders.push(data[i]);
- }
- }
- });
- ResourceServer.get({
- realm : $route.current.params.realm,
- client : client.id
- }, function(data) {
- $scope.server = data;
- $scope.searchQuery();
- });
- $scope.addPolicy = function(policyType) {
- if (KcStrings.endsWith(policyType.type, '.js')) {
- ResourceServerPolicy.save({realm : realm.realm, client : client.id, type: policyType.type}, {name: policyType.name, type: policyType.type}, function(data) {
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/");
- Notifications.success("The policy has been created.");
- });
- } else {
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/" + policyType.type + "/create");
- }
- }
- $scope.firstPage = function() {
- $scope.query.first = 0;
- $scope.searchQuery();
- }
- $scope.previousPage = function() {
- $scope.query.first -= parseInt($scope.query.max);
- if ($scope.query.first < 0) {
- $scope.query.first = 0;
- }
- $scope.searchQuery();
- }
- $scope.nextPage = function() {
- $scope.query.first += parseInt($scope.query.max);
- $scope.searchQuery();
- }
- $scope.searchQuery = function() {
- $scope.searchLoaded = false;
- ResourceServerPolicy.query($scope.query, function(data) {
- $scope.policies = data;
- $scope.searchLoaded = true;
- $scope.lastSearch = $scope.query.search;
- if ($scope.detailsFilter) {
- $scope.showDetails();
- }
- });
- };
- $scope.loadDetails = function (policy) {
- if (policy.details) {
- policy.details.loaded = !policy.details.loaded;
- return;
- }
- policy.details = {loaded: false};
- ResourceServerPolicy.dependentPolicies({
- realm : $route.current.params.realm,
- client : client.id,
- id : policy.id
- }, function(response) {
- policy.dependentPolicies = response;
- policy.details.loaded = true;
- });
- }
- $scope.showDetails = function(item, event) {
- if (event.target.localName == 'a' || event.target.localName == 'button') {
- return;
- }
- if (item) {
- $scope.loadDetails(item);
- } else {
- for (i = 0; i < $scope.policies.length; i++) {
- $scope.loadDetails($scope.policies[i]);
- }
- }
- };
- $scope.delete = function(policy) {
- $scope.policy = policy;
- Policies.delete(ResourceServerPolicy, $route.current.params.realm, client, $scope, AuthzDialog, $location, Notifications, $route, false);
- };
- });
- module.controller('ResourceServerPermissionCtrl', function($scope, $http, $route, $location, realm, ResourceServer, ResourceServerPermission, PolicyProvider, client, AuthzDialog, Notifications) {
- $scope.realm = realm;
- $scope.client = client;
- $scope.policyProviders = [];
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- max : 20,
- first : 0
- };
- $scope.listSizes = [5, 10, 20];
- PolicyProvider.query({
- realm : $route.current.params.realm,
- client : client.id
- }, function (data) {
- for (i = 0; i < data.length; i++) {
- if (data[i].type == 'resource' || data[i].type == 'scope') {
- $scope.policyProviders.push(data[i]);
- }
- }
- });
- ResourceServer.get({
- realm : $route.current.params.realm,
- client : client.id
- }, function(data) {
- $scope.server = data;
- $scope.searchQuery();
- });
- $scope.addPolicy = function(policyType) {
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/permission/" + policyType.type + "/create");
- }
- $scope.firstPage = function() {
- $scope.query.first = 0;
- $scope.searchQuery();
- }
- $scope.previousPage = function() {
- $scope.query.first -= parseInt($scope.query.max);
- if ($scope.query.first < 0) {
- $scope.query.first = 0;
- }
- $scope.searchQuery();
- }
- $scope.nextPage = function() {
- $scope.query.first += parseInt($scope.query.max);
- $scope.searchQuery();
- }
- $scope.searchQuery = function() {
- $scope.searchLoaded = false;
- ResourceServerPermission.query($scope.query, function(data) {
- $scope.policies = data;
- $scope.searchLoaded = true;
- $scope.lastSearch = $scope.query.search;
- if ($scope.detailsFilter) {
- $scope.showDetails();
- }
- });
- };
- $scope.loadDetails = function (policy) {
- if (policy.details) {
- policy.details.loaded = !policy.details.loaded;
- return;
- }
- policy.details = {loaded: false};
- ResourceServerPermission.associatedPolicies({
- realm : $route.current.params.realm,
- client : client.id,
- id : policy.id
- }, function(response) {
- policy.associatedPolicies = response;
- policy.details.loaded = true;
- });
- }
- $scope.showDetails = function(item, event) {
- if (event.target.localName == 'a' || event.target.localName == 'button') {
- return;
- }
- if (item) {
- $scope.loadDetails(item);
- } else {
- for (i = 0; i < $scope.policies.length; i++) {
- $scope.loadDetails($scope.policies[i]);
- }
- }
- };
- $scope.delete = function(policy) {
- $scope.policy = policy;
- Policies.delete(ResourceServerPermission, $route.current.params.realm, client, $scope, AuthzDialog, $location, Notifications, $route, true);
- };
- });
- module.controller('ResourceServerPolicyResourceDetailCtrl', function($scope, $route, $location, realm, client, PolicyController, ResourceServerPermission, ResourceServerResource, policyViewState) {
- PolicyController.onInit({
- getPolicyType : function() {
- return "resource";
- },
- isPermission : function() {
- return true;
- },
- onInit : function() {
- $scope.resourcesUiSelect = {
- minimumInputLength: 1,
- delay: 500,
- allowClear: true,
- id: function(resource){ return resource._id; },
- query: function (query) {
- var data = {results: []};
- if ('' == query.term.trim()) {
- query.callback(data);
- return;
- }
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- name: query.term.trim(),
- deep: false,
- max : 20,
- first : 0
- };
- ResourceServerResource.query($scope.query, function(response) {
- data.results = response;
- query.callback(data);
- });
- },
- formatResult: function(object, container, query) {
- object.text = object.name;
- return object.name;
- }
- };
- $scope.policiesUiSelect = {
- minimumInputLength: 1,
- delay: 500,
- allowClear: true,
- query: function (query) {
- var data = {results: []};
- if ('' == query.term.trim()) {
- query.callback(data);
- return;
- }
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- permission: false,
- name: query.term.trim(),
- max : 20,
- first : 0
- };
- ResourceServerPermission.searchPolicies($scope.query, function(response) {
- data.results = response;
- query.callback(data);
- });
- },
- formatResult: function(object, container, query) {
- object.text = object.name;
- return object.name;
- }
- };
- $scope.applyToResourceType = function() {
- if ($scope.applyToResourceTypeFlag) {
- $scope.selectedResource = null;
- } else {
- $scope.policy.resourceType = null;
- }
- }
- },
- onInitUpdate : function(policy) {
- if (!policy.resourceType) {
- $scope.selectedResource = {};
- ResourceServerPermission.resources({
- realm: $route.current.params.realm,
- client: client.id,
- id: policy.id
- }, function (resources) {
- resources[0].text = resources[0].name;
- $scope.selectedResource = resources[0];
- var copy = angular.copy($scope.selectedResource);
- $scope.$watch('selectedResource', function() {
- if (!angular.equals($scope.selectedResource, copy)) {
- $scope.changed = true;
- }
- }, true);
- });
- } else {
- $scope.applyToResourceTypeFlag = true;
- }
- ResourceServerPermission.associatedPolicies({
- realm : $route.current.params.realm,
- client : client.id,
- id : policy.id
- }, function(policies) {
- $scope.selectedPolicies = [];
- for (i = 0; i < policies.length; i++) {
- policies[i].text = policies[i].name;
- $scope.selectedPolicies.push(policies[i]);
- }
- var copy = angular.copy($scope.selectedPolicies);
- $scope.$watch('selectedPolicies', function() {
- if (!angular.equals($scope.selectedPolicies, copy)) {
- $scope.changed = true;
- }
- }, true);
- });
- },
- onUpdate : function() {
- if ($scope.selectedResource && $scope.selectedResource._id) {
- $scope.policy.resources = [];
- $scope.policy.resources.push($scope.selectedResource._id);
- } else {
- $scope.policy.resources = [];
- }
- var policies = [];
- for (i = 0; i < $scope.selectedPolicies.length; i++) {
- policies.push($scope.selectedPolicies[i].id);
- }
- $scope.policy.policies = policies;
- delete $scope.policy.config;
- },
- onInitCreate : function(newPolicy) {
- policyViewState.state.previousPage.name = 'authz-add-resource-permission';
- $scope.selectedResource = null;
- var copy = angular.copy($scope.selectedResource);
- $scope.$watch('selectedResource', function() {
- if (!angular.equals($scope.selectedResource, copy)) {
- $scope.changed = true;
- }
- }, true);
- $scope.selectedPolicies = null;
- var copy = angular.copy($scope.selectedPolicies);
- $scope.$watch('selectedPolicies', function() {
- if (!angular.equals($scope.selectedPolicies, copy)) {
- $scope.changed = true;
- }
- }, true);
- var resourceId = $location.search()['rsrid'];
- if (resourceId) {
- ResourceServerResource.get({
- realm : $route.current.params.realm,
- client : client.id,
- rsrid : resourceId
- }, function(data) {
- data.text = data.name;
- $scope.selectedResource = data;
- });
- }
- },
- onCreate : function() {
- if ($scope.selectedResource && $scope.selectedResource._id) {
- $scope.policy.resources = [];
- $scope.policy.resources.push($scope.selectedResource._id);
- } else {
- delete $scope.policy.resources
- }
- var policies = [];
- if ($scope.selectedPolicies) {
- for (i = 0; i < $scope.selectedPolicies.length; i++) {
- policies.push($scope.selectedPolicies[i].id);
- }
- }
- $scope.policy.policies = policies;
- delete $scope.policy.config;
- },
- onSaveState : function(policy) {
- policyViewState.state.selectedResource = $scope.selectedResource;
- policyViewState.state.applyToResourceTypeFlag = $scope.applyToResourceTypeFlag;
- },
- onRestoreState : function(policy) {
- $scope.selectedResource = policyViewState.state.selectedResource;
- $scope.applyToResourceTypeFlag = policyViewState.state.applyToResourceTypeFlag;
- policy.resourceType = policyViewState.state.policy.resourceType;
- }
- }, realm, client, $scope);
- });
- module.controller('ResourceServerPolicyScopeDetailCtrl', function($scope, $route, $location, realm, client, PolicyController, ResourceServerPolicy, ResourceServerResource, ResourceServerScope, policyViewState) {
- PolicyController.onInit({
- getPolicyType : function() {
- return "scope";
- },
- isPermission : function() {
- return true;
- },
- onInit : function() {
- $scope.scopesUiSelect = {
- minimumInputLength: 1,
- delay: 500,
- allowClear: true,
- query: function (query) {
- var data = {results: []};
- if ('' == query.term.trim()) {
- query.callback(data);
- return;
- }
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- name: query.term.trim(),
- deep: false,
- max : 20,
- first : 0
- };
- ResourceServerScope.query($scope.query, function(response) {
- data.results = response;
- query.callback(data);
- });
- },
- formatResult: function(object, container, query) {
- object.text = object.name;
- return object.name;
- }
- };
- $scope.resourcesUiSelect = {
- minimumInputLength: 1,
- delay: 500,
- allowClear: true,
- id: function(resource){ return resource._id; },
- query: function (query) {
- var data = {results: []};
- if ('' == query.term.trim()) {
- query.callback(data);
- return;
- }
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- name: query.term.trim(),
- deep: false,
- max : 20,
- first : 0
- };
- ResourceServerResource.query($scope.query, function(response) {
- data.results = response;
- query.callback(data);
- });
- },
- formatResult: function(object, container, query) {
- object.text = object.name;
- return object.name;
- }
- };
- $scope.policiesUiSelect = {
- minimumInputLength: 1,
- delay: 500,
- allowClear: true,
- query: function (query) {
- var data = {results: []};
- if ('' == query.term.trim()) {
- query.callback(data);
- return;
- }
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- permission: false,
- name: query.term.trim(),
- max : 20,
- first : 0
- };
- ResourceServerPolicy.query($scope.query, function(response) {
- data.results = response;
- query.callback(data);
- });
- },
- formatResult: function(object, container, query) {
- object.text = object.name;
- return object.name;
- }
- };
- $scope.selectResource = function() {
- $scope.selectedScopes = null;
- if ($scope.selectedResource) {
- ResourceServerResource.scopes({
- realm: $route.current.params.realm,
- client: client.id,
- rsrid: $scope.selectedResource._id
- }, function (data) {
- $scope.resourceScopes = data;
- });
- }
- }
- },
- onInitUpdate : function(policy) {
- ResourceServerPolicy.resources({
- realm : $route.current.params.realm,
- client : client.id,
- id : policy.id
- }, function(resources) {
- if (resources.length > 0) {
- for (i = 0; i < resources.length; i++) {
- ResourceServerResource.get({
- realm: $route.current.params.realm,
- client: client.id,
- rsrid: resources[0]._id,
- }, function (resource) {
- ResourceServerResource.query({
- realm: $route.current.params.realm,
- client: client.id,
- _id: resource._id,
- deep: false
- }, function (resource) {
- resource[0].text = resource[0].name;
- $scope.selectedResource = resource[0];
- var copy = angular.copy($scope.selectedResource);
- $scope.$watch('selectedResource', function() {
- if (!angular.equals($scope.selectedResource, copy)) {
- $scope.changed = true;
- }
- }, true);
- ResourceServerResource.scopes({
- realm: $route.current.params.realm,
- client: client.id,
- rsrid: resource[0]._id
- }, function (scopes) {
- $scope.resourceScopes = scopes;
- });
- });
- });
- }
- ResourceServerPolicy.scopes({
- realm : $route.current.params.realm,
- client : client.id,
- id : policy.id
- }, function(scopes) {
- $scope.selectedScopes = [];
- for (i = 0; i < scopes.length; i++) {
- scopes[i].text = scopes[i].name;
- $scope.selectedScopes.push(scopes[i].id);
- }
- var copy = angular.copy($scope.selectedScopes);
- $scope.$watch('selectedScopes', function() {
- if (!angular.equals($scope.selectedScopes, copy)) {
- $scope.changed = true;
- }
- }, true);
- });
- } else {
- $scope.selectedResource = null;
- var copy = angular.copy($scope.selectedResource);
- $scope.$watch('selectedResource', function() {
- if (!angular.equals($scope.selectedResource, copy)) {
- $scope.changed = true;
- }
- }, true);
- ResourceServerPolicy.scopes({
- realm : $route.current.params.realm,
- client : client.id,
- id : policy.id
- }, function(scopes) {
- $scope.selectedScopes = [];
- for (i = 0; i < scopes.length; i++) {
- scopes[i].text = scopes[i].name;
- $scope.selectedScopes.push(scopes[i]);
- }
- var copy = angular.copy($scope.selectedScopes);
- $scope.$watch('selectedScopes', function() {
- if (!angular.equals($scope.selectedScopes, copy)) {
- $scope.changed = true;
- }
- }, true);
- });
- }
- });
- ResourceServerPolicy.associatedPolicies({
- realm : $route.current.params.realm,
- client : client.id,
- id : policy.id
- }, function(policies) {
- $scope.selectedPolicies = [];
- for (i = 0; i < policies.length; i++) {
- policies[i].text = policies[i].name;
- $scope.selectedPolicies.push(policies[i]);
- }
- var copy = angular.copy($scope.selectedPolicies);
- $scope.$watch('selectedPolicies', function() {
- if (!angular.equals($scope.selectedPolicies, copy)) {
- $scope.changed = true;
- }
- }, true);
- });
- },
- onUpdate : function() {
- if ($scope.selectedResource != null) {
- $scope.policy.resources = [$scope.selectedResource._id];
- } else {
- $scope.policy.resources = [];
- }
- var scopes = [];
- for (i = 0; i < $scope.selectedScopes.length; i++) {
- if ($scope.selectedScopes[i].id) {
- scopes.push($scope.selectedScopes[i].id);
- } else {
- scopes.push($scope.selectedScopes[i]);
- }
- }
- $scope.policy.scopes = scopes;
- var policies = [];
- if ($scope.selectedPolicies) {
- for (i = 0; i < $scope.selectedPolicies.length; i++) {
- policies.push($scope.selectedPolicies[i].id);
- }
- }
- $scope.policy.policies = policies;
- delete $scope.policy.config;
- },
- onInitCreate : function(newPolicy) {
- policyViewState.state.previousPage.name = 'authz-add-scope-permission';
- var scopeId = $location.search()['scpid'];
- if (scopeId) {
- ResourceServerScope.get({
- realm: $route.current.params.realm,
- client: client.id,
- id: scopeId,
- }, function (data) {
- data.text = data.name;
- if (!$scope.policy.scopes) {
- $scope.selectedScopes = [];
- }
- $scope.selectedScopes.push(data);
- });
- }
- },
- onCreate : function() {
- if ($scope.selectedResource != null) {
- $scope.policy.resources = [$scope.selectedResource._id];
- }
- var scopes = [];
- for (i = 0; i < $scope.selectedScopes.length; i++) {
- if ($scope.selectedScopes[i].id) {
- scopes.push($scope.selectedScopes[i].id);
- } else {
- scopes.push($scope.selectedScopes[i]);
- }
- }
- $scope.policy.scopes = scopes;
- var policies = [];
- if ($scope.selectedPolicies) {
- for (i = 0; i < $scope.selectedPolicies.length; i++) {
- policies.push($scope.selectedPolicies[i].id);
- }
- }
- $scope.policy.policies = policies;
- delete $scope.policy.config;
- },
- onSaveState : function(policy) {
- policyViewState.state.selectedScopes = $scope.selectedScopes;
- policyViewState.state.selectedResource = $scope.selectedResource;
- policyViewState.state.resourceScopes = $scope.resourceScopes;
- },
- onRestoreState : function(policy) {
- $scope.selectedScopes = policyViewState.state.selectedScopes;
- $scope.selectedResource = policyViewState.state.selectedResource;
- $scope.resourceScopes = policyViewState.state.resourceScopes;
- }
- }, realm, client, $scope);
- });
- module.controller('ResourceServerPolicyUserDetailCtrl', function($scope, $route, realm, client, PolicyController, User) {
- PolicyController.onInit({
- getPolicyType : function() {
- return "user";
- },
- onInit : function() {
- $scope.usersUiSelect = {
- minimumInputLength: 1,
- delay: 500,
- allowClear: true,
- query: function (query) {
- var data = {results: []};
- if ('' == query.term.trim()) {
- query.callback(data);
- return;
- }
- User.query({realm: $route.current.params.realm, search: query.term.trim(), max: 20}, function(response) {
- data.results = response;
- query.callback(data);
- });
- },
- formatResult: function(object, container, query) {
- return object.username;
- }
- };
- $scope.selectedUsers = [];
- $scope.selectUser = function(user) {
- if (!user || !user.id) {
- return;
- }
- $scope.selectedUser = null;
- for (i = 0; i < $scope.selectedUsers.length; i++) {
- if ($scope.selectedUsers[i].id == user.id) {
- return;
- }
- }
- $scope.selectedUsers.push(user);
- }
- $scope.removeFromList = function(list, user) {
- for (i = 0; i < angular.copy(list).length; i++) {
- if (user == list[i]) {
- list.splice(i, 1);
- }
- }
- }
- },
- onInitUpdate : function(policy) {
- var selectedUsers = [];
- if (policy.users) {
- var users = policy.users;
- for (i = 0; i < users.length; i++) {
- User.get({realm: $route.current.params.realm, userId: users[i]}, function(data) {
- selectedUsers.push(data);
- $scope.selectedUsers = angular.copy(selectedUsers);
- });
- }
- }
- $scope.$watch('selectedUsers', function() {
- if (!angular.equals($scope.selectedUsers, selectedUsers)) {
- $scope.changed = true;
- } else {
- $scope.changed = false;
- }
- }, true);
- },
- onUpdate : function() {
- var users = [];
- for (i = 0; i < $scope.selectedUsers.length; i++) {
- users.push($scope.selectedUsers[i].id);
- }
- $scope.policy.users = users;
- delete $scope.policy.config;
- },
- onCreate : function() {
- var users = [];
- for (i = 0; i < $scope.selectedUsers.length; i++) {
- users.push($scope.selectedUsers[i].id);
- }
- $scope.policy.users = users;
- delete $scope.policy.config;
- }
- }, realm, client, $scope);
- });
- module.controller('ResourceServerPolicyClientDetailCtrl', function($scope, $route, realm, client, PolicyController, Client) {
- PolicyController.onInit({
- getPolicyType : function() {
- return "client";
- },
- onInit : function() {
- clientSelectControl($scope, $route.current.params.realm, Client);
- $scope.selectedClients = [];
- $scope.selectClient = function(client) {
- if (!client || !client.id) {
- return;
- }
- $scope.selectedClient = null;
- for (var i = 0; i < $scope.selectedClients.length; i++) {
- if ($scope.selectedClients[i].id == client.id) {
- return;
- }
- }
- $scope.selectedClients.push(client);
- }
- $scope.removeFromList = function(client) {
- var index = $scope.selectedClients.indexOf(client);
- if (index != -1) {
- $scope.selectedClients.splice(index, 1);
- }
- }
- },
- onInitUpdate : function(policy) {
- var selectedClients = [];
- if (policy.clients) {
- var clients = policy.clients;
- for (var i = 0; i < clients.length; i++) {
- Client.get({realm: $route.current.params.realm, client: clients[i]}, function(data) {
- selectedClients.push(data);
- $scope.selectedClients = angular.copy(selectedClients);
- });
- }
- }
- $scope.$watch('selectedClients', function() {
- if (!angular.equals($scope.selectedClients, selectedClients)) {
- $scope.changed = true;
- } else {
- $scope.changed = false;
- }
- }, true);
- },
- onUpdate : function() {
- var clients = [];
- for (var i = 0; i < $scope.selectedClients.length; i++) {
- clients.push($scope.selectedClients[i].id);
- }
- $scope.policy.clients = clients;
- delete $scope.policy.config;
- },
- onInitCreate : function() {
- var selectedClients = [];
- $scope.$watch('selectedClients', function() {
- if (!angular.equals($scope.selectedClients, selectedClients)) {
- $scope.changed = true;
- }
- }, true);
- },
- onCreate : function() {
- var clients = [];
- for (var i = 0; i < $scope.selectedClients.length; i++) {
- clients.push($scope.selectedClients[i].id);
- }
- $scope.policy.clients = clients;
- delete $scope.policy.config;
- }
- }, realm, client, $scope);
- });
- module.controller('ResourceServerPolicyRoleDetailCtrl', function($scope, $route, realm, client, Client, ClientRole, PolicyController, Role, RoleById) {
- PolicyController.onInit({
- getPolicyType : function() {
- return "role";
- },
- onInit : function() {
- Role.query({realm: $route.current.params.realm}, function(data) {
- $scope.roles = data;
- });
- Client.query({realm: $route.current.params.realm}, function (data) {
- $scope.clients = data;
- });
- $scope.selectedRoles = [];
- $scope.selectRole = function(role) {
- if (!role || !role.id) {
- return;
- }
- $scope.selectedRole = null;
- for (i = 0; i < $scope.selectedRoles.length; i++) {
- if ($scope.selectedRoles[i].id == role.id) {
- return;
- }
- }
- $scope.selectedRoles.push(role);
- var clientRoles = [];
- if ($scope.clientRoles) {
- for (i = 0; i < $scope.clientRoles.length; i++) {
- if ($scope.clientRoles[i].id != role.id) {
- clientRoles.push($scope.clientRoles[i]);
- }
- }
- $scope.clientRoles = clientRoles;
- }
- }
- $scope.removeFromList = function(role) {
- if ($scope.clientRoles && $scope.selectedClient && $scope.selectedClient.id == role.containerId) {
- $scope.clientRoles.push(role);
- }
- var index = $scope.selectedRoles.indexOf(role);
- if (index != -1) {
- $scope.selectedRoles.splice(index, 1);
- }
- }
- $scope.selectClient = function() {
- if (!$scope.selectedClient) {
- $scope.clientRoles = [];
- return;
- }
- ClientRole.query({realm: $route.current.params.realm, client: $scope.selectedClient.id}, function(data) {
- var roles = [];
- for (j = 0; j < data.length; j++) {
- var defined = false;
- for (i = 0; i < $scope.selectedRoles.length; i++) {
- if ($scope.selectedRoles[i].id == data[j].id) {
- defined = true;
- break;
- }
- }
- if (!defined) {
- data[j].container = {};
- data[j].container.name = $scope.selectedClient.clientId;
- roles.push(data[j]);
- }
- }
- $scope.clientRoles = roles;
- });
- }
- },
- onInitUpdate : function(policy) {
- var selectedRoles = [];
- if (policy.roles) {
- var roles = policy.roles;
- for (i = 0; i < roles.length; i++) {
- RoleById.get({realm: $route.current.params.realm, role: roles[i].id}, function(data) {
- for (i = 0; i < roles.length; i++) {
- if (roles[i].id == data.id) {
- data.required = roles[i].required ? true : false;
- }
- }
- for (i = 0; i < $scope.clients.length; i++) {
- if ($scope.clients[i].id == data.containerId) {
- data.container = {};
- data.container.name = $scope.clients[i].clientId;
- }
- }
- selectedRoles.push(data);
- $scope.selectedRoles = angular.copy(selectedRoles);
- });
- }
- }
- $scope.$watch('selectedRoles', function() {
- if (!angular.equals($scope.selectedRoles, selectedRoles)) {
- $scope.changed = true;
- } else {
- $scope.changed = false;
- }
- }, true);
- },
- onUpdate : function() {
- var roles = [];
- for (i = 0; i < $scope.selectedRoles.length; i++) {
- var role = {};
- role.id = $scope.selectedRoles[i].id;
- if ($scope.selectedRoles[i].required) {
- role.required = $scope.selectedRoles[i].required;
- }
- roles.push(role);
- }
- $scope.policy.roles = roles;
- delete $scope.policy.config;
- },
- onCreate : function() {
- var roles = [];
- for (i = 0; i < $scope.selectedRoles.length; i++) {
- var role = {};
- role.id = $scope.selectedRoles[i].id;
- if ($scope.selectedRoles[i].required) {
- role.required = $scope.selectedRoles[i].required;
- }
- roles.push(role);
- }
- $scope.policy.roles = roles;
- delete $scope.policy.config;
- }
- }, realm, client, $scope);
-
- $scope.hasRealmRole = function () {
- for (i = 0; i < $scope.selectedRoles.length; i++) {
- if (!$scope.selectedRoles[i].clientRole) {
- return true;
- }
- }
- return false;
- }
- $scope.hasClientRole = function () {
- for (i = 0; i < $scope.selectedRoles.length; i++) {
- if ($scope.selectedRoles[i].clientRole) {
- return true;
- }
- }
- return false;
- }
- });
- module.controller('ResourceServerPolicyGroupDetailCtrl', function($scope, $route, realm, client, Client, Groups, Group, PolicyController, Notifications, $translate) {
- PolicyController.onInit({
- getPolicyType : function() {
- return "group";
- },
- onInit : function() {
- $scope.tree = [];
- Groups.query({realm: $route.current.params.realm}, function(groups) {
- $scope.groups = groups;
- $scope.groupList = [
- {"id" : "realm", "name": $translate.instant('groups'),
- "subGroups" : groups}
- ];
- });
- var isLeaf = function(node) {
- return node.id != "realm" && (!node.subGroups || node.subGroups.length == 0);
- }
- $scope.getGroupClass = function(node) {
- if (node.id == "realm") {
- return 'pficon pficon-users';
- }
- if (isLeaf(node)) {
- return 'normal';
- }
- if (node.subGroups.length && node.collapsed) return 'collapsed';
- if (node.subGroups.length && !node.collapsed) return 'expanded';
- return 'collapsed';
- }
- $scope.getSelectedClass = function(node) {
- if (node.selected) {
- return 'selected';
- } else if ($scope.cutNode && $scope.cutNode.id == node.id) {
- return 'cut';
- }
- return undefined;
- }
- $scope.selectGroup = function(group) {
- for (i = 0; i < $scope.selectedGroups.length; i++) {
- if ($scope.selectedGroups[i].id == group.id) {
- return
- }
- }
- if (group.id == "realm") {
- Notifications.error("You must choose a group");
- return;
- }
- $scope.selectedGroups.push({id: group.id, path: group.path});
- $scope.changed = true;
- }
- $scope.extendChildren = function(group) {
- $scope.changed = true;
- }
- $scope.removeFromList = function(group) {
- var index = $scope.selectedGroups.indexOf(group);
- if (index != -1) {
- $scope.selectedGroups.splice(index, 1);
- $scope.changed = true;
- }
- }
- },
- onInitCreate : function(policy) {
- var selectedGroups = [];
- $scope.selectedGroups = angular.copy(selectedGroups);
- $scope.$watch('selectedGroups', function() {
- if (!angular.equals($scope.selectedGroups, selectedGroups)) {
- $scope.changed = true;
- } else {
- $scope.changed = PolicyController.isNewAssociatedPolicy();
- }
- }, true);
- },
- onInitUpdate : function(policy) {
- $scope.selectedGroups = policy.groups;
- angular.forEach($scope.selectedGroups, function(group, index){
- Group.get({realm: $route.current.params.realm, groupId: group.id}, function (existing) {
- group.path = existing.path;
- });
- });
- $scope.$watch('selectedGroups', function() {
- if (!$scope.changed) {
- return;
- }
- if (!angular.equals($scope.selectedGroups, selectedGroups)) {
- $scope.changed = true;
- } else {
- $scope.changed = false;
- }
- }, true);
- },
- onUpdate : function() {
- $scope.policy.groups = $scope.selectedGroups;
- delete $scope.policy.config;
- },
- onCreate : function() {
- $scope.policy.groups = $scope.selectedGroups;
- delete $scope.policy.config;
- }
- }, realm, client, $scope);
- });
- module.controller('ResourceServerPolicyJSDetailCtrl', function($scope, $route, $location, realm, PolicyController, client, serverInfo) {
- PolicyController.onInit({
- getPolicyType : function() {
- return "js";
- },
- onInit : function() {
- $scope.readOnly = !serverInfo.featureEnabled('UPLOAD_SCRIPTS');
- $scope.initEditor = function(editor){
- editor.$blockScrolling = Infinity;
- editor.setReadOnly($scope.readOnly);
- var session = editor.getSession();
- session.setMode('ace/mode/javascript');
- };
- },
- onInitUpdate : function(policy) {
- },
- onUpdate : function() {
- delete $scope.policy.config;
- },
- onInitCreate : function(newPolicy) {
- },
- onCreate : function() {
- delete $scope.policy.config;
- }
- }, realm, client, $scope);
- });
- module.controller('ResourceServerPolicyTimeDetailCtrl', function($scope, $route, $location, realm, PolicyController, client) {
- function clearEmptyStrings() {
- if ($scope.policy.notBefore != undefined && $scope.policy.notBefore.trim() == '') {
- $scope.policy.notBefore = null;
- }
- if ($scope.policy.notOnOrAfter != undefined && $scope.policy.notOnOrAfter.trim() == '') {
- $scope.policy.notOnOrAfter = null;
- }
- }
- PolicyController.onInit({
- getPolicyType : function() {
- return "time";
- },
- onInit : function() {
- },
- onInitUpdate : function(policy) {
- if (policy.dayMonth) {
- policy.dayMonth = parseInt(policy.dayMonth);
- }
- if (policy.dayMonthEnd) {
- policy.dayMonthEnd = parseInt(policy.dayMonthEnd);
- }
- if (policy.month) {
- policy.month = parseInt(policy.month);
- }
- if (policy.monthEnd) {
- policy.monthEnd = parseInt(policy.monthEnd);
- }
- if (policy.year) {
- policy.year = parseInt(policy.year);
- }
- if (policy.yearEnd) {
- policy.yearEnd = parseInt(policy.yearEnd);
- }
- if (policy.hour) {
- policy.hour = parseInt(policy.hour);
- }
- if (policy.hourEnd) {
- policy.hourEnd = parseInt(policy.hourEnd);
- }
- if (policy.minute) {
- policy.minute = parseInt(policy.minute);
- }
- if (policy.minuteEnd) {
- policy.minuteEnd = parseInt(policy.minuteEnd);
- }
- },
- onUpdate : function() {
- clearEmptyStrings();
- delete $scope.policy.config;
- },
- onInitCreate : function(newPolicy) {
- },
- onCreate : function() {
- clearEmptyStrings();
- delete $scope.policy.config;
- }
- }, realm, client, $scope);
- $scope.isRequired = function () {
- var policy = $scope.policy;
- if (!policy) {
- return true;
- }
- if (policy.notOnOrAfter || policy.notBefore
- || policy.dayMonth
- || policy.month
- || policy.year
- || policy.hour
- || policy.minute) {
- return false;
- }
- return true;
- }
- });
- module.controller('ResourceServerPolicyAggregateDetailCtrl', function($scope, $route, $location, realm, PolicyController, ResourceServerPolicy, client, PolicyProvider, policyViewState) {
- PolicyController.onInit({
- getPolicyType : function() {
- return "aggregate";
- },
- onInit : function() {
- $scope.policiesUiSelect = {
- minimumInputLength: 1,
- delay: 500,
- allowClear: true,
- query: function (query) {
- var data = {results: []};
- if ('' == query.term.trim()) {
- query.callback(data);
- return;
- }
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- permission: false,
- name: query.term.trim(),
- max : 20,
- first : 0
- };
- ResourceServerPolicy.query($scope.query, function(response) {
- data.results = response;
- query.callback(data);
- });
- },
- formatResult: function(object, container, query) {
- object.text = object.name;
- return object.name;
- }
- };
- },
- onInitUpdate : function(policy) {
- ResourceServerPolicy.associatedPolicies({
- realm : $route.current.params.realm,
- client : client.id,
- id : policy.id
- }, function(policies) {
- $scope.selectedPolicies = [];
- for (i = 0; i < policies.length; i++) {
- policies[i].text = policies[i].name;
- $scope.selectedPolicies.push(policies[i]);
- }
- var copy = angular.copy($scope.selectedPolicies);
- $scope.$watch('selectedPolicies', function() {
- if (!angular.equals($scope.selectedPolicies, copy)) {
- $scope.changed = true;
- }
- }, true);
- });
- },
- onUpdate : function() {
- var policies = [];
- for (i = 0; i < $scope.selectedPolicies.length; i++) {
- policies.push($scope.selectedPolicies[i].id);
- }
- $scope.policy.policies = policies;
- delete $scope.policy.config;
- },
- onInitCreate : function(newPolicy) {
- policyViewState.state.previousPage.name = 'authz-add-aggregated-policy';
- },
- onCreate : function() {
- var policies = [];
- for (i = 0; i < $scope.selectedPolicies.length; i++) {
- policies.push($scope.selectedPolicies[i].id);
- }
- $scope.policy.policies = policies;
- delete $scope.policy.config;
- }
- }, realm, client, $scope);
- });
- module.controller('ResourceServerPolicyClientScopeDetailCtrl', function($scope, $route, realm, client, ClientScope, PolicyController) {
- PolicyController.onInit({
- getPolicyType : function() {
- return "client-scope";
- },
- onInit : function() {
- ClientScope.query({realm: $route.current.params.realm}, function(data) {
- $scope.clientScopes = data;
- });
- $scope.selectedClientScopes = [];
- $scope.selectClientScope = function(clientScope) {
- if (!clientScope || !clientScope.id) {
- return;
- }
- $scope.selectedClientScope = null;
- for (i = 0; i < $scope.selectedClientScopes.length; i++) {
- if ($scope.selectedClientScopes[i].id == clientScope.id) {
- return;
- }
- }
- $scope.selectedClientScopes.push(clientScope);
- }
- $scope.removeFromList = function(clientScope) {
- var index = $scope.selectedClientScopes.indexOf(clientScope);
- if (index != -1) {
- $scope.selectedClientScopes.splice(index, 1);
- }
- }
- },
- onInitUpdate : function(policy) {
- var selectedClientScopes = [];
- if (policy.clientScopes) {
- var clientScopes = policy.clientScopes;
- for (i = 0; i < clientScopes.length; i++) {
- ClientScope.get({realm: $route.current.params.realm, clientScope: clientScopes[i].id}, function(data) {
- for (i = 0; i < clientScopes.length; i++) {
- if (clientScopes[i].id == data.id) {
- data.required = clientScopes[i].required ? true : false;
- }
- }
- selectedClientScopes.push(data);
- $scope.selectedClientScopes = angular.copy(selectedClientScopes);
- });
- }
- }
- $scope.$watch('selectedClientScopes', function() {
- if (!angular.equals($scope.selectedClientScopes, selectedClientScopes)) {
- $scope.changed = true;
- } else {
- $scope.changed = false;
- }
- }, true);
- },
- onUpdate : function() {
- var clientScopes = [];
- for (i = 0; i < $scope.selectedClientScopes.length; i++) {
- var clientScope = {};
- clientScope.id = $scope.selectedClientScopes[i].id;
- if ($scope.selectedClientScopes[i].required) {
- clientScope.required = $scope.selectedClientScopes[i].required;
- }
- clientScopes.push(clientScope);
- }
- $scope.policy.clientScopes = clientScopes;
- delete $scope.policy.config;
- },
- onCreate : function() {
- var clientScopes = [];
- for (i = 0; i < $scope.selectedClientScopes.length; i++) {
- var clientScope = {};
- clientScope.id = $scope.selectedClientScopes[i].id;
- if ($scope.selectedClientScopes[i].required) {
- clientScope.required = $scope.selectedClientScopes[i].required;
- }
- clientScopes.push(clientScope);
- }
- $scope.policy.clientScopes = clientScopes;
- delete $scope.policy.config;
- }
- }, realm, client, $scope);
- });
- module.controller('ResourceServerPolicyRegexDetailCtrl', function($scope, realm, client, PolicyController) {
- PolicyController.onInit({
- getPolicyType : function() {
- return "regex";
- },
- onInit : function() {
- },
- onInitUpdate : function(policy) {
- },
- onUpdate : function() {
- delete $scope.policy.config;
- },
- onCreate : function() {
- delete $scope.policy.config;
- }
- }, realm, client, $scope);
- });
- module.service("PolicyController", function($http, $route, $location, ResourceServer, ResourceServerPolicy, ResourceServerPermission, AuthzDialog, Notifications, policyViewState, PolicyProvider, viewState) {
- var PolicyController = {};
- PolicyController.isNewAssociatedPolicy = function() {
- return $route.current.params['new_policy'] != null;
- }
- PolicyController.isBackNewAssociatedPolicy = function() {
- return $route.current.params['back'] != null;
- }
- PolicyController.onInit = function(delegate, realm, client, $scope) {
- $scope.policyProviders = [];
- PolicyProvider.query({
- realm : $route.current.params.realm,
- client : client.id
- }, function (data) {
- for (i = 0; i < data.length; i++) {
- if (data[i].type != 'resource' && data[i].type != 'scope') {
- $scope.policyProviders.push(data[i]);
- }
- }
- });
- if ((!policyViewState.state || !PolicyController.isBackNewAssociatedPolicy()) && !PolicyController.isNewAssociatedPolicy()) {
- policyViewState.state = {};
- }
- if (!policyViewState.state.previousPage) {
- policyViewState.state.previousPage = {};
- }
- $scope.policyViewState = policyViewState;
- $scope.addPolicy = function(policyType) {
- policyViewState.state.policy = $scope.policy;
- if (delegate.onSaveState) {
- delegate.onSaveState($scope.policy);
- }
- if ($scope.selectedPolicies) {
- policyViewState.state.selectedPolicies = $scope.selectedPolicies;
- }
- var previousUrl = window.location.href.substring(window.location.href.indexOf('/realms'));
- if (previousUrl.indexOf('back=true') == -1) {
- previousUrl = previousUrl + (previousUrl.indexOf('?') == -1 ? '?' : '&') + 'back=true';
- }
- policyViewState.state.previousUrl = previousUrl;
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/" + policyType.type + "/create?new_policy=true");
- }
- $scope.detailPolicy = function(policy) {
- policyViewState.state.policy = $scope.policy;
- if (delegate.onSaveState) {
- delegate.onSaveState($scope.policy);
- }
- if ($scope.selectedPolicies) {
- policyViewState.state.selectedPolicies = $scope.selectedPolicies;
- }
- var previousUrl = window.location.href.substring(window.location.href.indexOf('/realms'));
- if (previousUrl.indexOf('back=true') == -1) {
- previousUrl = previousUrl + (previousUrl.indexOf('?') == -1 ? '?' : '&') + 'back=true';
- }
- policyViewState.state.previousUrl = previousUrl;
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/" + policy.type + "/" + policy.id + "?new_policy=true");
- }
- $scope.removePolicy = function(list, policy) {
- for (i = 0; i < angular.copy(list).length; i++) {
- if (policy.id == list[i].id) {
- list.splice(i, 1);
- }
- }
- }
- $scope.selectPolicy = function(policy) {
- if (!policy || !policy.id) {
- return;
- }
- if (!$scope.selectedPolicies) {
- $scope.selectedPolicies = [];
- }
- $scope.selectedPolicy = null;
- for (i = 0; i < $scope.selectedPolicies.length; i++) {
- if ($scope.selectedPolicies[i].id == policy.id) {
- return;
- }
- }
- $scope.selectedPolicies.push(policy);
- }
- $scope.createNewPolicy = function() {
- $scope.showNewPolicy = true;
- }
- $scope.cancelCreateNewPolicy = function() {
- $scope.showNewPolicy = false;
- }
- $scope.historyBackOnSaveOrCancel = PolicyController.isNewAssociatedPolicy();
- if (!delegate.isPermission) {
- delegate.isPermission = function () {
- return false;
- }
- }
- var service = ResourceServerPolicy;
- if (delegate.isPermission()) {
- service = ResourceServerPermission;
- }
- $scope.realm = realm;
- $scope.client = client;
- $scope.decisionStrategies = ['AFFIRMATIVE', 'UNANIMOUS', 'CONSENSUS'];
- $scope.logics = ['POSITIVE', 'NEGATIVE'];
- delegate.onInit();
- var $instance = this;
- ResourceServer.get({
- realm : $route.current.params.realm,
- client : client.id
- }, function(data) {
- $scope.server = data;
- var policyId = $route.current.params.id;
- if (!policyId) {
- $scope.create = true;
- var policy = {};
- policy.type = delegate.getPolicyType();
- policy.config = {};
- policy.logic = 'POSITIVE';
- policy.decisionStrategy = 'UNANIMOUS';
- $scope.changed = $scope.historyBackOnSaveOrCancel || PolicyController.isBackNewAssociatedPolicy();
- if (viewState.state != null && viewState.state.previousUrl != null) {
- $scope.previousUrl = viewState.state.previousUrl;
- policyViewState.state.rootUrl = $scope.previousUrl;
- viewState.state = {};
- }
- $scope.policy = angular.copy(policy);
- $scope.$watch('policy', function() {
- if (!angular.equals($scope.policy, policy)) {
- $scope.changed = true;
- }
- }, true);
- if (PolicyController.isBackNewAssociatedPolicy()) {
- if (delegate.onRestoreState) {
- delegate.onRestoreState($scope.policy);
- }
- $instance.restoreState($scope);
- } else if (delegate.onInitCreate) {
- delegate.onInitCreate(policy);
- }
- $scope.save = function() {
- $instance.checkNameAvailability(function () {
- if (delegate.onCreate) {
- delegate.onCreate();
- }
- service.save({realm : realm.realm, client : client.id, type: $scope.policy.type}, $scope.policy, function(data) {
- if (delegate.isPermission()) {
- if ($scope.historyBackOnSaveOrCancel || policyViewState.state.rootUrl != null) {
- if (policyViewState.state.rootUrl != null) {
- $location.url(policyViewState.state.rootUrl);
- } else {
- policyViewState.state.newPolicyName = $scope.policy.name;
- $location.url(policyViewState.state.previousUrl);
- }
- } else {
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/permission/" + $scope.policy.type + "/" + data.id);
- }
- Notifications.success("The permission has been created.");
- } else {
- if ($scope.historyBackOnSaveOrCancel) {
- policyViewState.state.newPolicyName = $scope.policy.name;
- $location.url(policyViewState.state.previousUrl);
- } else {
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/" + $scope.policy.type + "/" + data.id);
- }
- Notifications.success("The policy has been created.");
- }
- });
- });
- }
- $scope.reset = function() {
- if (delegate.isPermission()) {
- if ($scope.historyBackOnSaveOrCancel || policyViewState.state.rootUrl != null) {
- if (policyViewState.state.rootUrl != null) {
- $location.url(policyViewState.state.rootUrl);
- } else {
- $location.url(policyViewState.state.previousUrl);
- }
- } else {
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/permission/");
- }
- } else {
- if ($scope.historyBackOnSaveOrCancel) {
- $location.url(policyViewState.state.previousUrl);
- } else {
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/");
- }
- }
- }
- } else {
- service.get({
- realm: realm.realm,
- client : client.id,
- type: delegate.getPolicyType(),
- id: $route.current.params.id
- }, function(data) {
- $scope.originalPolicy = data;
- var policy = angular.copy(data);
- $scope.changed = $scope.historyBackOnSaveOrCancel || PolicyController.isBackNewAssociatedPolicy();
- $scope.policy = angular.copy(policy);
- if (PolicyController.isBackNewAssociatedPolicy()) {
- if (delegate.onRestoreState) {
- delegate.onRestoreState($scope.policy);
- }
- $instance.restoreState($scope);
- } else if (delegate.onInitUpdate) {
- delegate.onInitUpdate($scope.policy);
- }
- $scope.$watch('policy', function() {
- if (!angular.equals($scope.policy, policy)) {
- $scope.changed = true;
- }
- }, true);
- $scope.save = function() {
- $instance.checkNameAvailability(function () {
- if (delegate.onUpdate) {
- delegate.onUpdate();
- }
- service.update({realm : realm.realm, client : client.id, type: $scope.policy.type, id : $scope.policy.id}, $scope.policy, function() {
- if (delegate.isPermission()) {
- if ($scope.historyBackOnSaveOrCancel) {
- $location.url(policyViewState.state.previousUrl);
- } else {
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/permission/" + $scope.policy.type + "/" + $scope.policy.id);
- }
- $route.reload();
- Notifications.success("The permission has been updated.");
- } else {
- if ($scope.historyBackOnSaveOrCancel) {
- $location.url(policyViewState.state.previousUrl);
- } else {
- $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/authz/resource-server/policy/" + $scope.policy.type + "/" + $scope.policy.id);
- }
- $route.reload();
- Notifications.success("The policy has been updated.");
- }
- });
- });
- }
- $scope.reset = function() {
- if ($scope.historyBackOnSaveOrCancel) {
- $location.url(policyViewState.state.previousUrl);
- } else {
- var freshPolicy = angular.copy(data);
- if (delegate.onInitUpdate) {
- delegate.onInitUpdate(freshPolicy);
- }
- $scope.policy = angular.copy(freshPolicy);
- $scope.changed = false;
- }
- }
- });
- $scope.remove = function() {
- Policies.delete(ResourceServerPolicy, $route.current.params.realm, client, $scope, AuthzDialog, $location, Notifications, $route, delegate.isPermission());
- }
- }
- });
- $scope.checkNewNameAvailability = function () {
- $instance.checkNameAvailability(function () {});
- }
- this.checkNameAvailability = function (onSuccess) {
- if (!$scope.policy.name || $scope.policy.name.trim().length == 0) {
- return;
- }
- ResourceServerPolicy.search({
- realm: $route.current.params.realm,
- client: client.id,
- name: $scope.policy.name
- }, function(data) {
- if (data && data.id && data.id != $scope.policy.id) {
- Notifications.error("Name already in use by another policy or permission, please choose another one.");
- } else {
- onSuccess();
- }
- });
- }
- this.restoreState = function($scope) {
- $scope.policy.name = policyViewState.state.policy.name;
- $scope.policy.description = policyViewState.state.policy.description;
- $scope.policy.decisionStrategy = policyViewState.state.policy.decisionStrategy;
- $scope.policy.logic = policyViewState.state.policy.logic;
- $scope.selectedPolicies = policyViewState.state.selectedPolicies;
- if (!$scope.selectedPolicies) {
- $scope.selectedPolicies = [];
- }
- $scope.changed = true;
- var previousPage = policyViewState.state.previousPage;
- if (policyViewState.state.newPolicyName) {
- ResourceServerPolicy.query({
- realm: realm.realm,
- client : client.id,
- permission: false,
- name: policyViewState.state.newPolicyName,
- max : 20,
- first : 0
- }, function(response) {
- for (i = 0; i < response.length; i++) {
- if (response[i].name == policyViewState.state.newPolicyName) {
- response[i].text = response[i].name;
- $scope.selectedPolicies.push(response[i]);
- }
- }
- var rootUrl = policyViewState.state.rootUrl;
- policyViewState.state = {};
- policyViewState.state.previousPage = previousPage;
- policyViewState.state.rootUrl = rootUrl;
- });
- } else {
- var rootUrl = policyViewState.state.rootUrl;
- policyViewState.state = {};
- policyViewState.state.previousPage = previousPage;
- policyViewState.state.rootUrl = rootUrl;
- }
- }
- }
- return PolicyController;
- });
- module.controller('PolicyEvaluateCtrl', function($scope, $http, $route, $location, realm, clients, roles, ResourceServer, client, ResourceServerResource, ResourceServerScope, User, Notifications) {
- $scope.realm = realm;
- $scope.client = client;
- $scope.clients = clients;
- $scope.roles = roles;
- $scope.authzRequest = {};
- $scope.authzRequest.resources = [];
- $scope.authzRequest.context = {};
- $scope.authzRequest.context.attributes = {};
- $scope.authzRequest.roleIds = [];
- $scope.resultUrl = resourceUrl + '/partials/authz/policy/resource-server-policy-evaluate-result.html';
- $scope.addContextAttribute = function() {
- if (!$scope.newContextAttribute.value || $scope.newContextAttribute.value == '') {
- Notifications.error("You must provide a value to a context attribute.");
- return;
- }
- $scope.authzRequest.context.attributes[$scope.newContextAttribute.key] = $scope.newContextAttribute.value;
- delete $scope.newContextAttribute;
- }
- $scope.removeContextAttribute = function(key) {
- delete $scope.authzRequest.context.attributes[key];
- }
- $scope.getContextAttribute = function(key) {
- for (i = 0; i < $scope.defaultContextAttributes.length; i++) {
- if ($scope.defaultContextAttributes[i].key == key) {
- return $scope.defaultContextAttributes[i];
- }
- }
- return $scope.authzRequest.context.attributes[key];
- }
- $scope.getContextAttributeName = function(key) {
- var attribute = $scope.getContextAttribute(key);
- if (!attribute.name) {
- return key;
- }
- return attribute.name;
- }
- $scope.defaultContextAttributes = [
- {
- key : "custom",
- name : "Custom Attribute...",
- custom: true
- },
- {
- key : "kc.identity.authc.method",
- name : "Authentication Method",
- values: [
- {
- key : "pwd",
- name : "Password"
- },
- {
- key : "otp",
- name : "One-Time Password"
- },
- {
- key : "kbr",
- name : "Kerberos"
- }
- ]
- },
- {
- key : "kc.realm.name",
- name : "Realm"
- },
- {
- key : "kc.time.date_time",
- name : "Date/Time (MM/dd/yyyy hh:mm:ss)"
- },
- {
- key : "kc.client.network.ip_address",
- name : "Client IPv4 Address"
- },
- {
- key : "kc.client.network.host",
- name : "Client Host"
- },
- {
- key : "kc.client.user_agent",
- name : "Client/User Agent"
- }
- ];
- $scope.isDefaultContextAttribute = function() {
- if (!$scope.newContextAttribute) {
- return true;
- }
- if ($scope.newContextAttribute.custom) {
- return false;
- }
- if (!$scope.getContextAttribute($scope.newContextAttribute.key).custom) {
- return true;
- }
- return false;
- }
- $scope.selectDefaultContextAttribute = function() {
- $scope.newContextAttribute = angular.copy($scope.newContextAttribute);
- }
- $scope.setApplyToResourceType = function() {
- delete $scope.newResource;
- $scope.authzRequest.resources = [];
- }
- $scope.addResource = function() {
- var resource = angular.copy($scope.newResource);
- if (!resource) {
- resource = {};
- }
- delete resource.text;
- if (!$scope.newScopes || (resource._id != null && $scope.newScopes.length > 0 && $scope.newScopes[0].id)) {
- $scope.newScopes = [];
- }
- var scopes = [];
- for (i = 0; i < $scope.newScopes.length; i++) {
- if ($scope.newScopes[i].name) {
- scopes.push($scope.newScopes[i].name);
- } else {
- scopes.push($scope.newScopes[i]);
- }
- }
- resource.scopes = scopes;
- $scope.authzRequest.resources.push(resource);
- delete $scope.newResource;
- delete $scope.newScopes;
- }
- $scope.removeResource = function(index) {
- $scope.authzRequest.resources.splice(index, 1);
- }
- $scope.resolveScopes = function() {
- if ($scope.newResource._id) {
- $scope.newResource.scopes = [];
- $scope.scopes = [];
- ResourceServerResource.scopes({
- realm: $route.current.params.realm,
- client: client.id,
- rsrid: $scope.newResource._id
- }, function (data) {
- $scope.scopes = data;
- });
- }
- }
- $scope.reevaluate = function() {
- if ($scope.authzRequest.entitlements) {
- $scope.entitlements();
- } else {
- $scope.save();
- }
- }
- $scope.showAuthzData = function() {
- $scope.showRpt = true;
- }
- $scope.save = function() {
- $scope.authzRequest.entitlements = false;
- if ($scope.applyResourceType) {
- if (!$scope.newResource) {
- $scope.newResource = {};
- }
- if (!$scope.newScopes || ($scope.newResource._id != null && $scope.newScopes.length > 0 && $scope.newScopes[0].id)) {
- $scope.newScopes = [];
- }
- var scopes = angular.copy($scope.newScopes);
- for (i = 0; i < scopes.length; i++) {
- delete scopes[i].text;
- }
- $scope.authzRequest.resources[0].scopes = scopes;
- }
- $http.post(authUrl + '/admin/realms/'+ $route.current.params.realm + '/clients/' + client.id + '/authz/resource-server/policy/evaluate'
- , $scope.authzRequest).then(function(response) {
- $scope.evaluationResult = response.data;
- $scope.showResultTab();
- });
- }
- $scope.entitlements = function() {
- $scope.authzRequest.entitlements = true;
- $http.post(authUrl + '/admin/realms/'+ $route.current.params.realm + '/clients/' + client.id + '/authz/resource-server/policy/evaluate'
- , $scope.authzRequest).then(function(response) {
- $scope.evaluationResult = response.data;
- $scope.showResultTab();
- });
- }
- $scope.showResultTab = function() {
- $scope.showResult = true;
- $scope.showRpt = false;
- }
- $scope.showRequestTab = function() {
- $scope.showResult = false;
- $scope.showRpt = false;
- }
- $scope.usersUiSelect = {
- minimumInputLength: 1,
- delay: 500,
- allowClear: true,
- query: function (query) {
- var data = {results: []};
- if ('' == query.term.trim()) {
- query.callback(data);
- return;
- }
- User.query({realm: $route.current.params.realm, search: query.term.trim(), max: 20}, function(response) {
- data.results = response;
- query.callback(data);
- });
- },
- formatResult: function(object, container, query) {
- object.text = object.username;
- return object.username;
- }
- };
- $scope.resourcesUiSelect = {
- minimumInputLength: 1,
- delay: 500,
- allowClear: true,
- id: function(resource){ return resource._id; },
- query: function (query) {
- var data = {results: []};
- if ('' == query.term.trim()) {
- query.callback(data);
- return;
- }
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- name: query.term.trim(),
- deep: false,
- max : 20,
- first : 0
- };
- ResourceServerResource.query($scope.query, function(response) {
- data.results = response;
- query.callback(data);
- });
- },
- formatResult: function(object, container, query) {
- object.text = object.name;
- return object.name;
- }
- };
- $scope.scopesUiSelect = {
- minimumInputLength: 1,
- delay: 500,
- allowClear: true,
- query: function (query) {
- var data = {results: []};
- if ('' == query.term.trim()) {
- query.callback(data);
- return;
- }
- $scope.query = {
- realm: realm.realm,
- client : client.id,
- name: query.term.trim(),
- deep: false,
- max : 20,
- first : 0
- };
- ResourceServerScope.query($scope.query, function(response) {
- data.results = response;
- query.callback(data);
- });
- },
- formatResult: function(object, container, query) {
- object.text = object.name;
- return object.name;
- }
- };
- ResourceServer.get({
- realm : $route.current.params.realm,
- client : client.id
- }, function(data) {
- $scope.server = data;
- });
- $scope.selectUser = function(user) {
- if (!user || !user.id) {
- $scope.selectedUser = null;
- $scope.authzRequest.userId = '';
- return;
- }
- $scope.authzRequest.userId = user.id;
- }
- $scope.reset = function() {
- $scope.authzRequest = angular.copy(authzRequest);
- $scope.changed = false;
- }
- });
- getManageClientId = function(realm) {
- if (realm.realm == masterRealm) {
- return 'master-realm';
- } else {
- return 'realm-management';
- }
- }
- module.controller('RealmRolePermissionsCtrl', function($scope, $http, $route, $location, realm, role, RoleManagementPermissions, Client, Notifications, Dialog, RealmRoleRemover) {
- console.log('RealmRolePermissionsCtrl');
- $scope.role = role;
- $scope.realm = realm;
-
- $scope.remove = function() {
- RealmRoleRemover.remove($scope.role, realm, Dialog, $location, Notifications);
- };
-
- RoleManagementPermissions.get({realm: realm.realm, role: role.id}, function(data) {
- $scope.permissions = data;
- $scope.$watch('permissions.enabled', function(newVal, oldVal) {
- if (newVal != oldVal) {
- var param = {enabled: $scope.permissions.enabled};
- $scope.permissions= RoleManagementPermissions.update({realm: realm.realm, role:role.id}, param);
- }
- }, true);
- });
- Client.query({realm: realm.realm, clientId: getManageClientId(realm)}, function(data) {
- $scope.realmManagementClientId = data[0].id;
- });
- });
- module.controller('ClientRolePermissionsCtrl', function($scope, $http, $route, $location, realm, client, role, Client, RoleManagementPermissions, Client, Notifications) {
- console.log('RealmRolePermissionsCtrl');
- $scope.client = client;
- $scope.role = role;
- $scope.realm = realm;
- RoleManagementPermissions.get({realm: realm.realm, role: role.id}, function(data) {
- $scope.permissions = data;
- $scope.$watch('permissions.enabled', function(newVal, oldVal) {
- if (newVal != oldVal) {
- var param = {enabled: $scope.permissions.enabled};
- $scope.permissions = RoleManagementPermissions.update({realm: realm.realm, role:role.id}, param);
- }
- }, true);
- });
- Client.query({realm: realm.realm, clientId: getManageClientId(realm)}, function(data) {
- $scope.realmManagementClientId = data[0].id;
- });
- });
- module.controller('UsersPermissionsCtrl', function($scope, $http, $route, $location, realm, UsersManagementPermissions, Client, Notifications) {
- console.log('UsersPermissionsCtrl');
- $scope.realm = realm;
- var first = true;
- UsersManagementPermissions.get({realm: realm.realm}, function(data) {
- $scope.permissions = data;
- $scope.$watch('permissions.enabled', function(newVal, oldVal) {
- if (newVal != oldVal) {
- var param = {enabled: $scope.permissions.enabled};
- $scope.permissions = UsersManagementPermissions.update({realm: realm.realm}, param);
- }
- }, true);
- });
- Client.query({realm: realm.realm, clientId: getManageClientId(realm)}, function(data) {
- $scope.realmManagementClientId = data[0].id;
- });
- });
- module.controller('ClientPermissionsCtrl', function($scope, $http, $route, $location, realm, client, Client, ClientManagementPermissions, Notifications) {
- $scope.client = client;
- $scope.realm = realm;
- ClientManagementPermissions.get({realm: realm.realm, client: client.id}, function(data) {
- $scope.permissions = data;
- $scope.$watch('permissions.enabled', function(newVal, oldVal) {
- if (newVal != oldVal) {
- var param = {enabled: $scope.permissions.enabled};
- $scope.permissions = ClientManagementPermissions.update({realm: realm.realm, client: client.id}, param);
- }
- }, true);
- });
- Client.query({realm: realm.realm, clientId: getManageClientId(realm)}, function(data) {
- $scope.realmManagementClientId = data[0].id;
- });
- });
- module.controller('IdentityProviderPermissionCtrl', function($scope, $http, $route, $location, realm, identityProvider, Client, IdentityProviderManagementPermissions, Notifications) {
- $scope.identityProvider = identityProvider;
- $scope.realm = realm;
- IdentityProviderManagementPermissions.get({realm: realm.realm, alias: identityProvider.alias}, function(data) {
- $scope.permissions = data;
- $scope.$watch('permissions.enabled', function(newVal, oldVal) {
- if (newVal != oldVal) {
- var param = {enabled: $scope.permissions.enabled};
- $scope.permissions = IdentityProviderManagementPermissions.update({realm: realm.realm, alias: identityProvider.alias}, param);
- }
- }, true);
- });
- Client.query({realm: realm.realm, clientId: getManageClientId(realm)}, function(data) {
- $scope.realmManagementClientId = data[0].id;
- });
- });
- module.controller('GroupPermissionsCtrl', function($scope, $http, $route, $location, realm, group, GroupManagementPermissions, Client, Notifications) {
- $scope.group = group;
- $scope.realm = realm;
- Client.query({realm: realm.realm, clientId: getManageClientId(realm)}, function(data) {
- $scope.realmManagementClientId = data[0].id;
- });
- GroupManagementPermissions.get({realm: realm.realm, group: group.id}, function(data) {
- $scope.permissions = data;
- $scope.$watch('permissions.enabled', function(newVal, oldVal) {
- if (newVal != oldVal) {
- var param = {enabled: $scope.permissions.enabled};
- $scope.permissions = GroupManagementPermissions.update({realm: realm.realm, group: group.id}, param);
- }
- }, true);
- });
- });
|