services.js 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256
  1. 'use strict';
  2. var module = angular.module('keycloak.services', [ 'ngResource', 'ngRoute' ]);
  3. module.service('Dialog', function($modal, $translate) {
  4. var dialog = {};
  5. var openDialog = function(title, message, btns, template) {
  6. var controller = function($scope, $modalInstance, title, message, btns) {
  7. $scope.title = title;
  8. $scope.message = message;
  9. $scope.btns = btns;
  10. $scope.ok = function () {
  11. $modalInstance.close();
  12. };
  13. $scope.cancel = function () {
  14. $modalInstance.dismiss('cancel');
  15. };
  16. };
  17. return $modal.open({
  18. templateUrl: resourceUrl + template,
  19. controller: controller,
  20. resolve: {
  21. title: function() {
  22. return title;
  23. },
  24. message: function() {
  25. return message;
  26. },
  27. btns: function() {
  28. return btns;
  29. }
  30. }
  31. }).result;
  32. }
  33. var escapeHtml = function(str) {
  34. var div = document.createElement('div');
  35. div.appendChild(document.createTextNode(str));
  36. return div.innerHTML;
  37. };
  38. dialog.confirmDelete = function(name, type, success) {
  39. var title = $translate.instant('dialogs.delete.title', {type: escapeHtml(type.charAt(0).toUpperCase() + type.slice(1))});
  40. var msg = $translate.instant('dialogs.delete.message', {type: type, name: name});
  41. var confirm = $translate.instant('dialogs.delete.confirm');
  42. dialog.confirmWithButtonText(title, msg, confirm, success);
  43. }
  44. dialog.confirmGenerateKeys = function(name, type, success) {
  45. var title = 'Generate new keys for realm';
  46. var msg = 'Are you sure you want to permanently generate new keys for ' + name + '?';
  47. var btns = {
  48. ok: {
  49. label: 'Generate Keys',
  50. cssClass: 'btn btn-danger'
  51. },
  52. cancel: {
  53. label: 'Cancel',
  54. cssClass: 'btn btn-default'
  55. }
  56. }
  57. openDialog(title, msg, btns, '/templates/kc-modal.html').then(success);
  58. }
  59. dialog.confirm = function(title, message, success, cancel) {
  60. dialog.confirmWithButtonText(title, message, title, success, cancel);
  61. }
  62. dialog.confirmWithButtonText = function(title, message, confirm, success, cancel) {
  63. var btns = {
  64. ok: {
  65. label: confirm,
  66. cssClass: 'btn btn-danger'
  67. },
  68. cancel: {
  69. label: $translate.instant('dialogs.cancel'),
  70. cssClass: 'btn btn-default'
  71. }
  72. }
  73. openDialog(title, message, btns, '/templates/kc-modal.html').then(success, cancel);
  74. }
  75. dialog.message = function(title, message, success, cancel) {
  76. var btns = {
  77. ok: {
  78. label: $translate.instant('dialogs.ok'),
  79. cssClass: 'btn btn-default'
  80. }
  81. }
  82. openDialog(title, message, btns, '/templates/kc-modal-message.html').then(success, cancel);
  83. }
  84. dialog.open = function(title, message, btns, success, cancel) {
  85. openDialog(title, message, btns, '/templates/kc-modal.html').then(success, cancel);
  86. }
  87. return dialog
  88. });
  89. module.service('CopyDialog', function($modal) {
  90. var dialog = {};
  91. dialog.open = function (title, suggested, success) {
  92. var controller = function($scope, $modalInstance, title) {
  93. $scope.title = title;
  94. $scope.name = { value: 'Copy of ' + suggested };
  95. $scope.ok = function () {
  96. console.log('ok with name: ' + $scope.name);
  97. $modalInstance.close();
  98. success($scope.name.value);
  99. };
  100. $scope.cancel = function () {
  101. $modalInstance.dismiss('cancel');
  102. };
  103. }
  104. $modal.open({
  105. templateUrl: resourceUrl + '/templates/kc-copy.html',
  106. controller: controller,
  107. resolve: {
  108. title: function() {
  109. return title;
  110. }
  111. }
  112. });
  113. };
  114. return dialog;
  115. });
  116. module.service('UpdateDialog', function($modal) {
  117. var dialog = {};
  118. dialog.open = function (title, name, desc, success) {
  119. var controller = function($scope, $modalInstance, title) {
  120. $scope.title = title;
  121. $scope.name = { value: name };
  122. $scope.description = { value: desc };
  123. $scope.ok = function () {
  124. console.log('ok with name: ' + $scope.name + 'and description: ' + $scope.description);
  125. $modalInstance.close();
  126. success($scope.name.value, $scope.description.value);
  127. };
  128. $scope.cancel = function () {
  129. $modalInstance.dismiss('cancel');
  130. };
  131. }
  132. $modal.open({
  133. templateUrl: resourceUrl + '/templates/kc-edit.html',
  134. controller: controller,
  135. resolve: {
  136. title: function() {
  137. return title;
  138. }
  139. }
  140. });
  141. };
  142. return dialog;
  143. });
  144. module.factory('Notifications', function($rootScope, $timeout, $translate) {
  145. // time (in ms) the notifications are shown
  146. var delay = 5000;
  147. var notifications = {};
  148. notifications.current = { display: false };
  149. notifications.current.remove = function() {
  150. if (notifications.scheduled) {
  151. $timeout.cancel(notifications.scheduled);
  152. delete notifications.scheduled;
  153. }
  154. delete notifications.current.type;
  155. delete notifications.current.header;
  156. delete notifications.current.message;
  157. notifications.current.display = false;
  158. console.debug("Remove message");
  159. }
  160. $rootScope.notification = notifications.current;
  161. notifications.message = function(type, header, message) {
  162. notifications.current.remove();
  163. notifications.current.type = type;
  164. notifications.current.header = header;
  165. notifications.current.message = message;
  166. notifications.current.display = true;
  167. notifications.scheduled = $timeout(function() {
  168. notifications.current.remove();
  169. }, delay);
  170. console.debug("Added message");
  171. }
  172. notifications.info = function(message) {
  173. notifications.message("info", $translate.instant('notifications.info.header'), message);
  174. };
  175. notifications.success = function(message) {
  176. notifications.message("success", $translate.instant('notifications.success.header'), message);
  177. };
  178. notifications.error = function(message) {
  179. notifications.message("danger", $translate.instant('notifications.error.header'), message);
  180. };
  181. notifications.warn = function(message) {
  182. notifications.message("warning", $translate.instant('notifications.warn.header'), message);
  183. };
  184. return notifications;
  185. });
  186. module.factory('ComponentUtils', function() {
  187. function sortGroups(prop, arr) {
  188. // sort current elements
  189. arr.sort(function (a, b) {
  190. if (a[prop] < b[prop]) { return -1; }
  191. if (a[prop] > b[prop]) { return 1; }
  192. return 0;
  193. });
  194. // check sub groups
  195. arr.forEach(function (item, index) {
  196. if (!!item.subGroups) {
  197. sortGroups(prop, item.subGroups);
  198. }
  199. });
  200. return arr;
  201. };
  202. var utils = {};
  203. utils.sortGroups = sortGroups;
  204. utils.findIndexById = function(array, id) {
  205. for (var i = 0; i < array.length; i++) {
  206. if (array[i].id === id) return i;
  207. }
  208. return -1;
  209. }
  210. utils.convertAllMultivaluedStringValuesToList = function(properties, config) {
  211. if (!properties) {
  212. return;
  213. }
  214. for (var i=0 ; i<properties.length ; i++) {
  215. var prop = properties[i];
  216. if (prop.type === 'MultivaluedString') {
  217. var configProperty = config[prop.name];
  218. if (configProperty == null) {
  219. configProperty = [];
  220. config[prop.name] = configProperty;
  221. }
  222. if (typeof configProperty === "string") {
  223. configProperty = configProperty.split("##");
  224. config[prop.name] = configProperty;
  225. }
  226. }
  227. }
  228. }
  229. utils.convertAllListValuesToMultivaluedString = function(properties, config) {
  230. if (!properties) {
  231. return;
  232. }
  233. for (var i=0 ; i<properties.length ; i++) {
  234. var prop = properties[i];
  235. if (prop.type === 'MultivaluedString') {
  236. var configVal = config[prop.name];
  237. if (configVal != null) {
  238. if (configVal.length > 0) {
  239. var lastVal = configVal[configVal.length - 1];
  240. if (lastVal === '') {
  241. console.log('Remove empty value from config property: ' + prop.name);
  242. configVal.splice(configVal.length - 1, 1);
  243. }
  244. }
  245. var attrVals = configVal.join("##");
  246. config[prop.name] = attrVals;
  247. }
  248. }
  249. }
  250. }
  251. utils.addLastEmptyValueToMultivaluedLists = function(properties, config) {
  252. if (!properties) {
  253. return;
  254. }
  255. for (var i=0 ; i<properties.length ; i++) {
  256. var prop = properties[i];
  257. if (prop.type === 'MultivaluedString') {
  258. var configProperty = config[prop.name];
  259. if (configProperty == null) {
  260. configProperty = [];
  261. config[prop.name] = configProperty;
  262. }
  263. if (configProperty.length == 0 || configProperty[configProperty.length - 1].length > 0) {
  264. configProperty.push('');
  265. }
  266. }
  267. }
  268. }
  269. utils.removeLastEmptyValue = function(componentConfig) {
  270. for (var configPropertyName in componentConfig) {
  271. var configVal = componentConfig[configPropertyName];
  272. if (configVal && configVal.length > 0) {
  273. var lastVal = configVal[configVal.length - 1];
  274. if (lastVal === '') {
  275. console.log('Remove empty value from config property: ' + configPropertyName);
  276. configVal.splice(configVal.length - 1, 1);
  277. }
  278. }
  279. }
  280. }
  281. // Allows you to use ui-select2 with <input> tag.
  282. // In HTML you will then use property.mvOptions like this:
  283. // <input ui-select2="prop.mvOptions" ng-model="...
  284. utils.addMvOptionsToMultivaluedLists = function(properties) {
  285. if (!properties) return;
  286. for (var i=0 ; i<properties.length ; i++) {
  287. var prop = properties[i];
  288. if (prop.type !== 'MultivaluedList') continue;
  289. prop.mvOptions = {
  290. 'multiple' : true,
  291. 'simple_tags' : true,
  292. 'tags' : angular.copy(prop.options)
  293. }
  294. }
  295. }
  296. return utils;
  297. });
  298. module.factory('Realm', function($resource) {
  299. return $resource(authUrl + '/admin/realms/:id', {
  300. id : '@realm'
  301. }, {
  302. update : {
  303. method : 'PUT'
  304. },
  305. create : {
  306. method : 'POST',
  307. params : { id : ''}
  308. }
  309. });
  310. });
  311. module.factory('RealmKeys', function($resource) {
  312. return $resource(authUrl + '/admin/realms/:id/keys', {
  313. id : '@realm'
  314. });
  315. });
  316. module.factory('RealmSpecificLocales', function($resource) {
  317. return $resource(authUrl + '/admin/realms/:id/localization', {
  318. id : '@realm'
  319. },{'get': {method:'GET', isArray:true}});
  320. });
  321. module.factory('RealmSpecificLocalizationTexts', function($resource) {
  322. return $resource(authUrl + '/admin/realms/:id/localization/:locale', {
  323. id : '@realm',
  324. locale : '@locale'
  325. });
  326. });
  327. module.factory('RealmSpecificLocalizationText', function ($resource) {
  328. return $resource(authUrl + '/admin/realms/:realm/localization/:locale/:key', {
  329. realm: '@realm',
  330. locale: '@locale',
  331. key: '@key'
  332. }, {
  333. // wrap plain text response as AngularJS $resource will convert it into a char array otherwise.
  334. get: {
  335. method: 'GET',
  336. transformResponse: function (data) {
  337. return {content: data};
  338. }
  339. },
  340. save: {
  341. method: 'PUT',
  342. headers: {
  343. 'Content-Type': 'text/plain;charset=utf-8'
  344. }
  345. }
  346. });
  347. });
  348. module.factory('RealmEventsConfig', function($resource) {
  349. return $resource(authUrl + '/admin/realms/:id/events/config', {
  350. id : '@realm'
  351. }, {
  352. update : {
  353. method : 'PUT'
  354. }
  355. });
  356. });
  357. module.factory('RealmEvents', function($resource) {
  358. return $resource(authUrl + '/admin/realms/:id/events', {
  359. id : '@realm'
  360. });
  361. });
  362. module.factory('RealmAdminEvents', function($resource) {
  363. return $resource(authUrl + '/admin/realms/:id/admin-events', {
  364. id : '@realm'
  365. });
  366. });
  367. module.factory('BruteForce', function($resource) {
  368. return $resource(authUrl + '/admin/realms/:realm/attack-detection/brute-force/users', {
  369. realm : '@realm'
  370. });
  371. });
  372. module.factory('BruteForceUser', function($resource) {
  373. return $resource(authUrl + '/admin/realms/:realm/attack-detection/brute-force/users/:userId', {
  374. realm : '@realm',
  375. userId : '@userId'
  376. });
  377. });
  378. module.factory('RequiredActions', function($resource) {
  379. return $resource(authUrl + '/admin/realms/:realm/authentication/required-actions/:alias', {
  380. realm : '@realm',
  381. alias : '@alias'
  382. }, {
  383. update : {
  384. method : 'PUT'
  385. }
  386. });
  387. });
  388. module.factory('RequiredActionRaisePriority', function($resource) {
  389. return $resource(authUrl + '/admin/realms/:realm/authentication/required-actions/:alias/raise-priority', {
  390. realm : '@realm',
  391. alias : '@alias'
  392. });
  393. });
  394. module.factory('RequiredActionLowerPriority', function($resource) {
  395. return $resource(authUrl + '/admin/realms/:realm/authentication/required-actions/:alias/lower-priority', {
  396. realm : '@realm',
  397. alias : '@alias'
  398. });
  399. });
  400. module.factory('UnregisteredRequiredActions', function($resource) {
  401. return $resource(authUrl + '/admin/realms/:realm/authentication/unregistered-required-actions', {
  402. realm : '@realm'
  403. });
  404. });
  405. module.factory('RegisterRequiredAction', function($resource) {
  406. return $resource(authUrl + '/admin/realms/:realm/authentication/register-required-action', {
  407. realm : '@realm'
  408. });
  409. });
  410. module.factory('RealmLDAPConnectionTester', function($resource, $httpParamSerializer) {
  411. return $resource(authUrl + '/admin/realms/:realm/testLDAPConnection', {
  412. realm : '@realm'
  413. });
  414. });
  415. module.factory('RealmSMTPConnectionTester', function($resource, $httpParamSerializer) {
  416. return $resource(authUrl + '/admin/realms/:realm/testSMTPConnection', {
  417. realm : '@realm'
  418. });
  419. });
  420. module.service('ServerInfo', function($resource, $q, $http) {
  421. var info = {};
  422. var delay = $q.defer();
  423. function copyInfo(data, info) {
  424. angular.copy(data, info);
  425. info.listProviderIds = function(spi) {
  426. var providers = info.providers[spi].providers;
  427. var ids = Object.keys(providers);
  428. ids.sort(function(a, b) {
  429. var s1;
  430. var s2;
  431. if (providers[a].order != providers[b].order) {
  432. s1 = providers[b].order;
  433. s2 = providers[a].order;
  434. } else {
  435. s1 = a;
  436. s2 = b;
  437. }
  438. if (s1 < s2) {
  439. return -1;
  440. } else if (s1 > s2) {
  441. return 1;
  442. } else {
  443. return 0;
  444. }
  445. });
  446. return ids;
  447. }
  448. info.featureEnabled = function(provider) {
  449. return info.profileInfo.disabledFeatures.indexOf(provider) == -1;
  450. }
  451. }
  452. $http.get(authUrl + '/admin/serverinfo').then(function(response) {
  453. copyInfo(response.data, info);
  454. delay.resolve(info);
  455. });
  456. return {
  457. get: function() {
  458. return info;
  459. },
  460. reload: function() {
  461. $http.get(authUrl + '/admin/serverinfo').then(function(response) {
  462. copyInfo(response.data, info);
  463. });
  464. },
  465. promise: delay.promise
  466. }
  467. });
  468. module.factory('ClientInitialAccess', function($resource) {
  469. return $resource(authUrl + '/admin/realms/:realm/clients-initial-access/:id', {
  470. realm : '@realm',
  471. id : '@id'
  472. });
  473. });
  474. module.factory('ClientProtocolMapper', function($resource) {
  475. return $resource(authUrl + '/admin/realms/:realm/clients/:client/protocol-mappers/models/:id', {
  476. realm : '@realm',
  477. client: '@client',
  478. id : "@id"
  479. }, {
  480. update : {
  481. method : 'PUT'
  482. }
  483. });
  484. });
  485. module.factory('ClientScopeProtocolMapper', function($resource) {
  486. return $resource(authUrl + '/admin/realms/:realm/client-scopes/:clientScope/protocol-mappers/models/:id', {
  487. realm : '@realm',
  488. clientScope: '@clientScope',
  489. id : "@id"
  490. }, {
  491. update : {
  492. method : 'PUT'
  493. }
  494. });
  495. });
  496. module.factory('User', function($resource) {
  497. return $resource(authUrl + '/admin/realms/:realm/users/:userId', {
  498. realm : '@realm',
  499. userId : '@userId'
  500. }, {
  501. update : {
  502. method : 'PUT'
  503. }
  504. });
  505. });
  506. module.service('UserSearchState', function() {
  507. this.isFirstSearch = true;
  508. this.query = {
  509. max : 20,
  510. first : 0
  511. };
  512. });
  513. module.service('ClientListSearchState', function() {
  514. this.isFirstSearch = true;
  515. this.query = {
  516. max : 20,
  517. first : 0,
  518. search: true
  519. };
  520. });
  521. // Service tracks the last flow selected in Authentication-->Flows tab
  522. module.service('LastFlowSelected', function() {
  523. this.alias = null;
  524. });
  525. module.service('RealmRoleRemover', function() {
  526. this.remove = function (role, realm, Dialog, $location, Notifications) {
  527. Dialog.confirmDelete(role.name, 'role', function () {
  528. role.$remove({
  529. realm: realm.realm,
  530. role: role.id
  531. }, function () {
  532. $location.url("/realms/" + realm.realm + "/roles");
  533. Notifications.success("The role has been deleted.");
  534. });
  535. });
  536. };
  537. });
  538. module.factory('UserSessionStats', function($resource) {
  539. return $resource(authUrl + '/admin/realms/:realm/users/:user/session-stats', {
  540. realm : '@realm',
  541. user : '@user'
  542. });
  543. });
  544. module.factory('UserSessions', function($resource) {
  545. return $resource(authUrl + '/admin/realms/:realm/users/:user/sessions', {
  546. realm : '@realm',
  547. user : '@user'
  548. });
  549. });
  550. module.factory('UserOfflineSessions', function($resource) {
  551. return $resource(authUrl + '/admin/realms/:realm/users/:user/offline-sessions/:client', {
  552. realm : '@realm',
  553. user : '@user',
  554. client : '@client'
  555. });
  556. });
  557. module.factory('UserSessionLogout', function($resource) {
  558. return $resource(authUrl + '/admin/realms/:realm/sessions/:session', {
  559. realm : '@realm',
  560. session : '@session'
  561. });
  562. });
  563. module.factory('UserLogout', function($resource) {
  564. return $resource(authUrl + '/admin/realms/:realm/users/:user/logout', {
  565. realm : '@realm',
  566. user : '@user'
  567. });
  568. });
  569. module.factory('UserFederatedIdentities', function($resource) {
  570. return $resource(authUrl + '/admin/realms/:realm/users/:user/federated-identity', {
  571. realm : '@realm',
  572. user : '@user'
  573. });
  574. });
  575. module.factory('UserFederatedIdentity', function($resource) {
  576. return $resource(authUrl + '/admin/realms/:realm/users/:user/federated-identity/:provider', {
  577. realm : '@realm',
  578. user : '@user',
  579. provider : '@provider'
  580. });
  581. });
  582. module.factory('UserConsents', function($resource) {
  583. return $resource(authUrl + '/admin/realms/:realm/users/:user/consents/:client', {
  584. realm : '@realm',
  585. user : '@user',
  586. client: '@client'
  587. });
  588. });
  589. module.factory('UserImpersonation', function($resource) {
  590. return $resource(authUrl + '/admin/realms/:realm/users/:user/impersonation', {
  591. realm : '@realm',
  592. user : '@user'
  593. });
  594. });
  595. module.factory('UserCredentials', function($resource) {
  596. var credentials = {};
  597. credentials.getCredentials = $resource(authUrl + '/admin/realms/:realm/users/:userId/credentials', {
  598. realm : '@realm',
  599. userId : '@userId'
  600. }).query;
  601. credentials.getConfiguredUserStorageCredentialTypes = $resource(authUrl + '/admin/realms/:realm/users/:userId/configured-user-storage-credential-types', {
  602. realm : '@realm',
  603. userId : '@userId'
  604. }).query;
  605. credentials.deleteCredential = $resource(authUrl + '/admin/realms/:realm/users/:userId/credentials/:credentialId', {
  606. realm : '@realm',
  607. userId : '@userId',
  608. credentialId : '@credentialId'
  609. }).delete;
  610. credentials.updateCredentialLabel = $resource(authUrl + '/admin/realms/:realm/users/:userId/credentials/:credentialId/userLabel', {
  611. realm : '@realm',
  612. userId : '@userId',
  613. credentialId : '@credentialId'
  614. }, {
  615. update : {
  616. method : 'PUT',
  617. headers: {
  618. 'Content-Type': 'text/plain;charset=utf-8'
  619. },
  620. transformRequest: function(credential, getHeaders) {
  621. return credential.userLabel;
  622. }
  623. }
  624. }).update;
  625. credentials.resetPassword = $resource(authUrl + '/admin/realms/:realm/users/:userId/reset-password', {
  626. realm : '@realm',
  627. userId : '@userId'
  628. }, {
  629. update : {
  630. method : 'PUT'
  631. }
  632. }).update;
  633. credentials.removeTotp = $resource(authUrl + '/admin/realms/:realm/users/:userId/remove-totp', {
  634. realm : '@realm',
  635. userId : '@userId'
  636. }, {
  637. update : {
  638. method : 'PUT'
  639. }
  640. }).update;
  641. credentials.disableCredentialTypes = $resource(authUrl + '/admin/realms/:realm/users/:userId/disable-credential-types', {
  642. realm : '@realm',
  643. userId : '@userId'
  644. }, {
  645. update : {
  646. method : 'PUT'
  647. }
  648. }).update;
  649. credentials.moveCredentialAfter = $resource(authUrl + '/admin/realms/:realm/users/:userId/credentials/:credentialId/moveAfter/:newPreviousCredentialId', {
  650. realm : '@realm',
  651. userId : '@userId',
  652. credentialId : '@credentialId',
  653. newPreviousCredentialId : '@newPreviousCredentialId'
  654. }, {
  655. update : {
  656. method : 'POST'
  657. }
  658. }).update;
  659. credentials.moveToFirst = $resource(authUrl + '/admin/realms/:realm/users/:userId/credentials/:credentialId/moveToFirst', {
  660. realm : '@realm',
  661. userId : '@userId',
  662. credentialId : '@credentialId'
  663. }, {
  664. update : {
  665. method : 'POST'
  666. }
  667. }).update;
  668. return credentials;
  669. });
  670. module.factory('UserExecuteActionsEmail', function($resource) {
  671. return $resource(authUrl + '/admin/realms/:realm/users/:userId/execute-actions-email', {
  672. realm : '@realm',
  673. userId : '@userId',
  674. lifespan : '@lifespan',
  675. }, {
  676. update : {
  677. method : 'PUT'
  678. }
  679. });
  680. });
  681. module.factory('RealmRoleMapping', function($resource) {
  682. return $resource(authUrl + '/admin/realms/:realm/users/:userId/role-mappings/realm', {
  683. realm : '@realm',
  684. userId : '@userId'
  685. });
  686. });
  687. module.factory('CompositeRealmRoleMapping', function($resource) {
  688. return $resource(authUrl + '/admin/realms/:realm/users/:userId/role-mappings/realm/composite', {
  689. realm : '@realm',
  690. userId : '@userId'
  691. });
  692. });
  693. module.factory('AvailableRealmRoleMapping', function($resource) {
  694. return $resource(authUrl + '/admin/realms/:realm/users/:userId/role-mappings/realm/available', {
  695. realm : '@realm',
  696. userId : '@userId'
  697. });
  698. });
  699. module.factory('ClientRoleMapping', function($resource) {
  700. return $resource(authUrl + '/admin/realms/:realm/users/:userId/role-mappings/clients/:client', {
  701. realm : '@realm',
  702. userId : '@userId',
  703. client : "@client"
  704. });
  705. });
  706. module.factory('AvailableClientRoleMapping', function($resource) {
  707. return $resource(authUrl + '/admin/realms/:realm/users/:userId/role-mappings/clients/:client/available', {
  708. realm : '@realm',
  709. userId : '@userId',
  710. client : "@client"
  711. });
  712. });
  713. module.factory('CompositeClientRoleMapping', function($resource) {
  714. return $resource(authUrl + '/admin/realms/:realm/users/:userId/role-mappings/clients/:client/composite', {
  715. realm : '@realm',
  716. userId : '@userId',
  717. client : "@client"
  718. });
  719. });
  720. module.factory('ClientRealmScopeMapping', function($resource) {
  721. return $resource(authUrl + '/admin/realms/:realm/clients/:client/scope-mappings/realm', {
  722. realm : '@realm',
  723. client : '@client'
  724. });
  725. });
  726. module.factory('ClientAvailableRealmScopeMapping', function($resource) {
  727. return $resource(authUrl + '/admin/realms/:realm/clients/:client/scope-mappings/realm/available', {
  728. realm : '@realm',
  729. client : '@client'
  730. });
  731. });
  732. module.factory('ClientCompositeRealmScopeMapping', function($resource) {
  733. return $resource(authUrl + '/admin/realms/:realm/clients/:client/scope-mappings/realm/composite', {
  734. realm : '@realm',
  735. client : '@client'
  736. });
  737. });
  738. module.factory('ClientClientScopeMapping', function($resource) {
  739. return $resource(authUrl + '/admin/realms/:realm/clients/:client/scope-mappings/clients/:targetClient', {
  740. realm : '@realm',
  741. client : '@client',
  742. targetClient : '@targetClient'
  743. });
  744. });
  745. module.factory('ClientAvailableClientScopeMapping', function($resource) {
  746. return $resource(authUrl + '/admin/realms/:realm/clients/:client/scope-mappings/clients/:targetClient/available', {
  747. realm : '@realm',
  748. client : '@client',
  749. targetClient : '@targetClient'
  750. });
  751. });
  752. module.factory('ClientCompositeClientScopeMapping', function($resource) {
  753. return $resource(authUrl + '/admin/realms/:realm/clients/:client/scope-mappings/clients/:targetClient/composite', {
  754. realm : '@realm',
  755. client : '@client',
  756. targetClient : '@targetClient'
  757. });
  758. });
  759. module.factory('RealmRoles', function($resource) {
  760. return $resource(authUrl + '/admin/realms/:realm/roles', {
  761. realm : '@realm'
  762. });
  763. });
  764. module.factory('RoleRealmComposites', function($resource) {
  765. return $resource(authUrl + '/admin/realms/:realm/roles-by-id/:role/composites/realm', {
  766. realm : '@realm',
  767. role : '@role'
  768. });
  769. });
  770. module.factory('RealmPushRevocation', function($resource) {
  771. return $resource(authUrl + '/admin/realms/:realm/push-revocation', {
  772. realm : '@realm'
  773. });
  774. });
  775. module.factory('RealmClearUserCache', function($resource) {
  776. return $resource(authUrl + '/admin/realms/:realm/clear-user-cache', {
  777. realm : '@realm'
  778. });
  779. });
  780. module.factory('RealmClearRealmCache', function($resource) {
  781. return $resource(authUrl + '/admin/realms/:realm/clear-realm-cache', {
  782. realm : '@realm'
  783. });
  784. });
  785. module.factory('RealmClearKeysCache', function($resource) {
  786. return $resource(authUrl + '/admin/realms/:realm/clear-keys-cache', {
  787. realm : '@realm'
  788. });
  789. });
  790. module.factory('RealmSessionStats', function($resource) {
  791. return $resource(authUrl + '/admin/realms/:realm/session-stats', {
  792. realm : '@realm'
  793. });
  794. });
  795. module.factory('RealmClientSessionStats', function($resource) {
  796. return $resource(authUrl + '/admin/realms/:realm/client-session-stats', {
  797. realm : '@realm'
  798. });
  799. });
  800. module.factory('RoleClientComposites', function($resource) {
  801. return $resource(authUrl + '/admin/realms/:realm/roles-by-id/:role/composites/clients/:client', {
  802. realm : '@realm',
  803. role : '@role',
  804. client : "@client"
  805. });
  806. });
  807. function clientSelectControl($scope, realm, Client) {
  808. $scope.clientsUiSelect = {
  809. minimumInputLength: 0,
  810. delay: 500,
  811. allowClear: true,
  812. query: function (query) {
  813. var data = {results: []};
  814. Client.query({realm: realm, search: true, clientId: query.term.trim(), max: 20}, function(response) {
  815. data.results = response;
  816. query.callback(data);
  817. });
  818. },
  819. formatResult: function(object, container, query) {
  820. object.text = object.clientId;
  821. return object.clientId;
  822. }
  823. };
  824. }
  825. function roleControl($scope, $route, realm, role, roles, Client,
  826. ClientRole, RoleById, RoleRealmComposites, RoleClientComposites,
  827. $http, $location, Notifications, Dialog, ComponentUtils) {
  828. $scope.$watch(function () {
  829. return $location.path();
  830. }, function () {
  831. $scope.path = $location.path().substring(1).split("/");
  832. });
  833. $scope.$watch('role', function () {
  834. if (!angular.equals($scope.role, role)) {
  835. $scope.changed = true;
  836. }
  837. }, true);
  838. $scope.update = function () {
  839. RoleById.update({
  840. realm: realm.realm,
  841. role: role.id
  842. }, $scope.role, function () {
  843. $scope.changed = false;
  844. role = angular.copy($scope.role);
  845. Notifications.success("Your changes have been saved to the role.");
  846. });
  847. };
  848. $scope.reset = function () {
  849. $scope.role = angular.copy(role);
  850. $scope.changed = false;
  851. };
  852. if (!role.id) return;
  853. $scope.compositeSwitch = role.composite;
  854. $scope.compositeSwitchDisabled = role.composite;
  855. $scope.realmRoles = angular.copy(roles);
  856. $scope.selectedRealmRoles = [];
  857. $scope.selectedRealmMappings = [];
  858. $scope.realmMappings = [];
  859. $scope.clientRoles = [];
  860. $scope.selectedClientRoles = [];
  861. $scope.selectedClientMappings = [];
  862. $scope.clientMappings = [];
  863. for (var j = 0; j < $scope.realmRoles.length; j++) {
  864. if ($scope.realmRoles[j].id == role.id) {
  865. var realmRole = $scope.realmRoles[j];
  866. var idx = $scope.realmRoles.indexOf(realmRole);
  867. $scope.realmRoles.splice(idx, 1);
  868. break;
  869. }
  870. }
  871. clientSelectControl($scope, $route.current.params.realm, Client);
  872. $scope.selectedClient = null;
  873. $scope.realmMappings = RoleRealmComposites.query({realm : realm.realm, role : role.id}, function(){
  874. for (var i = 0; i < $scope.realmMappings.length; i++) {
  875. var role = $scope.realmMappings[i];
  876. for (var j = 0; j < $scope.realmRoles.length; j++) {
  877. var realmRole = $scope.realmRoles[j];
  878. if (realmRole.id == role.id) {
  879. var idx = $scope.realmRoles.indexOf(realmRole);
  880. if (idx != -1) {
  881. $scope.realmRoles.splice(idx, 1);
  882. break;
  883. }
  884. }
  885. }
  886. }
  887. });
  888. $scope.addRealmRole = function() {
  889. $scope.compositeSwitchDisabled=true;
  890. $scope.selectedRealmRolesToAdd = JSON.parse('[' + $scope.selectedRealmRoles + ']');
  891. $http.post(authUrl + '/admin/realms/' + realm.realm + '/roles-by-id/' + role.id + '/composites',
  892. $scope.selectedRealmRolesToAdd).then(function() {
  893. for (var i = 0; i < $scope.selectedRealmRolesToAdd.length; i++) {
  894. var role = $scope.selectedRealmRolesToAdd[i];
  895. var idx = ComponentUtils.findIndexById($scope.realmRoles, role.id);
  896. if (idx != -1) {
  897. $scope.realmRoles.splice(idx, 1);
  898. $scope.realmMappings.push(role);
  899. }
  900. }
  901. $scope.selectedRealmRoles = [];
  902. $scope.selectedRealmRolesToAdd = [];
  903. Notifications.success("Role added to composite.");
  904. });
  905. };
  906. $scope.deleteRealmRole = function() {
  907. $scope.compositeSwitchDisabled=true;
  908. $scope.selectedRealmMappingsToRemove = JSON.parse('[' + $scope.selectedRealmMappings + ']');
  909. $http.delete(authUrl + '/admin/realms/' + realm.realm + '/roles-by-id/' + role.id + '/composites',
  910. {data : $scope.selectedRealmMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function() {
  911. for (var i = 0; i < $scope.selectedRealmMappingsToRemove.length; i++) {
  912. var role = $scope.selectedRealmMappingsToRemove[i];
  913. var idx = ComponentUtils.findIndexById($scope.realmMappings, role.id);
  914. if (idx != -1) {
  915. $scope.realmMappings.splice(idx, 1);
  916. $scope.realmRoles.push(role);
  917. }
  918. }
  919. $scope.selectedRealmMappings = [];
  920. $scope.selectedRealmMappingsToRemove = [];
  921. Notifications.success("Role removed from composite.");
  922. });
  923. };
  924. $scope.addClientRole = function() {
  925. $scope.compositeSwitchDisabled=true;
  926. $scope.selectedClientRolesToAdd = JSON.parse('[' + $scope.selectedClientRoles + ']');
  927. $http.post(authUrl + '/admin/realms/' + realm.realm + '/roles-by-id/' + role.id + '/composites',
  928. $scope.selectedClientRolesToAdd).then(function() {
  929. for (var i = 0; i < $scope.selectedClientRolesToAdd.length; i++) {
  930. var role = $scope.selectedClientRolesToAdd[i];
  931. var idx = ComponentUtils.findIndexById($scope.clientRoles, role.id);
  932. if (idx != -1) {
  933. $scope.clientRoles.splice(idx, 1);
  934. $scope.clientMappings.push(role);
  935. }
  936. }
  937. $scope.selectedClientRoles = [];
  938. $scope.selectedClientRolesToAdd = [];
  939. Notifications.success("Client role added.");
  940. });
  941. };
  942. $scope.deleteClientRole = function() {
  943. $scope.compositeSwitchDisabled=true;
  944. $scope.selectedClientMappingsToRemove = JSON.parse('[' + $scope.selectedClientMappings + ']');
  945. $http.delete(authUrl + '/admin/realms/' + realm.realm + '/roles-by-id/' + role.id + '/composites',
  946. {data : $scope.selectedClientMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function() {
  947. for (var i = 0; i < $scope.selectedClientMappingsToRemove.length; i++) {
  948. var role = $scope.selectedClientMappingsToRemove[i];
  949. var idx = ComponentUtils.findIndexById($scope.clientMappings, role.id);
  950. if (idx != -1) {
  951. $scope.clientMappings.splice(idx, 1);
  952. $scope.clientRoles.push(role);
  953. }
  954. }
  955. $scope.selectedClientMappings = [];
  956. $scope.selectedClientMappingsToRemove = [];
  957. Notifications.success("Client role removed.");
  958. });
  959. };
  960. $scope.changeClient = function(client) {
  961. console.log("selected client: ", client);
  962. if (!client || !client.id) {
  963. $scope.selectedClient = null;
  964. return;
  965. }
  966. $scope.selectedClient = client;
  967. $scope.clientRoles = ClientRole.query({realm : realm.realm, client : client.id}, function() {
  968. $scope.clientMappings = RoleClientComposites.query({realm : realm.realm, role : role.id, client : client.id}, function(){
  969. for (var i = 0; i < $scope.clientMappings.length; i++) {
  970. var role = $scope.clientMappings[i];
  971. for (var j = 0; j < $scope.clientRoles.length; j++) {
  972. var realmRole = $scope.clientRoles[j];
  973. if (realmRole.id == role.id) {
  974. var idx = $scope.clientRoles.indexOf(realmRole);
  975. if (idx != -1) {
  976. $scope.clientRoles.splice(idx, 1);
  977. break;
  978. }
  979. }
  980. }
  981. }
  982. });
  983. for (var j = 0; j < $scope.clientRoles.length; j++) {
  984. if ($scope.clientRoles[j] == role.id) {
  985. var appRole = $scope.clientRoles[j];
  986. var idx = $scope.clientRoles.indexof(appRole);
  987. $scope.clientRoles.splice(idx, 1);
  988. break;
  989. }
  990. }
  991. }
  992. );
  993. };
  994. }
  995. module.factory('Role', function($resource) {
  996. return $resource(authUrl + '/admin/realms/:realm/roles/:role', {
  997. realm : '@realm',
  998. role : '@role'
  999. }, {
  1000. update : {
  1001. method : 'PUT'
  1002. }
  1003. });
  1004. });
  1005. module.factory('RoleById', function($resource) {
  1006. return $resource(authUrl + '/admin/realms/:realm/roles-by-id/:role', {
  1007. realm : '@realm',
  1008. role : '@role'
  1009. }, {
  1010. update : {
  1011. method : 'PUT'
  1012. }
  1013. });
  1014. });
  1015. module.factory('ClientRole', function($resource) {
  1016. return $resource(authUrl + '/admin/realms/:realm/clients/:client/roles/:role', {
  1017. realm : '@realm',
  1018. client : "@client",
  1019. role : '@role'
  1020. }, {
  1021. update : {
  1022. method : 'PUT'
  1023. }
  1024. });
  1025. });
  1026. module.factory('ClientDefaultClientScopes', function($resource) {
  1027. return $resource(authUrl + '/admin/realms/:realm/clients/:client/default-client-scopes/:clientScopeId', {
  1028. realm : '@realm',
  1029. client : "@client",
  1030. clientScopeId : '@clientScopeId'
  1031. }, {
  1032. update : {
  1033. method : 'PUT'
  1034. }
  1035. });
  1036. });
  1037. module.factory('ClientOptionalClientScopes', function($resource) {
  1038. return $resource(authUrl + '/admin/realms/:realm/clients/:client/optional-client-scopes/:clientScopeId', {
  1039. realm : '@realm',
  1040. client : "@client",
  1041. clientScopeId : '@clientScopeId'
  1042. }, {
  1043. update : {
  1044. method : 'PUT'
  1045. }
  1046. });
  1047. });
  1048. module.factory('ClientEvaluateProtocolMappers', function($resource) {
  1049. return $resource(authUrl + '/admin/realms/:realm/clients/:client/evaluate-scopes/protocol-mappers?scope=:scopeParam', {
  1050. realm : '@realm',
  1051. client : "@client",
  1052. scopeParam : "@scopeParam"
  1053. });
  1054. });
  1055. module.factory('ClientEvaluateGrantedRoles', function($resource) {
  1056. return $resource(authUrl + '/admin/realms/:realm/clients/:client/evaluate-scopes/scope-mappings/:roleContainer/granted?scope=:scopeParam', {
  1057. realm : '@realm',
  1058. client : "@client",
  1059. roleContainer : "@roleContainer",
  1060. scopeParam : "@scopeParam"
  1061. });
  1062. });
  1063. module.factory('ClientEvaluateNotGrantedRoles', function($resource) {
  1064. return $resource(authUrl + '/admin/realms/:realm/clients/:client/evaluate-scopes/scope-mappings/:roleContainer/not-granted?scope=:scopeParam', {
  1065. realm : '@realm',
  1066. client : "@client",
  1067. roleContainer : "@roleContainer",
  1068. scopeParam : "@scopeParam"
  1069. });
  1070. });
  1071. module.factory('ClientEvaluateGenerateExampleAccessToken', function($resource) {
  1072. return buildClientEvaluateGenerateExampleUrl('generate-example-access-token');
  1073. });
  1074. module.factory('ClientEvaluateGenerateExampleIDToken', function($resource) {
  1075. return buildClientEvaluateGenerateExampleUrl('generate-example-id-token');
  1076. });
  1077. module.factory('ClientEvaluateGenerateExampleUserInfo', function($resource) {
  1078. return buildClientEvaluateGenerateExampleUrl('generate-example-userinfo');
  1079. });
  1080. function buildClientEvaluateGenerateExampleUrl(subPath) {
  1081. var urlTemplate = authUrl + '/admin/realms/:realm/clients/:client/evaluate-scopes/' + subPath + '?scope=:scopeParam&userId=:userId';
  1082. return {
  1083. url: function (parameters) {
  1084. return urlTemplate
  1085. .replace(':realm', parameters.realm)
  1086. .replace(':client', parameters.client)
  1087. .replace(':scopeParam', parameters.scopeParam)
  1088. .replace(':userId', parameters.userId);
  1089. }
  1090. }
  1091. }
  1092. module.factory('ClientProtocolMappersByProtocol', function($resource) {
  1093. return $resource(authUrl + '/admin/realms/:realm/clients/:client/protocol-mappers/protocol/:protocol', {
  1094. realm : '@realm',
  1095. client : "@client",
  1096. protocol : "@protocol"
  1097. });
  1098. });
  1099. module.factory('ClientScopeProtocolMappersByProtocol', function($resource) {
  1100. return $resource(authUrl + '/admin/realms/:realm/client-scopes/:clientScope/protocol-mappers/protocol/:protocol', {
  1101. realm : '@realm',
  1102. clientScope : "@clientScope",
  1103. protocol : "@protocol"
  1104. });
  1105. });
  1106. module.factory('ClientScopeRealmScopeMapping', function($resource) {
  1107. return $resource(authUrl + '/admin/realms/:realm/client-scopes/:clientScope/scope-mappings/realm', {
  1108. realm : '@realm',
  1109. clientScope : '@clientScope'
  1110. });
  1111. });
  1112. module.factory('ClientScopeAvailableRealmScopeMapping', function($resource) {
  1113. return $resource(authUrl + '/admin/realms/:realm/client-scopes/:clientScope/scope-mappings/realm/available', {
  1114. realm : '@realm',
  1115. clientScope : '@clientScope'
  1116. });
  1117. });
  1118. module.factory('ClientScopeCompositeRealmScopeMapping', function($resource) {
  1119. return $resource(authUrl + '/admin/realms/:realm/client-scopes/:clientScope/scope-mappings/realm/composite', {
  1120. realm : '@realm',
  1121. clientScope : '@clientScope'
  1122. });
  1123. });
  1124. module.factory('ClientScopeClientScopeMapping', function($resource) {
  1125. return $resource(authUrl + '/admin/realms/:realm/client-scopes/:clientScope/scope-mappings/clients/:targetClient', {
  1126. realm : '@realm',
  1127. clientScope : '@clientScope',
  1128. targetClient : '@targetClient'
  1129. });
  1130. });
  1131. module.factory('ClientScopeAvailableClientScopeMapping', function($resource) {
  1132. return $resource(authUrl + '/admin/realms/:realm/client-scopes/:clientScope/scope-mappings/clients/:targetClient/available', {
  1133. realm : '@realm',
  1134. clientScope : '@clientScope',
  1135. targetClient : '@targetClient'
  1136. });
  1137. });
  1138. module.factory('ClientScopeCompositeClientScopeMapping', function($resource) {
  1139. return $resource(authUrl + '/admin/realms/:realm/client-scopes/:clientScope/scope-mappings/clients/:targetClient/composite', {
  1140. realm : '@realm',
  1141. clientScope : '@clientScope',
  1142. targetClient : '@targetClient'
  1143. });
  1144. });
  1145. module.factory('ClientSessionStats', function($resource) {
  1146. return $resource(authUrl + '/admin/realms/:realm/clients/:client/session-stats', {
  1147. realm : '@realm',
  1148. client : "@client"
  1149. });
  1150. });
  1151. module.factory('ClientSessionStatsWithUsers', function($resource) {
  1152. return $resource(authUrl + '/admin/realms/:realm/clients/:client/session-stats?users=true', {
  1153. realm : '@realm',
  1154. client : "@client"
  1155. });
  1156. });
  1157. module.factory('ClientSessionCount', function($resource) {
  1158. return $resource(authUrl + '/admin/realms/:realm/clients/:client/session-count', {
  1159. realm : '@realm',
  1160. client : "@client"
  1161. });
  1162. });
  1163. module.factory('ClientUserSessions', function($resource) {
  1164. return $resource(authUrl + '/admin/realms/:realm/clients/:client/user-sessions', {
  1165. realm : '@realm',
  1166. client : "@client"
  1167. });
  1168. });
  1169. module.factory('ClientOfflineSessionCount', function($resource) {
  1170. return $resource(authUrl + '/admin/realms/:realm/clients/:client/offline-session-count', {
  1171. realm : '@realm',
  1172. client : "@client"
  1173. });
  1174. });
  1175. module.factory('ClientOfflineSessions', function($resource) {
  1176. return $resource(authUrl + '/admin/realms/:realm/clients/:client/offline-sessions', {
  1177. realm : '@realm',
  1178. client : "@client"
  1179. });
  1180. });
  1181. module.factory('RealmLogoutAll', function($resource) {
  1182. return $resource(authUrl + '/admin/realms/:realm/logout-all', {
  1183. realm : '@realm'
  1184. });
  1185. });
  1186. module.factory('ClientPushRevocation', function($resource) {
  1187. return $resource(authUrl + '/admin/realms/:realm/clients/:client/push-revocation', {
  1188. realm : '@realm',
  1189. client : "@client"
  1190. });
  1191. });
  1192. module.factory('ClientClusterNode', function($resource) {
  1193. return $resource(authUrl + '/admin/realms/:realm/clients/:client/nodes/:node', {
  1194. realm : '@realm',
  1195. client : "@client"
  1196. });
  1197. });
  1198. module.factory('ClientTestNodesAvailable', function($resource) {
  1199. return $resource(authUrl + '/admin/realms/:realm/clients/:client/test-nodes-available', {
  1200. realm : '@realm',
  1201. client : "@client"
  1202. });
  1203. });
  1204. module.factory('ClientCertificate', function($resource) {
  1205. return $resource(authUrl + '/admin/realms/:realm/clients/:client/certificates/:attribute', {
  1206. realm : '@realm',
  1207. client : "@client",
  1208. attribute: "@attribute"
  1209. });
  1210. });
  1211. module.factory('ClientCertificateGenerate', function($resource) {
  1212. return $resource(authUrl + '/admin/realms/:realm/clients/:client/certificates/:attribute/generate', {
  1213. realm : '@realm',
  1214. client : "@client",
  1215. attribute: "@attribute"
  1216. },
  1217. {
  1218. generate : {
  1219. method : 'POST'
  1220. }
  1221. });
  1222. });
  1223. module.factory('ClientCertificateDownload', function($resource) {
  1224. return $resource(authUrl + '/admin/realms/:realm/clients/:client/certificates/:attribute/download', {
  1225. realm : '@realm',
  1226. client : "@client",
  1227. attribute: "@attribute"
  1228. },
  1229. {
  1230. download : {
  1231. method : 'POST',
  1232. responseType: 'arraybuffer'
  1233. }
  1234. });
  1235. });
  1236. module.factory('Client', function($resource) {
  1237. return $resource(authUrl + '/admin/realms/:realm/clients/:client', {
  1238. realm : '@realm',
  1239. client : '@client'
  1240. }, {
  1241. update : {
  1242. method : 'PUT'
  1243. }
  1244. });
  1245. });
  1246. module.factory('ClientScope', function($resource) {
  1247. return $resource(authUrl + '/admin/realms/:realm/client-scopes/:clientScope', {
  1248. realm : '@realm',
  1249. clientScope : '@clientScope'
  1250. }, {
  1251. update : {
  1252. method : 'PUT'
  1253. }
  1254. });
  1255. });
  1256. module.factory('RealmDefaultClientScopes', function($resource) {
  1257. return $resource(authUrl + '/admin/realms/:realm/default-default-client-scopes/:clientScopeId', {
  1258. realm : '@realm',
  1259. clientScopeId : '@clientScopeId'
  1260. }, {
  1261. update : {
  1262. method : 'PUT'
  1263. }
  1264. });
  1265. });
  1266. module.factory('RealmOptionalClientScopes', function($resource) {
  1267. return $resource(authUrl + '/admin/realms/:realm/default-optional-client-scopes/:clientScopeId', {
  1268. realm : '@realm',
  1269. clientScopeId : '@clientScopeId'
  1270. }, {
  1271. update : {
  1272. method : 'PUT'
  1273. }
  1274. });
  1275. });
  1276. module.factory('ClientDescriptionConverter', function($resource) {
  1277. return $resource(authUrl + '/admin/realms/:realm/client-description-converter', {
  1278. realm : '@realm'
  1279. });
  1280. });
  1281. /*
  1282. module.factory('ClientInstallation', function($resource) {
  1283. return $resource(authUrl + '/admin/realms/:realm/clients/:client/installation/providers/:provider', {
  1284. realm : '@realm',
  1285. client : '@client',
  1286. provider : '@provider'
  1287. });
  1288. });
  1289. */
  1290. module.factory('ClientInstallation', function($resource) {
  1291. var url = authUrl + '/admin/realms/:realm/clients/:client/installation/providers/:provider';
  1292. return {
  1293. url : function(parameters)
  1294. {
  1295. return url.replace(':realm', parameters.realm).replace(':client', parameters.client).replace(':provider', parameters.provider);
  1296. }
  1297. }
  1298. });
  1299. module.factory('ClientInstallationJBoss', function($resource) {
  1300. var url = authUrl + '/admin/realms/:realm/clients/:client/installation/jboss';
  1301. return {
  1302. url : function(parameters)
  1303. {
  1304. return url.replace(':realm', parameters.realm).replace(':client', parameters.client);
  1305. }
  1306. }
  1307. });
  1308. module.factory('ClientSecret', function($resource) {
  1309. return $resource(authUrl + '/admin/realms/:realm/clients/:client/client-secret', {
  1310. realm : '@realm',
  1311. client : '@client'
  1312. }, {
  1313. update : {
  1314. method : 'POST'
  1315. }
  1316. });
  1317. });
  1318. module.factory('ClientRegistrationAccessToken', function($resource) {
  1319. return $resource(authUrl + '/admin/realms/:realm/clients/:client/registration-access-token', {
  1320. realm : '@realm',
  1321. client : '@client'
  1322. }, {
  1323. update : {
  1324. method : 'POST'
  1325. }
  1326. });
  1327. });
  1328. module.factory('ClientOrigins', function($resource) {
  1329. return $resource(authUrl + '/admin/realms/:realm/clients/:client/allowed-origins', {
  1330. realm : '@realm',
  1331. client : '@client'
  1332. }, {
  1333. update : {
  1334. method : 'PUT',
  1335. isArray : true
  1336. }
  1337. });
  1338. });
  1339. module.factory('ClientServiceAccountUser', function($resource) {
  1340. return $resource(authUrl + '/admin/realms/:realm/clients/:client/service-account-user', {
  1341. realm : '@realm',
  1342. client : '@client'
  1343. });
  1344. });
  1345. module.factory('Current', function(Realm, $route, $rootScope) {
  1346. var current = {
  1347. realms: {},
  1348. realm: null
  1349. };
  1350. $rootScope.$on('$routeChangeStart', function() {
  1351. current.realms = Realm.query({briefRepresentation: true}, function(realms) {
  1352. var currentRealm = null;
  1353. if ($route.current.params.realm) {
  1354. for (var i = 0; i < realms.length; i++) {
  1355. if (realms[i].realm == $route.current.params.realm) {
  1356. currentRealm = realms[i];
  1357. }
  1358. }
  1359. }
  1360. current.realm = currentRealm;
  1361. });
  1362. });
  1363. return current;
  1364. });
  1365. module.factory('TimeUnit', function() {
  1366. var t = {};
  1367. t.autoUnit = function(time) {
  1368. if (!time) {
  1369. return 'Hours';
  1370. }
  1371. var unit = 'Seconds';
  1372. if (time % 60 == 0) {
  1373. unit = 'Minutes';
  1374. time = time / 60;
  1375. }
  1376. if (time % 60 == 0) {
  1377. unit = 'Hours';
  1378. time = time / 60;
  1379. }
  1380. if (time % 24 == 0) {
  1381. unit = 'Days'
  1382. time = time / 24;
  1383. }
  1384. return unit;
  1385. }
  1386. t.toSeconds = function(time, unit) {
  1387. switch (unit) {
  1388. case 'Seconds': return time;
  1389. case 'Minutes': return time * 60;
  1390. case 'Hours': return time * 3600;
  1391. case 'Days': return time * 86400;
  1392. default: throw 'invalid unit ' + unit;
  1393. }
  1394. }
  1395. t.toUnit = function(time, unit) {
  1396. switch (unit) {
  1397. case 'Seconds': return time;
  1398. case 'Minutes': return Math.ceil(time / 60);
  1399. case 'Hours': return Math.ceil(time / 3600);
  1400. case 'Days': return Math.ceil(time / 86400);
  1401. default: throw 'invalid unit ' + unit;
  1402. }
  1403. }
  1404. return t;
  1405. });
  1406. module.factory('TimeUnit2', function() {
  1407. var t = {};
  1408. t.asUnit = function(time) {
  1409. var unit = 'Minutes';
  1410. if (time) {
  1411. if (time == -1) {
  1412. time = -1;
  1413. } else {
  1414. if (time < 60) {
  1415. time = 60;
  1416. }
  1417. if (time % 60 == 0) {
  1418. unit = 'Minutes';
  1419. time = time / 60;
  1420. }
  1421. if (time % 60 == 0) {
  1422. unit = 'Hours';
  1423. time = time / 60;
  1424. }
  1425. if (time % 24 == 0) {
  1426. unit = 'Days'
  1427. time = time / 24;
  1428. }
  1429. }
  1430. }
  1431. var v = {
  1432. unit: unit,
  1433. time: time,
  1434. toSeconds: function() {
  1435. switch (v.unit) {
  1436. case 'Minutes':
  1437. return v.time * 60;
  1438. case 'Hours':
  1439. return v.time * 3600;
  1440. case 'Days':
  1441. return v.time * 86400;
  1442. }
  1443. }
  1444. }
  1445. return v;
  1446. }
  1447. return t;
  1448. });
  1449. module.filter('removeSelectedPolicies', function() {
  1450. return function(policies, selectedPolicies) {
  1451. var result = [];
  1452. for(var i in policies) {
  1453. var policy = policies[i];
  1454. var policyAvailable = true;
  1455. for(var j in selectedPolicies) {
  1456. if(policy.id === selectedPolicies[j].id && !policy.multipleSupported) {
  1457. policyAvailable = false;
  1458. }
  1459. }
  1460. if(policyAvailable) {
  1461. result.push(policy);
  1462. }
  1463. }
  1464. return result;
  1465. }
  1466. });
  1467. module.factory('IdentityProvider', function($resource) {
  1468. return $resource(authUrl + '/admin/realms/:realm/identity-provider/instances/:alias', {
  1469. realm : '@realm',
  1470. alias : '@alias'
  1471. }, {
  1472. update: {
  1473. method : 'PUT'
  1474. }
  1475. });
  1476. });
  1477. module.factory('IdentityProviderExport', function($resource) {
  1478. var url = authUrl + '/admin/realms/:realm/identity-provider/instances/:alias/export';
  1479. return {
  1480. url : function(parameters)
  1481. {
  1482. return url.replace(':realm', parameters.realm).replace(':alias', parameters.alias);
  1483. }
  1484. }
  1485. });
  1486. module.factory('IdentityProviderFactory', function($resource) {
  1487. return $resource(authUrl + '/admin/realms/:realm/identity-provider/providers/:provider_id', {
  1488. realm : '@realm',
  1489. provider_id : '@provider_id'
  1490. });
  1491. });
  1492. module.factory('IdentityProviderMapperTypes', function($resource) {
  1493. return $resource(authUrl + '/admin/realms/:realm/identity-provider/instances/:alias/mapper-types', {
  1494. realm : '@realm',
  1495. alias : '@alias'
  1496. });
  1497. });
  1498. module.factory('IdentityProviderMappers', function($resource) {
  1499. return $resource(authUrl + '/admin/realms/:realm/identity-provider/instances/:alias/mappers', {
  1500. realm : '@realm',
  1501. alias : '@alias'
  1502. });
  1503. });
  1504. module.factory('IdentityProviderMapper', function($resource) {
  1505. return $resource(authUrl + '/admin/realms/:realm/identity-provider/instances/:alias/mappers/:mapperId', {
  1506. realm : '@realm',
  1507. alias : '@alias',
  1508. mapperId: '@mapperId'
  1509. }, {
  1510. update: {
  1511. method : 'PUT'
  1512. }
  1513. });
  1514. });
  1515. module.factory('AuthenticationFlowExecutions', function($resource) {
  1516. return $resource(authUrl + '/admin/realms/:realm/authentication/flows/:alias/executions', {
  1517. realm : '@realm',
  1518. alias : '@alias'
  1519. }, {
  1520. update : {
  1521. method : 'PUT'
  1522. }
  1523. });
  1524. });
  1525. module.factory('CreateExecutionFlow', function($resource) {
  1526. return $resource(authUrl + '/admin/realms/:realm/authentication/flows/:alias/executions/flow', {
  1527. realm : '@realm',
  1528. alias : '@alias'
  1529. });
  1530. });
  1531. module.factory('CreateExecution', function($resource) {
  1532. return $resource(authUrl + '/admin/realms/:realm/authentication/flows/:alias/executions/execution', {
  1533. realm : '@realm',
  1534. alias : '@alias'
  1535. });
  1536. });
  1537. module.factory('AuthenticationFlows', function($resource) {
  1538. return $resource(authUrl + '/admin/realms/:realm/authentication/flows/:flow', {
  1539. realm : '@realm',
  1540. flow: '@flow'
  1541. });
  1542. });
  1543. module.factory('AuthenticationFormProviders', function($resource) {
  1544. return $resource(authUrl + '/admin/realms/:realm/authentication/form-providers', {
  1545. realm : '@realm'
  1546. });
  1547. });
  1548. module.factory('AuthenticationFormActionProviders', function($resource) {
  1549. return $resource(authUrl + '/admin/realms/:realm/authentication/form-action-providers', {
  1550. realm : '@realm'
  1551. });
  1552. });
  1553. module.factory('AuthenticatorProviders', function($resource) {
  1554. return $resource(authUrl + '/admin/realms/:realm/authentication/authenticator-providers', {
  1555. realm : '@realm'
  1556. });
  1557. });
  1558. module.factory('ClientAuthenticatorProviders', function($resource) {
  1559. return $resource(authUrl + '/admin/realms/:realm/authentication/client-authenticator-providers', {
  1560. realm : '@realm'
  1561. });
  1562. });
  1563. module.factory('AuthenticationFlowsCopy', function($resource) {
  1564. return $resource(authUrl + '/admin/realms/:realm/authentication/flows/:alias/copy', {
  1565. realm : '@realm',
  1566. alias : '@alias'
  1567. });
  1568. });
  1569. module.factory('AuthenticationFlowsUpdate', function($resource) {
  1570. return $resource(authUrl + '/admin/realms/:realm/authentication/flows/:flow', {
  1571. realm : '@realm',
  1572. flow : '@flow'
  1573. }, {
  1574. update : {
  1575. method : 'PUT'
  1576. }
  1577. });
  1578. });
  1579. module.factory('AuthenticationConfigDescription', function($resource) {
  1580. return $resource(authUrl + '/admin/realms/:realm/authentication/config-description/:provider', {
  1581. realm : '@realm',
  1582. provider: '@provider'
  1583. });
  1584. });
  1585. module.factory('PerClientAuthenticationConfigDescription', function($resource) {
  1586. return $resource(authUrl + '/admin/realms/:realm/authentication/per-client-config-description', {
  1587. realm : '@realm'
  1588. });
  1589. });
  1590. module.factory('AuthenticationConfig', function($resource) {
  1591. return $resource(authUrl + '/admin/realms/:realm/authentication/config/:config', {
  1592. realm : '@realm',
  1593. config: '@config'
  1594. }, {
  1595. update: {
  1596. method : 'PUT'
  1597. }
  1598. });
  1599. });
  1600. module.factory('AuthenticationExecutionConfig', function($resource) {
  1601. return $resource(authUrl + '/admin/realms/:realm/authentication/executions/:execution/config', {
  1602. realm : '@realm',
  1603. execution: '@execution'
  1604. });
  1605. });
  1606. module.factory('AuthenticationExecution', function($resource) {
  1607. return $resource(authUrl + '/admin/realms/:realm/authentication/executions/:execution', {
  1608. realm : '@realm',
  1609. execution : '@execution'
  1610. }, {
  1611. update : {
  1612. method : 'PUT'
  1613. }
  1614. });
  1615. });
  1616. module.factory('AuthenticationExecutionRaisePriority', function($resource) {
  1617. return $resource(authUrl + '/admin/realms/:realm/authentication/executions/:execution/raise-priority', {
  1618. realm : '@realm',
  1619. execution : '@execution'
  1620. });
  1621. });
  1622. module.factory('AuthenticationExecutionLowerPriority', function($resource) {
  1623. return $resource(authUrl + '/admin/realms/:realm/authentication/executions/:execution/lower-priority', {
  1624. realm : '@realm',
  1625. execution : '@execution'
  1626. });
  1627. });
  1628. module.service('SelectRoleDialog', function($modal) {
  1629. var dialog = {};
  1630. var openDialog = function(title, message, btns) {
  1631. var controller = function($scope, $modalInstance, title, message, btns) {
  1632. $scope.title = title;
  1633. $scope.message = message;
  1634. $scope.btns = btns;
  1635. $scope.ok = function () {
  1636. $modalInstance.close();
  1637. };
  1638. $scope.cancel = function () {
  1639. $modalInstance.dismiss('cancel');
  1640. };
  1641. };
  1642. return $modal.open({
  1643. templateUrl: resourceUrl + '/templates/kc-modal.html',
  1644. controller: controller,
  1645. resolve: {
  1646. title: function() {
  1647. return title;
  1648. },
  1649. message: function() {
  1650. return message;
  1651. },
  1652. btns: function() {
  1653. return btns;
  1654. }
  1655. }
  1656. }).result;
  1657. }
  1658. var escapeHtml = function(str) {
  1659. var div = document.createElement('div');
  1660. div.appendChild(document.createTextNode(str));
  1661. return div.innerHTML;
  1662. };
  1663. dialog.confirmDelete = function(name, type, success) {
  1664. var title = 'Delete ' + escapeHtml(type.charAt(0).toUpperCase() + type.slice(1));
  1665. var msg = 'Are you sure you want to permanently delete the ' + type + ' ' + name + '?';
  1666. var btns = {
  1667. ok: {
  1668. label: 'Delete',
  1669. cssClass: 'btn btn-danger'
  1670. },
  1671. cancel: {
  1672. label: 'Cancel',
  1673. cssClass: 'btn btn-default'
  1674. }
  1675. }
  1676. openDialog(title, msg, btns).then(success);
  1677. }
  1678. dialog.confirmGenerateKeys = function(name, type, success) {
  1679. var title = 'Generate new keys for realm';
  1680. var msg = 'Are you sure you want to permanently generate new keys for ' + name + '?';
  1681. var btns = {
  1682. ok: {
  1683. label: 'Generate Keys',
  1684. cssClass: 'btn btn-danger'
  1685. },
  1686. cancel: {
  1687. label: 'Cancel',
  1688. cssClass: 'btn btn-default'
  1689. }
  1690. }
  1691. openDialog(title, msg, btns).then(success);
  1692. }
  1693. dialog.confirm = function(title, message, success, cancel) {
  1694. var btns = {
  1695. ok: {
  1696. label: title,
  1697. cssClass: 'btn btn-danger'
  1698. },
  1699. cancel: {
  1700. label: 'Cancel',
  1701. cssClass: 'btn btn-default'
  1702. }
  1703. }
  1704. openDialog(title, message, btns).then(success, cancel);
  1705. }
  1706. return dialog
  1707. });
  1708. module.factory('Group', function($resource) {
  1709. return $resource(authUrl + '/admin/realms/:realm/groups/:groupId', {
  1710. realm : '@realm',
  1711. userId : '@groupId'
  1712. }, {
  1713. update : {
  1714. method : 'PUT'
  1715. }
  1716. });
  1717. });
  1718. module.factory('GroupChildren', function($resource) {
  1719. return $resource(authUrl + '/admin/realms/:realm/groups/:groupId/children', {
  1720. realm : '@realm',
  1721. groupId : '@groupId'
  1722. });
  1723. });
  1724. module.factory('GroupsCount', function($resource) {
  1725. return $resource(authUrl + '/admin/realms/:realm/groups/count', {
  1726. realm : '@realm'
  1727. },
  1728. {
  1729. query: {
  1730. isArray: false,
  1731. method: 'GET',
  1732. params: {},
  1733. transformResponse: function (data) {
  1734. return angular.fromJson(data)
  1735. }
  1736. }
  1737. });
  1738. });
  1739. module.factory('Groups', function($resource) {
  1740. return $resource(authUrl + '/admin/realms/:realm/groups', {
  1741. realm : '@realm'
  1742. })
  1743. });
  1744. module.factory('GroupRealmRoleMapping', function($resource) {
  1745. return $resource(authUrl + '/admin/realms/:realm/groups/:groupId/role-mappings/realm', {
  1746. realm : '@realm',
  1747. groupId : '@groupId'
  1748. });
  1749. });
  1750. module.factory('GroupCompositeRealmRoleMapping', function($resource) {
  1751. return $resource(authUrl + '/admin/realms/:realm/groups/:groupId/role-mappings/realm/composite', {
  1752. realm : '@realm',
  1753. groupId : '@groupId'
  1754. });
  1755. });
  1756. module.factory('GroupAvailableRealmRoleMapping', function($resource) {
  1757. return $resource(authUrl + '/admin/realms/:realm/groups/:groupId/role-mappings/realm/available', {
  1758. realm : '@realm',
  1759. groupId : '@groupId'
  1760. });
  1761. });
  1762. module.factory('GroupClientRoleMapping', function($resource) {
  1763. return $resource(authUrl + '/admin/realms/:realm/groups/:groupId/role-mappings/clients/:client', {
  1764. realm : '@realm',
  1765. groupId : '@groupId',
  1766. client : "@client"
  1767. });
  1768. });
  1769. module.factory('GroupAvailableClientRoleMapping', function($resource) {
  1770. return $resource(authUrl + '/admin/realms/:realm/groups/:groupId/role-mappings/clients/:client/available', {
  1771. realm : '@realm',
  1772. groupId : '@groupId',
  1773. client : "@client"
  1774. });
  1775. });
  1776. module.factory('GroupCompositeClientRoleMapping', function($resource) {
  1777. return $resource(authUrl + '/admin/realms/:realm/groups/:groupId/role-mappings/clients/:client/composite', {
  1778. realm : '@realm',
  1779. groupId : '@groupId',
  1780. client : "@client"
  1781. });
  1782. });
  1783. module.factory('GroupMembership', function($resource) {
  1784. return $resource(authUrl + '/admin/realms/:realm/groups/:groupId/members', {
  1785. realm : '@realm',
  1786. groupId : '@groupId'
  1787. });
  1788. });
  1789. module.factory('RoleList', function($resource) {
  1790. return $resource(authUrl + '/admin/realms/:realm/roles', {
  1791. realm : '@realm'
  1792. });
  1793. });
  1794. module.factory('RoleMembership', function($resource) {
  1795. return $resource(authUrl + '/admin/realms/:realm/roles/:role/users', {
  1796. realm : '@realm',
  1797. role : '@role'
  1798. });
  1799. });
  1800. module.factory('ClientRoleList', function($resource) {
  1801. return $resource(authUrl + '/admin/realms/:realm/clients/:client/roles', {
  1802. realm : '@realm',
  1803. client : '@client'
  1804. });
  1805. });
  1806. module.factory('ClientRoleMembership', function($resource) {
  1807. return $resource(authUrl + '/admin/realms/:realm/clients/:client/roles/:role/users', {
  1808. realm : '@realm',
  1809. client : '@client',
  1810. role : '@role'
  1811. });
  1812. });
  1813. module.factory('UserGroupMembership', function($resource) {
  1814. return $resource(authUrl + '/admin/realms/:realm/users/:userId/groups', {
  1815. realm : '@realm',
  1816. userId : '@userId'
  1817. });
  1818. });
  1819. module.factory('UserGroupMapping', function($resource) {
  1820. return $resource(authUrl + '/admin/realms/:realm/users/:userId/groups/:groupId', {
  1821. realm : '@realm',
  1822. userId : '@userId',
  1823. groupId : '@groupId'
  1824. }, {
  1825. update : {
  1826. method : 'PUT'
  1827. }
  1828. });
  1829. });
  1830. module.factory('UserProfile', function($resource) {
  1831. return $resource(authUrl + '/admin/realms/:realm/users/profile', {
  1832. realm : '@realm'
  1833. }, {
  1834. update : {
  1835. method : 'PUT'
  1836. }
  1837. });
  1838. });
  1839. module.factory('DefaultGroups', function($resource) {
  1840. return $resource(authUrl + '/admin/realms/:realm/default-groups/:groupId', {
  1841. realm : '@realm',
  1842. groupId : '@groupId'
  1843. }, {
  1844. update : {
  1845. method : 'PUT'
  1846. }
  1847. });
  1848. });
  1849. module.factory('SubComponentTypes', function($resource) {
  1850. return $resource(authUrl + '/admin/realms/:realm/components/:componentId/sub-component-types', {
  1851. realm: '@realm',
  1852. componentId: '@componentId'
  1853. });
  1854. });
  1855. module.factory('Components', function($resource, ComponentUtils) {
  1856. return $resource(authUrl + '/admin/realms/:realm/components/:componentId', {
  1857. realm : '@realm',
  1858. componentId : '@componentId'
  1859. }, {
  1860. update : {
  1861. method : 'PUT',
  1862. transformRequest: function(componentInstance) {
  1863. if (componentInstance.config) {
  1864. ComponentUtils.removeLastEmptyValue(componentInstance.config);
  1865. }
  1866. return angular.toJson(componentInstance);
  1867. }
  1868. },
  1869. save : {
  1870. method : 'POST',
  1871. transformRequest: function(componentInstance) {
  1872. if (componentInstance.config) {
  1873. ComponentUtils.removeLastEmptyValue(componentInstance.config);
  1874. }
  1875. return angular.toJson(componentInstance);
  1876. }
  1877. }
  1878. });
  1879. });
  1880. module.factory('UserStorageOperations', function($resource) {
  1881. var object = {}
  1882. object.sync = $resource(authUrl + '/admin/realms/:realm/user-storage/:componentId/sync', {
  1883. realm : '@realm',
  1884. componentId : '@componentId'
  1885. });
  1886. object.removeImportedUsers = $resource(authUrl + '/admin/realms/:realm/user-storage/:componentId/remove-imported-users', {
  1887. realm : '@realm',
  1888. componentId : '@componentId'
  1889. });
  1890. object.unlinkUsers = $resource(authUrl + '/admin/realms/:realm/user-storage/:componentId/unlink-users', {
  1891. realm : '@realm',
  1892. componentId : '@componentId'
  1893. });
  1894. object.simpleName = $resource(authUrl + '/admin/realms/:realm/user-storage/:componentId/name', {
  1895. realm : '@realm',
  1896. componentId : '@componentId'
  1897. });
  1898. return object;
  1899. });
  1900. module.factory('ClientStorageOperations', function($resource) {
  1901. var object = {}
  1902. object.simpleName = $resource(authUrl + '/admin/realms/:realm/client-storage/:componentId/name', {
  1903. realm : '@realm',
  1904. componentId : '@componentId'
  1905. });
  1906. return object;
  1907. });
  1908. module.factory('ClientRegistrationPolicyProviders', function($resource) {
  1909. return $resource(authUrl + '/admin/realms/:realm/client-registration-policy/providers', {
  1910. realm : '@realm',
  1911. });
  1912. });
  1913. module.factory('ClientPoliciesProfiles', function($resource) {
  1914. return $resource(authUrl + '/admin/realms/:realm/client-policies/profiles?include-global-profiles=:includeGlobalProfiles', {
  1915. realm : '@realm',
  1916. includeGlobalProfiles : '@includeGlobalProfiles'
  1917. }, {
  1918. update : {
  1919. method : 'PUT'
  1920. }
  1921. });
  1922. });
  1923. module.factory('ClientPolicies', function($resource) {
  1924. return $resource(authUrl + '/admin/realms/:realm/client-policies/policies', {
  1925. realm : '@realm',
  1926. }, {
  1927. update : {
  1928. method : 'PUT'
  1929. }
  1930. });
  1931. });
  1932. module.factory('LDAPMapperSync', function($resource) {
  1933. return $resource(authUrl + '/admin/realms/:realm/user-storage/:parentId/mappers/:mapperId/sync', {
  1934. realm : '@realm',
  1935. componentId : '@componentId',
  1936. mapperId: '@mapperId'
  1937. });
  1938. });
  1939. module.factory('UserGroupMembershipCount', function($resource) {
  1940. return $resource(authUrl + '/admin/realms/:realm/users/:userId/groups/count', {
  1941. realm : '@realm',
  1942. userId : '@userId'
  1943. },
  1944. {
  1945. query: {
  1946. isArray: false,
  1947. method: 'GET',
  1948. params: {},
  1949. transformResponse: function (data) {
  1950. return angular.fromJson(data)
  1951. }
  1952. }
  1953. });
  1954. });