clients.js 142 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857
  1. Array.prototype.remove = function(from, to) {
  2. var rest = this.slice((to || from) + 1 || this.length);
  3. this.length = from < 0 ? this.length + from : from;
  4. return this.push.apply(this, rest);
  5. };
  6. module.controller('ClientTabCtrl', function(Dialog, $scope, Current, Notifications, $location) {
  7. $scope.removeClient = function() {
  8. Dialog.confirmDelete($scope.client.clientId, 'client', function() {
  9. $scope.client.$remove({
  10. realm : Current.realm.realm,
  11. client : $scope.client.id
  12. }, function() {
  13. $location.url("/realms/" + Current.realm.realm + "/clients");
  14. Notifications.success("The client has been deleted.");
  15. });
  16. });
  17. };
  18. });
  19. module.controller('ClientRoleListCtrl', function($scope, $route, realm, client, ClientRoleList, RoleById, Notifications, Dialog) {
  20. $scope.realm = realm;
  21. $scope.roles = [];
  22. $scope.client = client;
  23. $scope.query = {
  24. realm: realm.realm,
  25. client: $scope.client.id,
  26. search : null,
  27. max : 20,
  28. first : 0
  29. }
  30. $scope.$watch('query.search', function (newVal, oldVal) {
  31. if($scope.query.search && $scope.query.search.length >= 3) {
  32. $scope.firstPage();
  33. }
  34. }, true);
  35. $scope.firstPage = function() {
  36. $scope.query.first = 0;
  37. $scope.searchQuery();
  38. }
  39. $scope.previousPage = function() {
  40. $scope.query.first -= parseInt($scope.query.max);
  41. if ($scope.query.first < 0) {
  42. $scope.query.first = 0;
  43. }
  44. $scope.searchQuery();
  45. }
  46. $scope.nextPage = function() {
  47. $scope.query.first += parseInt($scope.query.max);
  48. $scope.searchQuery();
  49. }
  50. $scope.searchQuery = function() {
  51. $scope.searchLoaded = false;
  52. $scope.roles = ClientRoleList.query($scope.query, function() {
  53. $scope.searchLoaded = true;
  54. $scope.lastSearch = $scope.query.search;
  55. });
  56. };
  57. $scope.searchQuery();
  58. $scope.removeRole = function(role) {
  59. Dialog.confirmDelete(role.name, 'role', function() {
  60. RoleById.remove({
  61. realm: realm.realm,
  62. role: role.id
  63. }, function () {
  64. $route.reload();
  65. Notifications.success("The role has been deleted.");
  66. });
  67. });
  68. };
  69. });
  70. module.controller('ClientCredentialsCtrl', function($scope, $location, realm, client, clientAuthenticatorProviders, clientConfigProperties, Client, ClientRegistrationAccessToken, Notifications) {
  71. $scope.realm = realm;
  72. $scope.client = angular.copy(client);
  73. $scope.clientAuthenticatorProviders = clientAuthenticatorProviders;
  74. var updateCurrentPartial = function(val) {
  75. $scope.clientAuthenticatorConfigPartial;
  76. switch(val) {
  77. case 'client-secret':
  78. $scope.clientAuthenticatorConfigPartial = 'client-credentials-secret.html';
  79. break;
  80. case 'client-jwt':
  81. $scope.clientAuthenticatorConfigPartial = 'client-credentials-jwt.html';
  82. break;
  83. case 'client-secret-jwt':
  84. $scope.clientAuthenticatorConfigPartial = 'client-credentials-secret-jwt.html';
  85. break;
  86. case 'client-x509':
  87. $scope.clientAuthenticatorConfigPartial = 'client-credentials-x509.html';
  88. break;
  89. default:
  90. $scope.currentAuthenticatorConfigProperties = clientConfigProperties[val];
  91. $scope.clientAuthenticatorConfigPartial = 'client-credentials-generic.html';
  92. break;
  93. }
  94. };
  95. updateCurrentPartial(client.clientAuthenticatorType);
  96. $scope.$watch('client.clientAuthenticatorType', function() {
  97. if (!angular.equals($scope.client.clientAuthenticatorType, client.clientAuthenticatorType)) {
  98. Client.update({
  99. realm : realm.realm,
  100. client : client.id
  101. }, $scope.client, function() {
  102. $scope.changed = false;
  103. client = angular.copy($scope.client);
  104. updateCurrentPartial(client.clientAuthenticatorType)
  105. });
  106. }
  107. }, true);
  108. $scope.regenerateRegistrationAccessToken = function() {
  109. var secret = ClientRegistrationAccessToken.update({ realm : $scope.realm.realm, client : $scope.client.id },
  110. function(data) {
  111. Notifications.success('The registration access token has been updated.');
  112. $scope.client['registrationAccessToken'] = data.registrationAccessToken;
  113. },
  114. function() {
  115. Notifications.error('Failed to update the registration access token');
  116. }
  117. );
  118. };
  119. });
  120. module.controller('ClientSecretCtrl', function($scope, $location, Client, ClientSecret, Notifications) {
  121. var secret = ClientSecret.get({ realm : $scope.realm.realm, client : $scope.client.id },
  122. function() {
  123. $scope.secret = secret.value;
  124. }
  125. );
  126. $scope.changePassword = function() {
  127. var secret = ClientSecret.update({ realm : $scope.realm.realm, client : $scope.client.id },
  128. function() {
  129. Notifications.success('The secret has been changed.');
  130. $scope.secret = secret.value;
  131. },
  132. function() {
  133. Notifications.error("The secret was not changed due to a problem.");
  134. $scope.secret = "error";
  135. }
  136. );
  137. };
  138. $scope.tokenEndpointAuthSigningAlg = $scope.client.attributes['token.endpoint.auth.signing.alg'];
  139. $scope.switchChange = function() {
  140. $scope.changed = true;
  141. }
  142. $scope.save = function() {
  143. $scope.client.attributes['token.endpoint.auth.signing.alg'] = $scope.tokenEndpointAuthSigningAlg;
  144. Client.update({
  145. realm : $scope.realm.realm,
  146. client : $scope.client.id
  147. }, $scope.client, function() {
  148. $scope.changed = false;
  149. $scope.clientCopy = angular.copy($scope.client);
  150. Notifications.success("Client authentication configuration has been saved to the client.");
  151. });
  152. };
  153. $scope.$watch(function() {
  154. return $location.path();
  155. }, function() {
  156. $scope.path = $location.path().substring(1).split("/");
  157. });
  158. $scope.cancel = function() {
  159. $location.url("/realms/" + $scope.realm.realm + "/clients/" + $scope.client.id + "/credentials");
  160. };
  161. });
  162. module.controller('ClientX509Ctrl', function($scope, $location, Client, Notifications) {
  163. console.log('ClientX509Ctrl invoked');
  164. $scope.clientCopy = angular.copy($scope.client);
  165. $scope.changed = false;
  166. $scope.$watch('client', function() {
  167. if (!angular.equals($scope.client, $scope.clientCopy)) {
  168. $scope.changed = true;
  169. }
  170. }, true);
  171. function updateProperties() {
  172. if ($scope.client.attributes["x509.allow.regex.pattern.comparison"]) {
  173. if ($scope.client.attributes["x509.allow.regex.pattern.comparison"] == "true") {
  174. $scope.allowRegexPatternComparison = true;
  175. } else {
  176. $scope.allowRegexPatternComparison = false;
  177. }
  178. }
  179. }
  180. updateProperties();
  181. $scope.switchChange = function() {
  182. $scope.changed = true;
  183. }
  184. $scope.save = function() {
  185. if ($scope.allowRegexPatternComparison == true) {
  186. $scope.client.attributes["x509.allow.regex.pattern.comparison"] = "true";
  187. } else {
  188. $scope.client.attributes["x509.allow.regex.pattern.comparison"] = "false";
  189. }
  190. if (!$scope.client.attributes["x509.subjectdn"]) {
  191. Notifications.error("The SubjectDN must not be empty.");
  192. } else {
  193. Client.update({
  194. realm : $scope.realm.realm,
  195. client : $scope.client.id
  196. }, $scope.client, function() {
  197. $scope.changed = false;
  198. $scope.clientCopy = angular.copy($scope.client);
  199. Notifications.success("Client authentication configuration has been saved to the client.");
  200. }, function() {
  201. Notifications.error("The SubjectDN was not changed due to a problem.");
  202. $scope.subjectdn = "error";
  203. });
  204. }
  205. };
  206. $scope.$watch(function() {
  207. return $location.path();
  208. }, function() {
  209. $scope.path = $location.path().substring(1).split("/");
  210. });
  211. $scope.reset = function() {
  212. $scope.client.attributes["x509.subjectdn"] = $scope.clientCopy.attributes["x509.subjectdn"];
  213. $scope.client.attributes["x509.allow.regex.pattern.comparison"] = $scope.clientCopy.attributes["x509.allow.regex.pattern.comparison"];
  214. updateProperties();
  215. $location.url("/realms/" + $scope.realm.realm + "/clients/" + $scope.client.id + "/credentials");
  216. };
  217. });
  218. module.controller('ClientSignedJWTCtrl', function($scope, Client, Notifications) {
  219. console.log('ClientSignedJWTCtrl invoked');
  220. $scope.tokenEndpointAuthSigningAlg = $scope.client.attributes['token.endpoint.auth.signing.alg'];
  221. $scope.$watch('tokenEndpointAuthSigningAlg', function() {
  222. if (!angular.equals($scope.client.attributes['token.endpoint.auth.signing.alg'], $scope.tokenEndpointAuthSigningAlg)) {
  223. $scope.client.attributes['token.endpoint.auth.signing.alg'] = $scope.tokenEndpointAuthSigningAlg;
  224. Client.update({
  225. realm : $scope.realm.realm,
  226. client : $scope.client.id
  227. }, $scope.client, function() {
  228. Notifications.success("Signature algorithm has been saved to the client.");
  229. });
  230. }
  231. }, true);
  232. });
  233. module.controller('ClientGenericCredentialsCtrl', function($scope, $location, Client, Notifications) {
  234. console.log('ClientGenericCredentialsCtrl invoked');
  235. $scope.clientCopy = angular.copy($scope.client);
  236. $scope.changed = false;
  237. $scope.$watch('client', function() {
  238. if (!angular.equals($scope.client, $scope.clientCopy)) {
  239. $scope.changed = true;
  240. }
  241. }, true);
  242. $scope.save = function() {
  243. Client.update({
  244. realm : $scope.realm.realm,
  245. client : $scope.client.id
  246. }, $scope.client, function() {
  247. $scope.changed = false;
  248. $scope.clientCopy = angular.copy($scope.client);
  249. Notifications.success("Client authentication configuration has been saved to the client.");
  250. });
  251. };
  252. $scope.reset = function() {
  253. $scope.client = angular.copy($scope.clientCopy);
  254. $scope.changed = false;
  255. };
  256. });
  257. module.controller('ClientIdentityProviderCtrl', function($scope, $location, $route, realm, client, Client, $location, Notifications) {
  258. $scope.realm = realm;
  259. $scope.client = angular.copy(client);
  260. var length = 0;
  261. if ($scope.client.identityProviders) {
  262. length = $scope.client.identityProviders.length;
  263. for (i = 0; i < $scope.client.identityProviders.length; i++) {
  264. var clientProvider = $scope.client.identityProviders[i];
  265. if (clientProvider.retrieveToken) {
  266. clientProvider.retrieveToken = clientProvider.retrieveToken.toString();
  267. }
  268. }
  269. } else {
  270. $scope.client.identityProviders = [];
  271. }
  272. $scope.identityProviders = [];
  273. var providersMissingInClient = [];
  274. for (j = 0; j < realm.identityProviders.length; j++) {
  275. var identityProvider = realm.identityProviders[j];
  276. var clientProvider = null;
  277. for (i = 0; i < $scope.client.identityProviders.length; i++) {
  278. clientProvider = $scope.client.identityProviders[i];
  279. if (clientProvider) {
  280. if (clientProvider.id == identityProvider.id) {
  281. $scope.identityProviders[i] = {};
  282. $scope.identityProviders[i].identityProvider = identityProvider;
  283. $scope.identityProviders[i].retrieveToken = clientProvider.retrieveToken;
  284. break;
  285. }
  286. clientProvider = null;
  287. }
  288. }
  289. if (clientProvider == null) {
  290. providersMissingInClient.push(identityProvider);
  291. }
  292. }
  293. for (j = 0; j < providersMissingInClient.length; j++) {
  294. var identityProvider = providersMissingInClient[j];
  295. var currentProvider = {};
  296. currentProvider.identityProvider = identityProvider;
  297. currentProvider.retrieveToken = "false";
  298. $scope.identityProviders.push(currentProvider);
  299. var currentClientProvider = {};
  300. currentClientProvider.id = identityProvider.id;
  301. currentClientProvider.retrieveToken = "false";
  302. $scope.client.identityProviders.push(currentClientProvider);
  303. }
  304. var oldCopy = angular.copy($scope.client);
  305. $scope.save = function() {
  306. Client.update({
  307. realm : realm.realm,
  308. client : client.id
  309. }, $scope.client, function() {
  310. $scope.changed = false;
  311. $route.reload();
  312. Notifications.success("Your changes have been saved to the client.");
  313. });
  314. };
  315. $scope.reset = function() {
  316. $scope.client = angular.copy(oldCopy);
  317. $scope.changed = false;
  318. };
  319. $scope.$watch('client', function() {
  320. if (!angular.equals($scope.client, oldCopy)) {
  321. $scope.changed = true;
  322. }
  323. }, true);
  324. });
  325. module.controller('ClientSamlKeyCtrl', function($scope, $location, $http, $upload, realm, client,
  326. ClientCertificate, ClientCertificateGenerate,
  327. ClientCertificateDownload, Notifications) {
  328. $scope.realm = realm;
  329. $scope.client = client;
  330. var signingKeyInfo = ClientCertificate.get({ realm : realm.realm, client : client.id, attribute: 'saml.signing' },
  331. function() {
  332. $scope.signingKeyInfo = signingKeyInfo;
  333. }
  334. );
  335. $scope.generateSigningKey = function() {
  336. var keyInfo = ClientCertificateGenerate.generate({ realm : realm.realm, client : client.id, attribute: 'saml.signing' },
  337. function() {
  338. Notifications.success('Signing key has been regenerated.');
  339. $scope.signingKeyInfo = keyInfo;
  340. },
  341. function() {
  342. Notifications.error("Signing key was not regenerated.");
  343. }
  344. );
  345. };
  346. $scope.importSigningKey = function() {
  347. $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/saml/Signing/import/saml.signing");
  348. };
  349. $scope.exportSigningKey = function() {
  350. $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/saml/Signing/export/saml.signing");
  351. };
  352. var encryptionKeyInfo = ClientCertificate.get({ realm : realm.realm, client : client.id, attribute: 'saml.encryption' },
  353. function() {
  354. $scope.encryptionKeyInfo = encryptionKeyInfo;
  355. }
  356. );
  357. $scope.generateEncryptionKey = function() {
  358. var keyInfo = ClientCertificateGenerate.generate({ realm : realm.realm, client : client.id, attribute: 'saml.encryption' },
  359. function() {
  360. Notifications.success('Encryption key has been regenerated.');
  361. $scope.encryptionKeyInfo = keyInfo;
  362. },
  363. function() {
  364. Notifications.error("Encryption key was not regenerated.");
  365. }
  366. );
  367. };
  368. $scope.importEncryptionKey = function() {
  369. $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/saml/Encryption/import/saml.encryption");
  370. };
  371. $scope.exportEncryptionKey = function() {
  372. $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/saml/Encryption/export/saml.encryption");
  373. };
  374. $scope.$watch(function() {
  375. return $location.path();
  376. }, function() {
  377. $scope.path = $location.path().substring(1).split("/");
  378. });
  379. });
  380. module.controller('ClientCertificateImportCtrl', function($scope, $location, $http, $upload, realm, client, callingContext, $routeParams,
  381. ClientCertificate, ClientCertificateGenerate,
  382. ClientCertificateDownload, Notifications) {
  383. console.log("callingContext: " + callingContext);
  384. var keyType = $routeParams.keyType;
  385. var attribute = $routeParams.attribute;
  386. $scope.realm = realm;
  387. $scope.client = client;
  388. $scope.keyType = keyType;
  389. if (callingContext == 'saml') {
  390. var uploadUrl = authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/certificates/' + attribute + '/upload';
  391. var redirectLocation = "/realms/" + realm.realm + "/clients/" + client.id + "/saml/keys";
  392. } else if (callingContext == 'oidc') {
  393. var uploadUrl = authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/certificates/' + attribute + '/upload-certificate';
  394. var redirectLocation = "/realms/" + realm.realm + "/clients/" + client.id + "/oidc/keys";
  395. }
  396. $scope.files = [];
  397. $scope.onFileSelect = function($files) {
  398. $scope.files = $files;
  399. };
  400. $scope.cancel = function() {
  401. $location.url(redirectLocation);
  402. }
  403. $scope.keyFormats = [
  404. "JKS",
  405. "PKCS12",
  406. "Certificate PEM"
  407. ];
  408. if (callingContext == 'oidc') {
  409. $scope.keyFormats.push('Public Key PEM');
  410. $scope.keyFormats.push('JSON Web Key Set');
  411. }
  412. $scope.hideKeystoreSettings = function() {
  413. return $scope.uploadKeyFormat == 'Certificate PEM' || $scope.uploadKeyFormat == 'Public Key PEM' || $scope.uploadKeyFormat == 'JSON Web Key Set';
  414. }
  415. $scope.uploadKeyFormat = $scope.keyFormats[0];
  416. $scope.uploadFile = function() {
  417. //$files: an array of files selected, each file has name, size, and type.
  418. for (var i = 0; i < $scope.files.length; i++) {
  419. var $file = $scope.files[i];
  420. $scope.upload = $upload.upload({
  421. url: uploadUrl,
  422. // method: POST or PUT,
  423. // headers: {'headerKey': 'headerValue'}, withCredential: true,
  424. data: {keystoreFormat: $scope.uploadKeyFormat,
  425. keyAlias: $scope.uploadKeyAlias,
  426. keyPassword: $scope.uploadKeyPassword,
  427. storePassword: $scope.uploadStorePassword
  428. },
  429. file: $file
  430. /* set file formData name for 'Content-Desposition' header. Default: 'file' */
  431. //fileFormDataName: myFile,
  432. /* customize how data is added to formData. See #40#issuecomment-28612000 for example */
  433. //formDataAppender: function(formData, key, val){}
  434. }).then(function(data, status, headers) {
  435. Notifications.success("Keystore uploaded successfully.");
  436. $location.url(redirectLocation);
  437. })
  438. //.then(success, error, progress);
  439. }
  440. };
  441. $scope.$watch(function() {
  442. return $location.path();
  443. }, function() {
  444. $scope.path = $location.path().substring(1).split("/");
  445. });
  446. });
  447. module.controller('ClientCertificateExportCtrl', function($scope, $location, $http, $upload, realm, client, callingContext, $routeParams,
  448. ClientCertificate, ClientCertificateGenerate,
  449. ClientCertificateDownload, Notifications) {
  450. var keyType = $routeParams.keyType;
  451. var attribute = $routeParams.attribute;
  452. $scope.realm = realm;
  453. $scope.client = client;
  454. $scope.keyType = keyType;
  455. if (callingContext == 'saml') {
  456. var downloadUrl = authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/certificates/' + attribute + '/download';
  457. var realmCertificate = true;
  458. } else if (callingContext == 'oidc') {
  459. var downloadUrl = authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/certificates/' + attribute + '/generate-and-download'
  460. var realmCertificate = false;
  461. }
  462. var jks = {
  463. keyAlias: client.clientId,
  464. realmAlias: realm.realm,
  465. realmCertificate: realmCertificate
  466. };
  467. $scope.keyFormats = [
  468. "JKS",
  469. "PKCS12"
  470. ];
  471. var keyInfo = ClientCertificate.get({ realm : realm.realm, client : client.id, attribute: attribute },
  472. function() {
  473. $scope.keyInfo = keyInfo;
  474. }
  475. );
  476. $scope.jks = jks;
  477. $scope.jks.format = $scope.keyFormats[0];
  478. $scope.download = function() {
  479. $http({
  480. url: downloadUrl,
  481. method: 'POST',
  482. responseType: 'arraybuffer',
  483. data: $scope.jks,
  484. headers: {
  485. 'Content-Type': 'application/json',
  486. 'Accept': 'application/octet-stream'
  487. }
  488. }).then(function(response){
  489. var blob = new Blob([response.data], {
  490. type: 'application/octet-stream'
  491. });
  492. var ext = ".jks";
  493. if ($scope.jks.format == 'PKCS12') ext = ".p12";
  494. if (callingContext == 'oidc') {
  495. $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/oidc/keys");
  496. Notifications.success("New keypair and certificate generated successfully. Download keystore file")
  497. }
  498. saveAs(blob, 'keystore' + ext);
  499. }).catch(function(response) {
  500. var errorMsg = 'Error downloading';
  501. try {
  502. var error = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(response.data)));
  503. errorMsg = error['error_description'] ? error['error_description'] : errorMsg;
  504. } catch (err) {
  505. }
  506. Notifications.error(errorMsg);
  507. });
  508. }
  509. $scope.$watch(function() {
  510. return $location.path();
  511. }, function() {
  512. $scope.path = $location.path().substring(1).split("/");
  513. });
  514. $scope.cancel = function() {
  515. $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/oidc/keys");
  516. }
  517. });
  518. module.controller('ClientOidcKeyCtrl', function($scope, $location, realm, client, Client, ClientCertificate, Notifications, $route) {
  519. $scope.realm = realm;
  520. $scope.client = angular.copy(client);
  521. var signingKeyInfo = ClientCertificate.get({ realm : realm.realm, client : client.id, attribute: 'jwt.credential' },
  522. function() {
  523. $scope.signingKeyInfo = signingKeyInfo;
  524. }
  525. );
  526. $scope.changed = false;
  527. $scope.$watch('client', function() {
  528. if (!angular.equals($scope.client, client)) {
  529. $scope.changed = true;
  530. }
  531. }, true);
  532. if ($scope.client.attributes["use.jwks.url"]) {
  533. if ($scope.client.attributes["use.jwks.url"] == "true") {
  534. $scope.useJwksUrl = true;
  535. } else {
  536. $scope.useJwksUrl = false;
  537. }
  538. }
  539. if ($scope.client.attributes["use.jwks.string"]) {
  540. if ($scope.client.attributes["use.jwks.string"] == "true") {
  541. $scope.useJwksString = true;
  542. } else {
  543. $scope.useJwksString = false;
  544. }
  545. }
  546. $scope.jwksUrlSwitchChange = function() {
  547. $scope.changed = true;
  548. if ($scope.useJwksUrl == false) {
  549. $scope.useJwksString = false;
  550. }
  551. }
  552. $scope.jwksStringSwitchChange = function() {
  553. $scope.changed = true;
  554. if ($scope.useJwksString == false) {
  555. $scope.useJwksUrl = false;
  556. }
  557. }
  558. $scope.save = function() {
  559. if ($scope.useJwksUrl == true) {
  560. $scope.client.attributes["use.jwks.url"] = "true";
  561. } else {
  562. $scope.client.attributes["use.jwks.url"] = "false";
  563. }
  564. if ($scope.useJwksString == true) {
  565. $scope.client.attributes["use.jwks.string"] = "true";
  566. } else {
  567. $scope.client.attributes["use.jwks.string"] = "false";
  568. }
  569. Client.update({
  570. realm : realm.realm,
  571. client : client.id
  572. }, $scope.client, function() {
  573. $scope.changed = false;
  574. client = angular.copy($scope.client);
  575. Notifications.success("OIDC key has been saved to the client.");
  576. });
  577. };
  578. $scope.importCertificate = function() {
  579. $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/oidc/Signing/import/jwt.credential");
  580. };
  581. $scope.generateSigningKey = function() {
  582. $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/oidc/Signing/export/jwt.credential");
  583. };
  584. $scope.reset = function() {
  585. $route.reload();
  586. };
  587. });
  588. module.controller('ClientSessionsCtrl', function($scope, realm, sessionCount, client,
  589. ClientUserSessions) {
  590. $scope.realm = realm;
  591. $scope.count = sessionCount.count;
  592. $scope.sessions = [];
  593. $scope.client = client;
  594. $scope.page = 0;
  595. $scope.query = {
  596. realm : realm.realm,
  597. client: $scope.client.id,
  598. max : 5,
  599. first : 0
  600. }
  601. $scope.firstPage = function() {
  602. $scope.query.first = 0;
  603. if ($scope.query.first < 0) {
  604. $scope.query.first = 0;
  605. }
  606. $scope.loadUsers();
  607. }
  608. $scope.previousPage = function() {
  609. $scope.query.first -= parseInt($scope.query.max);
  610. if ($scope.query.first < 0) {
  611. $scope.query.first = 0;
  612. }
  613. $scope.loadUsers();
  614. }
  615. $scope.nextPage = function() {
  616. $scope.query.first += parseInt($scope.query.max);
  617. $scope.loadUsers();
  618. }
  619. $scope.toDate = function(val) {
  620. return new Date(val);
  621. };
  622. $scope.loadUsers = function() {
  623. ClientUserSessions.query($scope.query, function(updated) {
  624. $scope.sessions = updated;
  625. })
  626. };
  627. });
  628. module.controller('ClientOfflineSessionsCtrl', function($scope, realm, offlineSessionCount, client,
  629. ClientOfflineSessions) {
  630. $scope.realm = realm;
  631. $scope.count = offlineSessionCount.count;
  632. $scope.sessions = [];
  633. $scope.client = client;
  634. $scope.page = 0;
  635. $scope.query = {
  636. realm : realm.realm,
  637. client: $scope.client.id,
  638. max : 5,
  639. first : 0
  640. }
  641. $scope.firstPage = function() {
  642. $scope.query.first = 0;
  643. if ($scope.query.first < 0) {
  644. $scope.query.first = 0;
  645. }
  646. $scope.loadUsers();
  647. }
  648. $scope.previousPage = function() {
  649. $scope.query.first -= parseInt($scope.query.max);
  650. if ($scope.query.first < 0) {
  651. $scope.query.first = 0;
  652. }
  653. $scope.loadUsers();
  654. }
  655. $scope.nextPage = function() {
  656. $scope.query.first += parseInt($scope.query.max);
  657. $scope.loadUsers();
  658. }
  659. $scope.toDate = function(val) {
  660. return new Date(val);
  661. };
  662. $scope.loadUsers = function() {
  663. ClientOfflineSessions.query($scope.query, function(updated) {
  664. $scope.sessions = updated;
  665. })
  666. };
  667. });
  668. module.controller('ClientRoleDetailCtrl', function($scope, $route, realm, client, role, roles, Client,
  669. Role, ClientRole, RoleById, RoleRealmComposites, RoleClientComposites,
  670. $http, $location, Dialog, Notifications, ComponentUtils) {
  671. $scope.realm = realm;
  672. $scope.client = client;
  673. $scope.role = angular.copy(role);
  674. $scope.create = !role.name;
  675. $scope.changed = $scope.create;
  676. $scope.save = function() {
  677. convertAttributeValuesToLists();
  678. if ($scope.create) {
  679. ClientRole.save({
  680. realm: realm.realm,
  681. client : client.id
  682. }, $scope.role, function (data, headers) {
  683. $scope.changed = false;
  684. convertAttributeValuesToString($scope.role);
  685. role = angular.copy($scope.role);
  686. ClientRole.get({ realm: realm.realm, client : client.id, role: role.name }, function(role) {
  687. var id = role.id;
  688. $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/roles/" + id);
  689. Notifications.success("The role has been created.");
  690. });
  691. });
  692. } else {
  693. $scope.update();
  694. }
  695. };
  696. $scope.remove = function() {
  697. Dialog.confirmDelete($scope.role.name, 'role', function() {
  698. $scope.role.$remove({
  699. realm : realm.realm,
  700. client : client.id,
  701. role : $scope.role.id
  702. }, function() {
  703. $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/roles");
  704. Notifications.success("The role has been deleted.");
  705. });
  706. });
  707. };
  708. $scope.cancel = function () {
  709. $location.url("/realms/" + realm.realm + "/clients/" + client.id + "/roles");
  710. };
  711. $scope.addAttribute = function() {
  712. $scope.role.attributes[$scope.newAttribute.key] = $scope.newAttribute.value;
  713. delete $scope.newAttribute;
  714. }
  715. $scope.removeAttribute = function(key) {
  716. delete $scope.role.attributes[key];
  717. }
  718. function convertAttributeValuesToLists() {
  719. var attrs = $scope.role.attributes;
  720. for (var attribute in attrs) {
  721. if (typeof attrs[attribute] === "string") {
  722. var attrVals = attrs[attribute].split("##");
  723. attrs[attribute] = attrVals;
  724. }
  725. }
  726. }
  727. function convertAttributeValuesToString(role) {
  728. var attrs = role.attributes;
  729. for (var attribute in attrs) {
  730. if (typeof attrs[attribute] === "object") {
  731. var attrVals = attrs[attribute].join("##");
  732. attrs[attribute] = attrVals;
  733. }
  734. }
  735. }
  736. roleControl($scope, $route, realm, role, roles, Client,
  737. ClientRole, RoleById, RoleRealmComposites, RoleClientComposites,
  738. $http, $location, Notifications, Dialog, ComponentUtils);
  739. });
  740. module.controller('ClientRoleMembersCtrl', function($scope, realm, client, role, ClientRoleMembership, Dialog, Notifications, $location) {
  741. $scope.realm = realm;
  742. $scope.page = 0;
  743. $scope.role = role;
  744. $scope.client = client;
  745. $scope.query = {
  746. realm: realm.realm,
  747. role: role.name,
  748. client: client.id,
  749. max : 5,
  750. first : 0
  751. }
  752. $scope.firstPage = function() {
  753. $scope.query.first = 0;
  754. $scope.searchQuery();
  755. }
  756. $scope.previousPage = function() {
  757. $scope.query.first -= parseInt($scope.query.max);
  758. if ($scope.query.first < 0) {
  759. $scope.query.first = 0;
  760. }
  761. $scope.searchQuery();
  762. }
  763. $scope.nextPage = function() {
  764. $scope.query.first += parseInt($scope.query.max);
  765. $scope.searchQuery();
  766. }
  767. $scope.searchQuery = function() {
  768. $scope.searchLoaded = false;
  769. $scope.users = ClientRoleMembership.query($scope.query, function() {
  770. console.log('search loaded');
  771. $scope.searchLoaded = true;
  772. $scope.lastSearch = $scope.query.search;
  773. });
  774. };
  775. $scope.searchQuery();
  776. });
  777. module.controller('ClientImportCtrl', function($scope, $location, $upload, realm, serverInfo, Notifications) {
  778. $scope.realm = realm;
  779. $scope.files = [];
  780. $scope.onFileSelect = function($files) {
  781. $scope.files = $files;
  782. };
  783. $scope.clearFileSelect = function() {
  784. $scope.files = null;
  785. }
  786. $scope.uploadFile = function() {
  787. //$files: an array of files selected, each file has name, size, and type.
  788. for (var i = 0; i < $scope.files.length; i++) {
  789. var $file = $scope.files[i];
  790. $scope.upload = $upload.upload({
  791. url: authUrl + '/admin/realms/' + realm.realm + '/client-importers/' + $scope.configFormat.id + '/upload',
  792. // method: POST or PUT,
  793. // headers: {'headerKey': 'headerValue'}, withCredential: true,
  794. data: {myObj: ""},
  795. file: $file
  796. /* set file formData name for 'Content-Desposition' header. Default: 'file' */
  797. //fileFormDataName: myFile,
  798. /* customize how data is added to formData. See #40#issuecomment-28612000 for example */
  799. //formDataAppender: function(formData, key, val){}
  800. }).success(function(data, status, headers) {
  801. Notifications.success("Uploaded successfully.");
  802. $location.url("/realms/" + realm.realm + "/clients");
  803. })
  804. .error(function() {
  805. Notifications.error("The file can not be uploaded. Please verify the file.");
  806. });
  807. //.then(success, error, progress);
  808. }
  809. };
  810. $scope.$watch(function() {
  811. return $location.path();
  812. }, function() {
  813. $scope.path = $location.path().substring(1).split("/");
  814. });
  815. });
  816. module.controller('ClientListCtrl', function($scope, realm, Client, ClientListSearchState, $route, Dialog, Notifications) {
  817. $scope.init = function() {
  818. $scope.realm = realm;
  819. $scope.searchLoaded = true;
  820. ClientListSearchState.query.realm = realm.realm;
  821. $scope.query = ClientListSearchState.query;
  822. if (!ClientListSearchState.isFirstSearch) {
  823. $scope.searchQuery();
  824. } else {
  825. $scope.query.clientId = null;
  826. $scope.firstPage();
  827. }
  828. };
  829. $scope.searchQuery = function() {
  830. console.log("query.search: ", $scope.query);
  831. $scope.searchLoaded = false;
  832. $scope.clients = Client.query($scope.query, function() {
  833. $scope.searchLoaded = true;
  834. $scope.lastSearch = $scope.query.search;
  835. ClientListSearchState.isFirstSearch = false;
  836. });
  837. };
  838. $scope.firstPage = function() {
  839. $scope.query.first = 0;
  840. $scope.searchQuery();
  841. }
  842. $scope.previousPage = function() {
  843. $scope.query.first -= parseInt($scope.query.max);
  844. if ($scope.query.first < 0) {
  845. $scope.query.first = 0;
  846. }
  847. $scope.searchQuery();
  848. }
  849. $scope.nextPage = function() {
  850. $scope.query.first += parseInt($scope.query.max);
  851. $scope.searchQuery();
  852. }
  853. $scope.removeClient = function(client) {
  854. Dialog.confirmDelete(client.clientId, 'client', function() {
  855. Client.remove({
  856. realm : realm.realm,
  857. client : client.id
  858. }, function() {
  859. $route.reload();
  860. Notifications.success("The client has been deleted.");
  861. });
  862. });
  863. };
  864. $scope.exportClient = function(client) {
  865. var clientCopy = angular.copy(client);
  866. delete clientCopy.id;
  867. if (clientCopy.protocolMappers) {
  868. for (var i = 0; i < clientCopy.protocolMappers.length; i++) {
  869. delete clientCopy.protocolMappers[i].id;
  870. }
  871. }
  872. saveAs(new Blob([angular.toJson(clientCopy, 4)], { type: 'application/json' }), clientCopy.clientId + '.json');
  873. }
  874. });
  875. module.controller('ClientInstallationCtrl', function($scope, realm, client, serverInfo, ClientInstallation,$http, $routeParams) {
  876. $scope.realm = realm;
  877. $scope.client = client;
  878. $scope.installation = null;
  879. $scope.download = null;
  880. $scope.configFormat = null;
  881. $scope.filename = null;
  882. var protocol = client.protocol;
  883. if (!protocol) protocol = 'openid-connect';
  884. $scope.configFormats = serverInfo.clientInstallations[protocol];
  885. console.log('configFormats.length: ' + $scope.configFormats.length);
  886. $scope.changeFormat = function() {
  887. var url = ClientInstallation.url({ realm: $routeParams.realm, client: $routeParams.client, provider: $scope.configFormat.id });
  888. if ($scope.configFormat.mediaType == 'application/zip') {
  889. $http({
  890. url: url,
  891. method: 'GET',
  892. responseType: 'arraybuffer',
  893. cache: false
  894. }).then(function(response) {
  895. var installation = response.data;
  896. $scope.installation = installation;
  897. }
  898. );
  899. } else {
  900. $http.get(url).then(function (response) {
  901. var installation = response.data;
  902. if ($scope.configFormat.mediaType == 'application/json') {
  903. installation = angular.fromJson(response.data);
  904. installation = angular.toJson(installation, true);
  905. }
  906. $scope.installation = installation;
  907. });
  908. }
  909. };
  910. $scope.download = function() {
  911. saveAs(new Blob([$scope.installation], { type: $scope.configFormat.mediaType }), $scope.configFormat.filename);
  912. }
  913. });
  914. module.controller('ClientDetailCtrl', function($scope, realm, client, flows, $route, serverInfo, Client, ClientDescriptionConverter, Components, ClientStorageOperations, $location, $modal, Dialog, Notifications, TimeUnit2) {
  915. $scope.serverInfo = serverInfo;
  916. $scope.flows = [];
  917. $scope.clientFlows = [];
  918. var emptyFlow = {
  919. id: "",
  920. alias: ""
  921. }
  922. for (var i=0 ; i<flows.length ; i++) {
  923. if (flows[i].providerId == 'client-flow') {
  924. $scope.clientFlows.push(flows[i]);
  925. } else {
  926. $scope.flows.push(flows[i]);
  927. }
  928. }
  929. $scope.flows.push(emptyFlow)
  930. $scope.clientFlows.push(emptyFlow)
  931. $scope.accessTypes = [
  932. "confidential",
  933. "public",
  934. "bearer-only"
  935. ];
  936. $scope.protocols = serverInfo.listProviderIds('login-protocol');
  937. $scope.signatureAlgorithms = [
  938. "RSA_SHA1",
  939. "RSA_SHA256",
  940. "RSA_SHA256_MGF1",
  941. "RSA_SHA512",
  942. "RSA_SHA512_MGF1",
  943. "DSA_SHA1"
  944. ];
  945. $scope.nameIdFormats = [
  946. "username",
  947. "email",
  948. "transient",
  949. "persistent"
  950. ];
  951. $scope.xmlKeyNameTranformers = [
  952. "NONE",
  953. "KEY_ID",
  954. "CERT_SUBJECT"
  955. ];
  956. $scope.canonicalization = [
  957. {name: "EXCLUSIVE", value: "http://www.w3.org/2001/10/xml-exc-c14n#" },
  958. {name: "EXCLUSIVE_WITH_COMMENTS", value: "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"},
  959. {name: "INCLUSIVE", value: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" },
  960. {name: "INCLUSIVE_WITH_COMMENTS", value: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"}
  961. ];
  962. $scope.requestObjectRequiredOptions = [
  963. "not required",
  964. "request or request_uri",
  965. "request only",
  966. "request_uri only"
  967. ];
  968. $scope.changePkceCodeChallengeMethodOptions = [
  969. "S256",
  970. "plain",
  971. ""
  972. ];
  973. $scope.realm = realm;
  974. $scope.samlAuthnStatement = false;
  975. $scope.samlOneTimeUseCondition = false;
  976. $scope.samlMultiValuedRoles = false;
  977. $scope.samlArtifactBinding = false;
  978. $scope.samlServerSignature = false;
  979. $scope.samlServerSignatureEnableKeyInfoExtension = false;
  980. $scope.samlAssertionSignature = false;
  981. $scope.samlClientSignature = false;
  982. $scope.samlEncrypt = false;
  983. $scope.samlForcePostBinding = false;
  984. $scope.samlForceNameIdFormat = false;
  985. $scope.samlXmlKeyNameTranformer = $scope.xmlKeyNameTranformers[1];
  986. $scope.disableAuthorizationTab = !client.authorizationServicesEnabled;
  987. $scope.disableServiceAccountRolesTab = !client.serviceAccountsEnabled;
  988. $scope.disableCredentialsTab = client.publicClient;
  989. $scope.oauth2DeviceAuthorizationGrantEnabled = false;
  990. $scope.oidcCibaGrantEnabled = false;
  991. // KEYCLOAK-6771 Certificate Bound Token
  992. // https://tools.ietf.org/html/draft-ietf-oauth-mtls-08#section-3
  993. $scope.tlsClientCertificateBoundAccessTokens = false;
  994. $scope.useRefreshTokens = true;
  995. $scope.useIdTokenAsDetachedSignature = false;
  996. $scope.accessTokenLifespan = TimeUnit2.asUnit(client.attributes['access.token.lifespan']);
  997. $scope.samlAssertionLifespan = TimeUnit2.asUnit(client.attributes['saml.assertion.lifespan']);
  998. $scope.clientSessionIdleTimeout = TimeUnit2.asUnit(client.attributes['client.session.idle.timeout']);
  999. $scope.clientSessionMaxLifespan = TimeUnit2.asUnit(client.attributes['client.session.max.lifespan']);
  1000. $scope.clientOfflineSessionIdleTimeout = TimeUnit2.asUnit(client.attributes['client.offline.session.idle.timeout']);
  1001. $scope.clientOfflineSessionMaxLifespan = TimeUnit2.asUnit(client.attributes['client.offline.session.max.lifespan']);
  1002. $scope.oauth2DeviceCodeLifespan = TimeUnit2.asUnit(client.attributes['oauth2.device.code.lifespan']);
  1003. $scope.oauth2DevicePollingInterval = parseInt(client.attributes['oauth2.device.polling.interval']);
  1004. // PAR request.
  1005. $scope.requirePushedAuthorizationRequests = false;
  1006. if(client.origin) {
  1007. if ($scope.access.viewRealm) {
  1008. Components.get({realm: realm.realm, componentId: client.origin}, function (link) {
  1009. $scope.originName = link.name;
  1010. //$scope.originLink = "#/realms/" + realm.realm + "/user-storage/providers/" + link.providerId + "/" + link.id;
  1011. })
  1012. }
  1013. else {
  1014. // KEYCLOAK-4328
  1015. ClientStorageOperations.simpleName.get({realm: realm.realm, componentId: client.origin}, function (link) {
  1016. $scope.originName = link.name;
  1017. //$scope.originLink = $location.absUrl();
  1018. })
  1019. }
  1020. } else {
  1021. console.log("origin is null");
  1022. }
  1023. function updateProperties() {
  1024. if (!$scope.client.attributes) {
  1025. $scope.client.attributes = {};
  1026. }
  1027. $scope.accessType = $scope.accessTypes[0];
  1028. if ($scope.client.bearerOnly) {
  1029. $scope.accessType = $scope.accessTypes[2];
  1030. } else if ($scope.client.publicClient) {
  1031. $scope.accessType = $scope.accessTypes[1];
  1032. }
  1033. if ($scope.client.protocol) {
  1034. $scope.protocol = $scope.protocols[$scope.protocols.indexOf($scope.client.protocol)];
  1035. } else {
  1036. $scope.protocol = $scope.protocols[0];
  1037. }
  1038. if ($scope.client.attributes['saml.signature.algorithm'] == 'RSA_SHA1') {
  1039. $scope.signatureAlgorithm = $scope.signatureAlgorithms[0];
  1040. } else if ($scope.client.attributes['saml.signature.algorithm'] == 'RSA_SHA256') {
  1041. $scope.signatureAlgorithm = $scope.signatureAlgorithms[1];
  1042. } else if ($scope.client.attributes['saml.signature.algorithm'] == 'RSA_SHA256_MGF1') {
  1043. $scope.signatureAlgorithm = $scope.signatureAlgorithms[2];
  1044. } else if ($scope.client.attributes['saml.signature.algorithm'] == 'RSA_SHA512') {
  1045. $scope.signatureAlgorithm = $scope.signatureAlgorithms[3];
  1046. } else if ($scope.client.attributes['saml.signature.algorithm'] == 'RSA_SHA512_MGF1') {
  1047. $scope.signatureAlgorithm = $scope.signatureAlgorithms[4];
  1048. } else if ($scope.client.attributes['saml.signature.algorithm'] == 'DSA_SHA1') {
  1049. $scope.signatureAlgorithm = $scope.signatureAlgorithms[5];
  1050. }
  1051. if ($scope.client.attributes['saml_name_id_format'] == 'username') {
  1052. $scope.nameIdFormat = $scope.nameIdFormats[0];
  1053. } else if ($scope.client.attributes['saml_name_id_format'] == 'email') {
  1054. $scope.nameIdFormat = $scope.nameIdFormats[1];
  1055. } else if ($scope.client.attributes['saml_name_id_format'] == 'transient') {
  1056. $scope.nameIdFormat = $scope.nameIdFormats[2];
  1057. } else if ($scope.client.attributes['saml_name_id_format'] == 'persistent') {
  1058. $scope.nameIdFormat = $scope.nameIdFormats[3];
  1059. }
  1060. if ($scope.client.attributes["saml.artifact.binding"]) {
  1061. if ($scope.client.attributes["saml.artifact.binding"] == "true") {
  1062. $scope.samlArtifactBinding = true;
  1063. } else {
  1064. $scope.samlArtifactBinding = false;
  1065. }
  1066. }
  1067. if ($scope.client.attributes["saml.server.signature"]) {
  1068. if ($scope.client.attributes["saml.server.signature"] == "true") {
  1069. $scope.samlServerSignature = true;
  1070. } else {
  1071. $scope.samlServerSignature = false;
  1072. }
  1073. }
  1074. if ($scope.client.attributes["saml.server.signature.keyinfo.ext"]) {
  1075. if ($scope.client.attributes["saml.server.signature.keyinfo.ext"] == "true") {
  1076. $scope.samlServerSignatureEnableKeyInfoExtension = true;
  1077. } else {
  1078. $scope.samlServerSignatureEnableKeyInfoExtension = false;
  1079. }
  1080. }
  1081. if ($scope.client.attributes['saml.server.signature.keyinfo.xmlSigKeyInfoKeyNameTransformer'] === 'NONE') {
  1082. $scope.samlXmlKeyNameTranformer = $scope.xmlKeyNameTranformers[0];
  1083. } else if ($scope.client.attributes['saml.server.signature.keyinfo.xmlSigKeyInfoKeyNameTransformer'] === 'KEY_ID') {
  1084. $scope.samlXmlKeyNameTranformer = $scope.xmlKeyNameTranformers[1];
  1085. } else if ($scope.client.attributes['saml.server.signature.keyinfo.xmlSigKeyInfoKeyNameTransformer'] === 'CERT_SUBJECT') {
  1086. $scope.samlXmlKeyNameTranformer = $scope.xmlKeyNameTranformers[2];
  1087. }
  1088. if ($scope.client.attributes["saml.assertion.signature"]) {
  1089. if ($scope.client.attributes["saml.assertion.signature"] == "true") {
  1090. $scope.samlAssertionSignature = true;
  1091. } else {
  1092. $scope.samlAssertionSignature = false;
  1093. }
  1094. }
  1095. if ($scope.client.attributes["saml.client.signature"]) {
  1096. if ($scope.client.attributes["saml.client.signature"] == "true") {
  1097. $scope.samlClientSignature = true;
  1098. } else {
  1099. $scope.samlClientSignature = false;
  1100. }
  1101. }
  1102. if ($scope.client.attributes["saml.encrypt"]) {
  1103. if ($scope.client.attributes["saml.encrypt"] == "true") {
  1104. $scope.samlEncrypt = true;
  1105. } else {
  1106. $scope.samlEncrypt = false;
  1107. }
  1108. }
  1109. if ($scope.client.attributes["saml.authnstatement"]) {
  1110. if ($scope.client.attributes["saml.authnstatement"] == "true") {
  1111. $scope.samlAuthnStatement = true;
  1112. } else {
  1113. $scope.samlAuthnStatement = false;
  1114. }
  1115. }
  1116. if ($scope.client.attributes["saml.onetimeuse.condition"]) {
  1117. if ($scope.client.attributes["saml.onetimeuse.condition"] == "true") {
  1118. $scope.samlOneTimeUseCondition = true;
  1119. } else {
  1120. $scope.samlOneTimeUseCondition = false;
  1121. }
  1122. }
  1123. if ($scope.client.attributes["saml_force_name_id_format"]) {
  1124. if ($scope.client.attributes["saml_force_name_id_format"] == "true") {
  1125. $scope.samlForceNameIdFormat = true;
  1126. } else {
  1127. $scope.samlForceNameIdFormat = false;
  1128. }
  1129. }
  1130. if ($scope.client.attributes["saml.multivalued.roles"]) {
  1131. if ($scope.client.attributes["saml.multivalued.roles"] == "true") {
  1132. $scope.samlMultiValuedRoles = true;
  1133. } else {
  1134. $scope.samlMultiValuedRoles = false;
  1135. }
  1136. }
  1137. if ($scope.client.attributes["saml.force.post.binding"]) {
  1138. if ($scope.client.attributes["saml.force.post.binding"] == "true") {
  1139. $scope.samlForcePostBinding = true;
  1140. } else {
  1141. $scope.samlForcePostBinding = false;
  1142. }
  1143. }
  1144. $scope.accessTokenSignedResponseAlg = $scope.client.attributes['access.token.signed.response.alg'];
  1145. $scope.idTokenSignedResponseAlg = $scope.client.attributes['id.token.signed.response.alg'];
  1146. $scope.idTokenEncryptedResponseAlg = $scope.client.attributes['id.token.encrypted.response.alg'];
  1147. $scope.idTokenEncryptedResponseEnc = $scope.client.attributes['id.token.encrypted.response.enc'];
  1148. $scope.authorizationSignedResponseAlg = $scope.client.attributes['authorization.signed.response.alg'];
  1149. $scope.authorizationEncryptedResponseAlg = $scope.client.attributes['authorization.encrypted.response.alg'];
  1150. $scope.authorizationEncryptedResponseEnc = $scope.client.attributes['authorization.encrypted.response.enc'];
  1151. var attrVal1 = $scope.client.attributes['user.info.response.signature.alg'];
  1152. $scope.userInfoSignedResponseAlg = attrVal1==null ? 'unsigned' : attrVal1;
  1153. var attrVal2 = $scope.client.attributes['request.object.signature.alg'];
  1154. $scope.requestObjectSignatureAlg = attrVal2==null ? 'any' : attrVal2;
  1155. var attrVal3 = $scope.client.attributes['request.object.required'];
  1156. $scope.requestObjectRequired = attrVal3==null ? 'not required' : attrVal3;
  1157. var attrVal4 = $scope.client.attributes['pkce.code.challenge.method'];
  1158. $scope.pkceCodeChallengeMethod = attrVal4==null ? 'none' : attrVal4;
  1159. var attrVal5 = $scope.client.attributes['ciba.backchannel.auth.request.signing.alg'];
  1160. $scope.cibaBackchannelAuthRequestSigningAlg = attrVal5==null ? 'none' : attrVal5;
  1161. var attrVal6 = $scope.client.attributes['request.object.encryption.alg'];
  1162. $scope.requestObjectEncryptionAlg = attrVal6==null ? 'any' : attrVal6;
  1163. var attrVal7 = $scope.client.attributes['request.object.encryption.enc'];
  1164. $scope.requestObjectEncryptionEnc = attrVal7==null ? 'any' : attrVal7;
  1165. var attrVal8 = $scope.client.attributes['ciba.backchannel.auth.request.signing.alg'];
  1166. $scope.cibaBackchannelAuthRequestSigningAlg = attrVal8==null ? 'any' : attrVal8;
  1167. if ($scope.client.attributes["exclude.session.state.from.auth.response"]) {
  1168. if ($scope.client.attributes["exclude.session.state.from.auth.response"] == "true") {
  1169. $scope.excludeSessionStateFromAuthResponse = true;
  1170. } else {
  1171. $scope.excludeSessionStateFromAuthResponse = false;
  1172. }
  1173. }
  1174. if ($scope.client.attributes["oauth2.device.authorization.grant.enabled"]) {
  1175. if ($scope.client.attributes["oauth2.device.authorization.grant.enabled"] == "true") {
  1176. $scope.oauth2DeviceAuthorizationGrantEnabled = true;
  1177. } else {
  1178. $scope.oauth2DeviceAuthorizationGrantEnabled = false;
  1179. }
  1180. }
  1181. if ($scope.client.attributes["oidc.ciba.grant.enabled"]) {
  1182. if ($scope.client.attributes["oidc.ciba.grant.enabled"] == "true") {
  1183. $scope.oidcCibaGrantEnabled = true;
  1184. } else {
  1185. $scope.oidcCibaGrantEnabled = false;
  1186. }
  1187. }
  1188. $scope.cibaBackchannelTokenDeliveryMode = $scope.client.attributes['ciba.backchannel.token.delivery.mode'];
  1189. if ($scope.client.attributes["use.refresh.tokens"]) {
  1190. if ($scope.client.attributes["use.refresh.tokens"] == "true") {
  1191. $scope.useRefreshTokens = true;
  1192. } else {
  1193. $scope.useRefreshTokens = false;
  1194. }
  1195. }
  1196. if ($scope.client.attributes["id.token.as.detached.signature"]) {
  1197. if ($scope.client.attributes["id.token.as.detached.signature"] == "true") {
  1198. $scope.useIdTokenAsDetachedSignature = true;
  1199. } else {
  1200. $scope.useIdTokenAsDetachedSignature = false;
  1201. }
  1202. }
  1203. // KEYCLOAK-6771 Certificate Bound Token
  1204. // https://tools.ietf.org/html/draft-ietf-oauth-mtls-08#section-3
  1205. if ($scope.client.attributes["tls.client.certificate.bound.access.tokens"]) {
  1206. if ($scope.client.attributes["tls.client.certificate.bound.access.tokens"] == "true") {
  1207. $scope.tlsClientCertificateBoundAccessTokens = true;
  1208. } else {
  1209. $scope.tlsClientCertificateBoundAccessTokens = false;
  1210. }
  1211. }
  1212. // PAR request.
  1213. if ($scope.client.attributes["require.pushed.authorization.requests"]) {
  1214. if ($scope.client.attributes["require.pushed.authorization.requests"] == "true") {
  1215. $scope.requirePushedAuthorizationRequests = true;
  1216. } else {
  1217. $scope.requirePushedAuthorizationRequests = false;
  1218. }
  1219. }
  1220. var useRefreshToken = $scope.client.attributes["client_credentials.use_refresh_token"];
  1221. if (useRefreshToken === "true") {
  1222. $scope.useRefreshTokenForClientCredentialsGrant = true;
  1223. } else {
  1224. $scope.useRefreshTokenForClientCredentialsGrant = false;
  1225. }
  1226. if ($scope.client.attributes["display.on.consent.screen"]) {
  1227. if ($scope.client.attributes["display.on.consent.screen"] == "true") {
  1228. $scope.displayOnConsentScreen = true;
  1229. } else {
  1230. $scope.displayOnConsentScreen = false;
  1231. }
  1232. }
  1233. if ($scope.client.attributes["backchannel.logout.session.required"]) {
  1234. if ($scope.client.attributes["backchannel.logout.session.required"] == "true") {
  1235. $scope.backchannelLogoutSessionRequired = true;
  1236. } else {
  1237. $scope.backchannelLogoutSessionRequired = false;
  1238. }
  1239. }
  1240. if ($scope.client.attributes["backchannel.logout.revoke.offline.tokens"]) {
  1241. if ($scope.client.attributes["backchannel.logout.revoke.offline.tokens"] == "true") {
  1242. $scope.backchannelLogoutRevokeOfflineSessions = true;
  1243. } else {
  1244. $scope.backchannelLogoutRevokeOfflineSessions = false;
  1245. }
  1246. }
  1247. if ($scope.client.attributes["request.uris"] && $scope.client.attributes["request.uris"].length > 0) {
  1248. $scope.client.requestUris = $scope.client.attributes["request.uris"].split("##");
  1249. } else {
  1250. $scope.client.requestUris = [];
  1251. }
  1252. }
  1253. if (!$scope.create) {
  1254. $scope.client = client;
  1255. updateProperties();
  1256. $scope.clientEdit = angular.copy(client);
  1257. }
  1258. $scope.samlIdpInitiatedUrl = function(ssoName) {
  1259. return encodeURI($location.absUrl().replace(/\/admin.*/, "/realms/") + realm.realm + "/protocol/saml/clients/") + encodeURIComponent(ssoName)
  1260. }
  1261. $scope.importFile = function(fileContent){
  1262. console.debug(fileContent);
  1263. ClientDescriptionConverter.save({
  1264. realm: realm.realm
  1265. }, fileContent, function (data) {
  1266. $scope.client = data;
  1267. updateProperties();
  1268. $scope.importing = true;
  1269. $scope.clientEdit = angular.copy(client);
  1270. });
  1271. };
  1272. $scope.viewImportDetails = function() {
  1273. $modal.open({
  1274. templateUrl: resourceUrl + '/partials/modal/view-object.html',
  1275. controller: 'ObjectModalCtrl',
  1276. resolve: {
  1277. object: function () {
  1278. return $scope.client;
  1279. }
  1280. }
  1281. })
  1282. };
  1283. $scope.switchChange = function() {
  1284. $scope.changed = true;
  1285. }
  1286. $scope.changeAccessType = function() {
  1287. if ($scope.accessType == "confidential") {
  1288. $scope.clientEdit.bearerOnly = false;
  1289. $scope.clientEdit.publicClient = false;
  1290. } else if ($scope.accessType == "public") {
  1291. $scope.clientEdit.bearerOnly = false;
  1292. $scope.clientEdit.publicClient = true;
  1293. } else if ($scope.accessType == "bearer-only") {
  1294. $scope.clientEdit.bearerOnly = true;
  1295. $scope.clientEdit.publicClient = false;
  1296. $scope.clientEdit.alwaysDisplayInConsole = false;
  1297. }
  1298. };
  1299. $scope.changeProtocol = function() {
  1300. if ($scope.protocol == "openid-connect") {
  1301. $scope.clientEdit.protocol = "openid-connect";
  1302. } else if ($scope.protocol == "saml") {
  1303. $scope.clientEdit.protocol = "saml";
  1304. }
  1305. };
  1306. $scope.changeAlgorithm = function() {
  1307. $scope.clientEdit.attributes['saml.signature.algorithm'] = $scope.signatureAlgorithm;
  1308. };
  1309. $scope.changeNameIdFormat = function() {
  1310. $scope.clientEdit.attributes['saml_name_id_format'] = $scope.nameIdFormat;
  1311. };
  1312. $scope.changeSamlSigKeyNameTranformer = function() {
  1313. $scope.clientEdit.attributes['saml.server.signature.keyinfo.xmlSigKeyInfoKeyNameTransformer'] = $scope.samlXmlKeyNameTranformer;
  1314. };
  1315. $scope.changeAccessTokenSignedResponseAlg = function() {
  1316. $scope.clientEdit.attributes['access.token.signed.response.alg'] = $scope.accessTokenSignedResponseAlg;
  1317. };
  1318. $scope.changeIdTokenSignedResponseAlg = function() {
  1319. $scope.clientEdit.attributes['id.token.signed.response.alg'] = $scope.idTokenSignedResponseAlg;
  1320. };
  1321. $scope.changeIdTokenEncryptedResponseAlg = function() {
  1322. $scope.clientEdit.attributes['id.token.encrypted.response.alg'] = $scope.idTokenEncryptedResponseAlg;
  1323. };
  1324. $scope.changeIdTokenEncryptedResponseEnc = function() {
  1325. $scope.clientEdit.attributes['id.token.encrypted.response.enc'] = $scope.idTokenEncryptedResponseEnc;
  1326. };
  1327. $scope.changeUserInfoSignedResponseAlg = function() {
  1328. if ($scope.userInfoSignedResponseAlg === 'unsigned') {
  1329. $scope.clientEdit.attributes['user.info.response.signature.alg'] = null;
  1330. } else {
  1331. $scope.clientEdit.attributes['user.info.response.signature.alg'] = $scope.userInfoSignedResponseAlg;
  1332. }
  1333. };
  1334. $scope.changeRequestObjectSignatureAlg = function() {
  1335. if ($scope.requestObjectSignatureAlg === 'any') {
  1336. $scope.clientEdit.attributes['request.object.signature.alg'] = null;
  1337. } else {
  1338. $scope.clientEdit.attributes['request.object.signature.alg'] = $scope.requestObjectSignatureAlg;
  1339. }
  1340. };
  1341. $scope.changeRequestObjectRequired = function() {
  1342. if ($scope.requestObjectRequired === 'not required') {
  1343. $scope.clientEdit.attributes['request.object.required'] = null;
  1344. } else {
  1345. $scope.clientEdit.attributes['request.object.required'] = $scope.requestObjectRequired;
  1346. }
  1347. };
  1348. $scope.changeRequestObjectEncryptionAlg = function() {
  1349. if ($scope.requestObjectEncryptionAlg === 'any') {
  1350. $scope.clientEdit.attributes['request.object.encryption.alg'] = null;
  1351. } else {
  1352. $scope.clientEdit.attributes['request.object.encryption.alg'] = $scope.requestObjectEncryptionAlg;
  1353. }
  1354. };
  1355. $scope.changeRequestObjectEncryptionEnc = function() {
  1356. if ($scope.requestObjectEncryptionEnc === 'any') {
  1357. $scope.clientEdit.attributes['request.object.encryption.enc'] = null;
  1358. } else {
  1359. $scope.clientEdit.attributes['request.object.encryption.enc'] = $scope.requestObjectEncryptionEnc;
  1360. }
  1361. };
  1362. $scope.changePkceCodeChallengeMethod = function() {
  1363. $scope.clientEdit.attributes['pkce.code.challenge.method'] = $scope.pkceCodeChallengeMethod;
  1364. };
  1365. $scope.changeCibaBackchannelAuthRequestSigningAlg = function() {
  1366. if ($scope.cibaBackchannelAuthRequestSigningAlg === 'any') {
  1367. $scope.clientEdit.attributes['ciba.backchannel.auth.request.signing.alg'] = null;
  1368. } else {
  1369. $scope.clientEdit.attributes['ciba.backchannel.auth.request.signing.alg'] = $scope.cibaBackchannelAuthRequestSigningAlg;
  1370. }
  1371. };
  1372. $scope.changeCibaBackchannelTokenDeliveryMode = function() {
  1373. $scope.clientEdit.attributes['ciba.backchannel.token.delivery.mode'] = $scope.cibaBackchannelTokenDeliveryMode;
  1374. };
  1375. $scope.changeAuthorizationSignedResponseAlg = function() {
  1376. $scope.clientEdit.attributes['authorization.signed.response.alg'] = $scope.authorizationSignedResponseAlg;
  1377. };
  1378. $scope.changeAuthorizationEncryptedResponseAlg = function() {
  1379. $scope.clientEdit.attributes['authorization.encrypted.response.alg'] = $scope.authorizationEncryptedResponseAlg;
  1380. };
  1381. $scope.changeAuthorizationEncryptedResponseEnc = function() {
  1382. $scope.clientEdit.attributes['authorization.encrypted.response.enc'] = $scope.authorizationEncryptedResponseEnc;
  1383. };
  1384. $scope.$watch(function() {
  1385. return $location.path();
  1386. }, function() {
  1387. $scope.path = $location.path().substring(1).split("/");
  1388. });
  1389. function isChanged() {
  1390. if (!angular.equals($scope.client, $scope.clientEdit)) {
  1391. return true;
  1392. }
  1393. if ($scope.newRedirectUri && $scope.newRedirectUri.length > 0) {
  1394. return true;
  1395. }
  1396. if ($scope.newWebOrigin && $scope.newWebOrigin.length > 0) {
  1397. return true;
  1398. }
  1399. if ($scope.newRequestUri && $scope.newRequestUri.length > 0) {
  1400. return true;
  1401. }
  1402. return false;
  1403. }
  1404. $scope.updateTimeouts = function() {
  1405. if ($scope.accessTokenLifespan.time) {
  1406. if ($scope.accessTokenLifespan.time === -1) {
  1407. $scope.clientEdit.attributes['access.token.lifespan'] = -1;
  1408. } else {
  1409. $scope.clientEdit.attributes['access.token.lifespan'] = $scope.accessTokenLifespan.toSeconds();
  1410. }
  1411. } else {
  1412. $scope.clientEdit.attributes['access.token.lifespan'] = null;
  1413. }
  1414. }
  1415. $scope.updateAssertionLifespan = function() {
  1416. if ($scope.samlAssertionLifespan.time) {
  1417. $scope.clientEdit.attributes['saml.assertion.lifespan'] = $scope.samlAssertionLifespan.toSeconds();
  1418. } else {
  1419. $scope.clientEdit.attributes['saml.assertion.lifespan'] = null;
  1420. }
  1421. }
  1422. $scope.updateClientSessionIdleTimeout = function() {
  1423. if ($scope.clientSessionIdleTimeout.time) {
  1424. $scope.clientEdit.attributes['client.session.idle.timeout'] = $scope.clientSessionIdleTimeout.toSeconds();
  1425. } else {
  1426. $scope.clientEdit.attributes['client.session.idle.timeout'] = null;
  1427. }
  1428. }
  1429. $scope.updateClientSessionMaxLifespan = function() {
  1430. if ($scope.clientSessionMaxLifespan.time) {
  1431. $scope.clientEdit.attributes['client.session.max.lifespan'] = $scope.clientSessionMaxLifespan.toSeconds();
  1432. } else {
  1433. $scope.clientEdit.attributes['client.session.max.lifespan'] = null;
  1434. }
  1435. }
  1436. $scope.updateClientOfflineSessionIdleTimeout = function() {
  1437. if ($scope.clientOfflineSessionIdleTimeout.time) {
  1438. $scope.clientEdit.attributes['client.offline.session.idle.timeout'] = $scope.clientOfflineSessionIdleTimeout.toSeconds();
  1439. } else {
  1440. $scope.clientEdit.attributes['client.offline.session.idle.timeout'] = null;
  1441. }
  1442. }
  1443. $scope.updateClientOfflineSessionMaxLifespan = function() {
  1444. if ($scope.clientOfflineSessionMaxLifespan.time) {
  1445. $scope.clientEdit.attributes['client.offline.session.max.lifespan'] = $scope.clientOfflineSessionMaxLifespan.toSeconds();
  1446. } else {
  1447. $scope.clientEdit.attributes['client.offline.session.max.lifespan'] = null;
  1448. }
  1449. }
  1450. $scope.updateOauth2DeviceCodeLifespan = function() {
  1451. if ($scope.oauth2DeviceCodeLifespan.time) {
  1452. $scope.clientEdit.attributes['oauth2.device.code.lifespan'] = $scope.oauth2DeviceCodeLifespan.toSeconds();
  1453. } else {
  1454. $scope.clientEdit.attributes['oauth2.device.code.lifespan'] = null;
  1455. }
  1456. }
  1457. $scope.updateOauth2DevicePollingInterval = function() {
  1458. if ($scope.oauth2DevicePollingInterval) {
  1459. $scope.clientEdit.attributes['oauth2.device.polling.interval'] = $scope.oauth2DevicePollingInterval;
  1460. } else {
  1461. $scope.clientEdit.attributes['oauth2.device.polling.interval'] = null;
  1462. }
  1463. }
  1464. $scope.confirmChangeAuthzSettings = function($event) {
  1465. if ($scope.client.authorizationServicesEnabled && $scope.clientEdit.authorizationServicesEnabled) {
  1466. $event.preventDefault();
  1467. Dialog.confirm("Disable Authorization Settings", "Are you sure you want to disable authorization ? Once you save your changes, all authorization settings associated with this client will be removed. This operation can not be reverted.", function () {
  1468. $scope.clientEdit.authorizationServicesEnabled = false;
  1469. }, function () {
  1470. $scope.clientEdit.authorizationServicesEnabled = true;
  1471. });
  1472. }
  1473. }
  1474. function configureAuthorizationServices() {
  1475. if ($scope.clientEdit.authorizationServicesEnabled) {
  1476. if ($scope.accessType == 'public') {
  1477. $scope.accessType = 'confidential';
  1478. }
  1479. $scope.clientEdit.publicClient = false;
  1480. $scope.clientEdit.serviceAccountsEnabled = true;
  1481. } else if ($scope.clientEdit.bearerOnly) {
  1482. $scope.clientEdit.serviceAccountsEnabled = false;
  1483. }
  1484. }
  1485. $scope.$watch('clientEdit', function() {
  1486. $scope.changed = isChanged();
  1487. configureAuthorizationServices();
  1488. }, true);
  1489. $scope.$watch('newRedirectUri', function() {
  1490. $scope.changed = isChanged();
  1491. }, true);
  1492. $scope.$watch('newWebOrigin', function() {
  1493. $scope.changed = isChanged();
  1494. }, true);
  1495. $scope.$watch('newRequestUri', function() {
  1496. $scope.changed = isChanged();
  1497. }, true);
  1498. $scope.deleteWebOrigin = function(index) {
  1499. $scope.clientEdit.webOrigins.splice(index, 1);
  1500. }
  1501. $scope.addWebOrigin = function() {
  1502. $scope.clientEdit.webOrigins.push($scope.newWebOrigin);
  1503. $scope.newWebOrigin = "";
  1504. }
  1505. $scope.deleteRequestUri = function(index) {
  1506. $scope.clientEdit.requestUris.splice(index, 1);
  1507. }
  1508. $scope.addRequestUri = function() {
  1509. $scope.clientEdit.requestUris.push($scope.newRequestUri);
  1510. $scope.newRequestUri = "";
  1511. }
  1512. $scope.deleteRedirectUri = function(index) {
  1513. $scope.clientEdit.redirectUris.splice(index, 1);
  1514. }
  1515. $scope.addRedirectUri = function() {
  1516. $scope.clientEdit.redirectUris.push($scope.newRedirectUri);
  1517. $scope.newRedirectUri = "";
  1518. }
  1519. $scope.save = function() {
  1520. if ($scope.newRedirectUri && $scope.newRedirectUri.length > 0) {
  1521. $scope.addRedirectUri();
  1522. }
  1523. if ($scope.newWebOrigin && $scope.newWebOrigin.length > 0) {
  1524. $scope.addWebOrigin();
  1525. }
  1526. if ($scope.newRequestUri && $scope.newRequestUri.length > 0) {
  1527. $scope.addRequestUri();
  1528. }
  1529. if ($scope.clientEdit.requestUris && $scope.clientEdit.requestUris.length > 0) {
  1530. $scope.clientEdit.attributes["request.uris"] = $scope.clientEdit.requestUris.join("##");
  1531. } else {
  1532. $scope.clientEdit.attributes["request.uris"] = null;
  1533. }
  1534. if (!$scope.clientEdit.frontchannelLogout) {
  1535. $scope.clientEdit.attributes["frontchannel.logout.url"] = null;
  1536. }
  1537. delete $scope.clientEdit.requestUris;
  1538. if ($scope.samlArtifactBinding == true) {
  1539. $scope.clientEdit.attributes["saml.artifact.binding"] = "true";
  1540. } else {
  1541. $scope.clientEdit.attributes["saml.artifact.binding"] = "false";
  1542. }
  1543. if ($scope.samlServerSignature == true) {
  1544. $scope.clientEdit.attributes["saml.server.signature"] = "true";
  1545. } else {
  1546. $scope.clientEdit.attributes["saml.server.signature"] = "false";
  1547. }
  1548. if ($scope.samlServerSignatureEnableKeyInfoExtension == true) {
  1549. $scope.clientEdit.attributes["saml.server.signature.keyinfo.ext"] = "true";
  1550. } else {
  1551. $scope.clientEdit.attributes["saml.server.signature.keyinfo.ext"] = "false";
  1552. }
  1553. if ($scope.samlAssertionSignature == true) {
  1554. $scope.clientEdit.attributes["saml.assertion.signature"] = "true";
  1555. } else {
  1556. $scope.clientEdit.attributes["saml.assertion.signature"] = "false";
  1557. }
  1558. if ($scope.samlClientSignature == true) {
  1559. $scope.clientEdit.attributes["saml.client.signature"] = "true";
  1560. } else {
  1561. $scope.clientEdit.attributes["saml.client.signature"] = "false";
  1562. }
  1563. if ($scope.samlEncrypt == true) {
  1564. $scope.clientEdit.attributes["saml.encrypt"] = "true";
  1565. } else {
  1566. $scope.clientEdit.attributes["saml.encrypt"] = "false";
  1567. }
  1568. if ($scope.samlAuthnStatement == true) {
  1569. $scope.clientEdit.attributes["saml.authnstatement"] = "true";
  1570. } else {
  1571. $scope.clientEdit.attributes["saml.authnstatement"] = "false";
  1572. }
  1573. if ($scope.samlOneTimeUseCondition == true) {
  1574. $scope.clientEdit.attributes["saml.onetimeuse.condition"] = "true";
  1575. } else {
  1576. $scope.clientEdit.attributes["saml.onetimeuse.condition"] = "false";
  1577. }
  1578. if ($scope.samlForceNameIdFormat == true) {
  1579. $scope.clientEdit.attributes["saml_force_name_id_format"] = "true";
  1580. } else {
  1581. $scope.clientEdit.attributes["saml_force_name_id_format"] = "false";
  1582. }
  1583. if ($scope.samlMultiValuedRoles == true) {
  1584. $scope.clientEdit.attributes["saml.multivalued.roles"] = "true";
  1585. } else {
  1586. $scope.clientEdit.attributes["saml.multivalued.roles"] = "false";
  1587. }
  1588. if ($scope.samlForcePostBinding == true) {
  1589. $scope.clientEdit.attributes["saml.force.post.binding"] = "true";
  1590. } else {
  1591. $scope.clientEdit.attributes["saml.force.post.binding"] = "false";
  1592. }
  1593. if ($scope.excludeSessionStateFromAuthResponse == true) {
  1594. $scope.clientEdit.attributes["exclude.session.state.from.auth.response"] = "true";
  1595. } else {
  1596. $scope.clientEdit.attributes["exclude.session.state.from.auth.response"] = "false";
  1597. }
  1598. if ($scope.oauth2DeviceAuthorizationGrantEnabled == true) {
  1599. $scope.clientEdit.attributes["oauth2.device.authorization.grant.enabled"] = "true";
  1600. } else {
  1601. $scope.clientEdit.attributes["oauth2.device.authorization.grant.enabled"] = "false";
  1602. }
  1603. if ($scope.oidcCibaGrantEnabled == true) {
  1604. $scope.clientEdit.attributes["oidc.ciba.grant.enabled"] = "true";
  1605. } else {
  1606. $scope.clientEdit.attributes["oidc.ciba.grant.enabled"] = "false";
  1607. }
  1608. if ($scope.useRefreshTokens == true) {
  1609. $scope.clientEdit.attributes["use.refresh.tokens"] = "true";
  1610. } else {
  1611. $scope.clientEdit.attributes["use.refresh.tokens"] = "false";
  1612. }
  1613. if ($scope.useIdTokenAsDetachedSignature == true) {
  1614. $scope.clientEdit.attributes["id.token.as.detached.signature"] = "true";
  1615. } else {
  1616. $scope.clientEdit.attributes["id.token.as.detached.signature"] = "false";
  1617. }
  1618. // KEYCLOAK-6771 Certificate Bound Token
  1619. // https://tools.ietf.org/html/draft-ietf-oauth-mtls-08#section-3
  1620. if ($scope.tlsClientCertificateBoundAccessTokens == true) {
  1621. $scope.clientEdit.attributes["tls.client.certificate.bound.access.tokens"] = "true";
  1622. } else {
  1623. $scope.clientEdit.attributes["tls.client.certificate.bound.access.tokens"] = "false";
  1624. }
  1625. // PAR request.
  1626. if ($scope.requirePushedAuthorizationRequests == true) {
  1627. $scope.clientEdit.attributes["require.pushed.authorization.requests"] = "true";
  1628. } else {
  1629. $scope.clientEdit.attributes["require.pushed.authorization.requests"] = "false";
  1630. }
  1631. // KEYCLOAK-9551 Client Credentials Grant generates refresh token
  1632. // https://tools.ietf.org/html/rfc6749#section-4.4.3
  1633. if ($scope.useRefreshTokenForClientCredentialsGrant === true) {
  1634. $scope.clientEdit.attributes["client_credentials.use_refresh_token"] = "true";
  1635. } else {
  1636. $scope.clientEdit.attributes["client_credentials.use_refresh_token"] = "false";
  1637. }
  1638. if ($scope.displayOnConsentScreen == true) {
  1639. $scope.clientEdit.attributes["display.on.consent.screen"] = "true";
  1640. } else {
  1641. $scope.clientEdit.attributes["display.on.consent.screen"] = "false";
  1642. }
  1643. if ($scope.backchannelLogoutSessionRequired == true) {
  1644. $scope.clientEdit.attributes["backchannel.logout.session.required"] = "true";
  1645. } else {
  1646. $scope.clientEdit.attributes["backchannel.logout.session.required"] = "false";
  1647. }
  1648. if ($scope.backchannelLogoutRevokeOfflineSessions == true) {
  1649. $scope.clientEdit.attributes["backchannel.logout.revoke.offline.tokens"] = "true";
  1650. } else {
  1651. $scope.clientEdit.attributes["backchannel.logout.revoke.offline.tokens"] = "false";
  1652. }
  1653. $scope.clientEdit.protocol = $scope.protocol;
  1654. $scope.clientEdit.attributes['saml.signature.algorithm'] = $scope.signatureAlgorithm;
  1655. $scope.clientEdit.attributes['saml_name_id_format'] = $scope.nameIdFormat;
  1656. if ($scope.clientEdit.protocol != 'saml' && !$scope.clientEdit.bearerOnly && ($scope.clientEdit.standardFlowEnabled || $scope.clientEdit.implicitFlowEnabled) && (!$scope.clientEdit.redirectUris || $scope.clientEdit.redirectUris.length == 0)) {
  1657. Notifications.error("You must specify at least one redirect uri");
  1658. } else {
  1659. Client.update({
  1660. realm : realm.realm,
  1661. client : client.id
  1662. }, $scope.clientEdit, function() {
  1663. $route.reload();
  1664. Notifications.success("Your changes have been saved to the client.");
  1665. });
  1666. }
  1667. };
  1668. $scope.reset = function() {
  1669. $route.reload();
  1670. };
  1671. $scope.cancel = function() {
  1672. $location.url("/realms/" + realm.realm + "/clients");
  1673. };
  1674. });
  1675. module.controller('CreateClientCtrl', function($scope, realm, client, $route, serverInfo, Client, ClientDescriptionConverter, $location, $modal, Dialog, Notifications) {
  1676. $scope.protocols = serverInfo.listProviderIds('login-protocol');
  1677. $scope.create = true;
  1678. $scope.realm = realm;
  1679. $scope.client = {
  1680. enabled: true,
  1681. attributes: {}
  1682. };
  1683. $scope.client.redirectUris = [];
  1684. $scope.protocol = $scope.protocols[0];
  1685. $scope.importFile = function(fileContent){
  1686. console.debug(fileContent);
  1687. ClientDescriptionConverter.save({
  1688. realm: realm.realm
  1689. }, fileContent, function (data) {
  1690. $scope.client = data;
  1691. if (data.protocol) {
  1692. $scope.protocol = data.protocol;
  1693. }
  1694. $scope.importing = true;
  1695. });
  1696. };
  1697. $scope.viewImportDetails = function() {
  1698. $modal.open({
  1699. templateUrl: resourceUrl + '/partials/modal/view-object.html',
  1700. controller: 'ObjectModalCtrl',
  1701. resolve: {
  1702. object: function () {
  1703. return $scope.client;
  1704. }
  1705. }
  1706. })
  1707. };
  1708. $scope.switchChange = function() {
  1709. $scope.changed = true;
  1710. }
  1711. $scope.changeProtocol = function() {
  1712. if ($scope.protocol == "openid-connect") {
  1713. $scope.client.protocol = "openid-connect";
  1714. } else if ($scope.protocol == "saml") {
  1715. $scope.client.protocol = "saml";
  1716. }
  1717. };
  1718. $scope.$watch(function() {
  1719. return $location.path();
  1720. }, function() {
  1721. $scope.path = $location.path().substring(1).split("/");
  1722. });
  1723. function isChanged() {
  1724. if (!angular.equals($scope.client, client)) {
  1725. return true;
  1726. }
  1727. return false;
  1728. }
  1729. $scope.$watch('client', function() {
  1730. $scope.changed = isChanged();
  1731. }, true);
  1732. $scope.save = function() {
  1733. $scope.client.protocol = $scope.protocol;
  1734. Client.save({
  1735. realm: realm.realm,
  1736. client: ''
  1737. }, $scope.client, function (data, headers) {
  1738. $scope.changed = false;
  1739. var l = headers().location;
  1740. var id = l.substring(l.lastIndexOf("/") + 1);
  1741. $location.url("/realms/" + realm.realm + "/clients/" + id);
  1742. Notifications.success("The client has been created.");
  1743. });
  1744. };
  1745. $scope.reset = function() {
  1746. $route.reload();
  1747. };
  1748. $scope.cancel = function() {
  1749. $location.url("/realms/" + realm.realm + "/clients");
  1750. };
  1751. });
  1752. module.controller('ClientScopeMappingCtrl', function($scope, $http, realm, $route, client, clients, Notifications,
  1753. Client, ClientScope,
  1754. ClientRealmScopeMapping, ClientClientScopeMapping, ClientRole,
  1755. ClientAvailableRealmScopeMapping, ClientAvailableClientScopeMapping,
  1756. ClientCompositeRealmScopeMapping, ClientCompositeClientScopeMapping) {
  1757. $scope.realm = realm;
  1758. $scope.client = angular.copy(client);
  1759. $scope.selectedRealmRoles = [];
  1760. $scope.selectedRealmMappings = [];
  1761. $scope.realmMappings = [];
  1762. $scope.clients = clients;
  1763. $scope.clientRoles = [];
  1764. $scope.clientComposite = [];
  1765. $scope.selectedClientRoles = [];
  1766. $scope.selectedClientMappings = [];
  1767. $scope.clientMappings = [];
  1768. $scope.dummymodel = [];
  1769. $scope.hideRoleSelector = function() {
  1770. return $scope.client.fullScopeAllowed;
  1771. }
  1772. $scope.changeFlag = function() {
  1773. console.log('changeFlag');
  1774. Client.update({
  1775. realm : realm.realm,
  1776. client : client.id
  1777. }, $scope.client, function() {
  1778. $scope.changed = false;
  1779. client = angular.copy($scope.client);
  1780. updateRealmRoles();
  1781. Notifications.success("Scope mappings updated.");
  1782. });
  1783. }
  1784. $scope.selectedClient = null;
  1785. $scope.selectClient = function(client) {
  1786. if (!client || !client.id) {
  1787. $scope.selectedClient = null;
  1788. return;
  1789. }
  1790. $scope.selectedClient = client;
  1791. updateClientRoles();
  1792. }
  1793. function updateRealmRoles() {
  1794. $scope.realmRoles = ClientAvailableRealmScopeMapping.query({realm : realm.realm, client : client.id});
  1795. $scope.realmMappings = ClientRealmScopeMapping.query({realm : realm.realm, client : client.id});
  1796. $scope.realmComposite = ClientCompositeRealmScopeMapping.query({realm : realm.realm, client : client.id});
  1797. }
  1798. function updateClientRoles() {
  1799. if ($scope.selectedClient) {
  1800. $scope.clientRoles = ClientAvailableClientScopeMapping.query({realm : realm.realm, client : client.id, targetClient : $scope.selectedClient.id});
  1801. $scope.clientMappings = ClientClientScopeMapping.query({realm : realm.realm, client : client.id, targetClient : $scope.selectedClient.id});
  1802. $scope.clientComposite = ClientCompositeClientScopeMapping.query({realm : realm.realm, client : client.id, targetClient : $scope.selectedClient.id});
  1803. } else {
  1804. $scope.clientRoles = null;
  1805. $scope.clientMappings = null;
  1806. $scope.clientComposite = null;
  1807. }
  1808. }
  1809. $scope.addRealmRole = function() {
  1810. $scope.selectedRealmRolesToAdd = JSON.parse('[' + $scope.selectedRealmRoles + ']');
  1811. $scope.selectedRealmRoles = [];
  1812. $http.post(authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/scope-mappings/realm',
  1813. $scope.selectedRealmRolesToAdd).then(function() {
  1814. updateRealmRoles();
  1815. $scope.selectedRealmRolesToAdd = [];
  1816. Notifications.success("Scope mappings updated.");
  1817. });
  1818. };
  1819. $scope.deleteRealmRole = function() {
  1820. $scope.selectedRealmMappingsToRemove = JSON.parse('[' + $scope.selectedRealmMappings + ']');
  1821. $scope.selectedRealmMappings = [];
  1822. $http.delete(authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/scope-mappings/realm',
  1823. {data : $scope.selectedRealmMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function () {
  1824. updateRealmRoles();
  1825. $scope.selectedRealmMappingsToRemove = [];
  1826. Notifications.success("Scope mappings updated.");
  1827. });
  1828. };
  1829. $scope.addClientRole = function() {
  1830. $scope.selectedClientRolesToAdd = JSON.parse('[' + $scope.selectedClientRoles + ']');
  1831. $scope.selectedClientRoles = [];
  1832. $http.post(authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/scope-mappings/clients/' + $scope.selectedClient.id,
  1833. $scope.selectedClientRolesToAdd).then(function () {
  1834. updateClientRoles();
  1835. $scope.selectedClientRolesToAdd = [];
  1836. Notifications.success("Scope mappings updated.");
  1837. });
  1838. };
  1839. $scope.deleteClientRole = function() {
  1840. $scope.selectedClientMappingsToRemove = JSON.parse('[' + $scope.selectedClientMappings + ']');
  1841. $scope.selectedClientMappings = [];
  1842. $http.delete(authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/scope-mappings/clients/' + $scope.selectedClient.id,
  1843. {data : $scope.selectedClientMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function () {
  1844. updateClientRoles();
  1845. $scope.selectedClientMappingsToRemove = [];
  1846. Notifications.success("Scope mappings updated.");
  1847. });
  1848. };
  1849. clientSelectControl($scope, $route.current.params.realm, Client);
  1850. updateRealmRoles();
  1851. });
  1852. module.controller('ClientRevocationCtrl', function($scope, realm, client, Client, ClientPushRevocation, $location, Dialog, Notifications) {
  1853. $scope.realm = realm;
  1854. $scope.client = client;
  1855. var setNotBefore = function() {
  1856. if ($scope.client.notBefore == 0) {
  1857. $scope.notBefore = "None";
  1858. } else {
  1859. $scope.notBefore = new Date($scope.client.notBefore * 1000);
  1860. }
  1861. };
  1862. setNotBefore();
  1863. var refresh = function() {
  1864. Client.get({ realm : realm.realm, client: $scope.client.id }, function(updated) {
  1865. $scope.client = updated;
  1866. setNotBefore();
  1867. })
  1868. };
  1869. $scope.clear = function() {
  1870. $scope.client.notBefore = 0;
  1871. Client.update({ realm : realm.realm, client: client.id}, $scope.client, function () {
  1872. $scope.notBefore = "None";
  1873. Notifications.success('Not Before cleared for client.');
  1874. refresh();
  1875. });
  1876. }
  1877. $scope.setNotBeforeNow = function() {
  1878. $scope.client.notBefore = new Date().getTime()/1000;
  1879. Client.update({ realm : realm.realm, client: $scope.client.id}, $scope.client, function () {
  1880. Notifications.success('Not Before set for client.');
  1881. refresh();
  1882. });
  1883. }
  1884. $scope.pushRevocation = function() {
  1885. ClientPushRevocation.save({realm : realm.realm, client: $scope.client.id}, function (globalReqResult) {
  1886. var successCount = globalReqResult.successRequests ? globalReqResult.successRequests.length : 0;
  1887. var failedCount = globalReqResult.failedRequests ? globalReqResult.failedRequests.length : 0;
  1888. if (successCount==0 && failedCount==0) {
  1889. Notifications.warn('No push sent. No admin URI configured or no registered cluster nodes available');
  1890. } else if (failedCount > 0) {
  1891. var msgStart = successCount>0 ? 'Successfully push notBefore to: ' + globalReqResult.successRequests + ' . ' : '';
  1892. Notifications.error(msgStart + 'Failed to push notBefore to: ' + globalReqResult.failedRequests + '. Verify availability of failed hosts and try again');
  1893. } else {
  1894. Notifications.success('Successfully push notBefore to: ' + globalReqResult.successRequests);
  1895. }
  1896. });
  1897. }
  1898. });
  1899. module.controller('ClientClusteringCtrl', function($scope, client, Client, ClientTestNodesAvailable, ClientClusterNode, realm, $location, $route, Dialog, Notifications, TimeUnit) {
  1900. $scope.client = client;
  1901. $scope.realm = realm;
  1902. var oldCopy = angular.copy($scope.client);
  1903. $scope.changed = false;
  1904. $scope.$watch('client', function() {
  1905. if (!angular.equals($scope.client, oldCopy)) {
  1906. $scope.changed = true;
  1907. }
  1908. }, true);
  1909. $scope.client.nodeReRegistrationTimeoutUnit = TimeUnit.autoUnit(client.nodeReRegistrationTimeout);
  1910. $scope.client.nodeReRegistrationTimeout = TimeUnit.toUnit(client.nodeReRegistrationTimeout, $scope.client.nodeReRegistrationTimeoutUnit);
  1911. $scope.save = function() {
  1912. var clientCopy = angular.copy($scope.client);
  1913. delete clientCopy['nodeReRegistrationTimeoutUnit'];
  1914. clientCopy.nodeReRegistrationTimeout = TimeUnit.toSeconds($scope.client.nodeReRegistrationTimeout, $scope.client.nodeReRegistrationTimeoutUnit)
  1915. Client.update({ realm : realm.realm, client : client.id }, clientCopy, function () {
  1916. $route.reload();
  1917. Notifications.success('Your changes have been saved to the client.');
  1918. });
  1919. };
  1920. $scope.reset = function() {
  1921. $route.reload();
  1922. };
  1923. $scope.testNodesAvailable = function() {
  1924. ClientTestNodesAvailable.get({ realm : realm.realm, client : client.id }, function(globalReqResult) {
  1925. $route.reload();
  1926. var successCount = globalReqResult.successRequests ? globalReqResult.successRequests.length : 0;
  1927. var failedCount = globalReqResult.failedRequests ? globalReqResult.failedRequests.length : 0;
  1928. if (successCount==0 && failedCount==0) {
  1929. Notifications.warn('No requests sent. No admin URI configured or no registered cluster nodes available');
  1930. } else if (failedCount > 0) {
  1931. var msgStart = successCount>0 ? 'Successfully verify availability for ' + globalReqResult.successRequests + ' . ' : '';
  1932. Notifications.error(msgStart + 'Failed to verify availability for: ' + globalReqResult.failedRequests + '. Fix or unregister failed cluster nodes and try again');
  1933. } else {
  1934. Notifications.success('Successfully sent requests to: ' + globalReqResult.successRequests);
  1935. }
  1936. });
  1937. };
  1938. if (client.registeredNodes) {
  1939. var nodeRegistrations = [];
  1940. for (node in client.registeredNodes) {
  1941. reg = {
  1942. host: node,
  1943. lastRegistration: new Date(client.registeredNodes[node] * 1000)
  1944. }
  1945. nodeRegistrations.push(reg);
  1946. }
  1947. $scope.nodeRegistrations = nodeRegistrations;
  1948. };
  1949. $scope.removeNode = function(node) {
  1950. Dialog.confirmDelete(node.host, 'node', function() {
  1951. ClientClusterNode.remove({ realm : realm.realm, client : client.id , node: node.host }, function() {
  1952. Notifications.success('Node ' + node.host + ' unregistered successfully.');
  1953. $route.reload();
  1954. });
  1955. });
  1956. };
  1957. });
  1958. module.controller('ClientClusteringNodeCtrl', function($scope, client, Client, ClientClusterNode, realm,
  1959. $location, $routeParams, Notifications, Dialog) {
  1960. $scope.client = client;
  1961. $scope.realm = realm;
  1962. $scope.create = !$routeParams.node;
  1963. $scope.save = function() {
  1964. ClientClusterNode.save({ realm : realm.realm, client : client.id , node: $scope.node.host }, function() {
  1965. Notifications.success('Node ' + $scope.node.host + ' registered successfully.');
  1966. $location.url('/realms/' + realm.realm + '/clients/' + client.id + '/clustering');
  1967. });
  1968. }
  1969. $scope.unregisterNode = function() {
  1970. Dialog.confirmDelete($scope.node.host, 'node', function() {
  1971. ClientClusterNode.remove({ realm : realm.realm, client : client.id , node: $scope.node.host }, function() {
  1972. Notifications.success('Node ' + $scope.node.host + ' unregistered successfully.');
  1973. $location.url('/realms/' + realm.realm + '/clients/' + client.id + '/clustering');
  1974. });
  1975. });
  1976. }
  1977. if ($scope.create) {
  1978. $scope.node = {}
  1979. $scope.registered = false;
  1980. } else {
  1981. var lastRegTime = client.registeredNodes[$routeParams.node];
  1982. if (lastRegTime) {
  1983. $scope.registered = true;
  1984. $scope.node = {
  1985. host: $routeParams.node,
  1986. lastRegistration: new Date(lastRegTime * 1000)
  1987. }
  1988. } else {
  1989. $scope.registered = false;
  1990. $scope.node = {
  1991. host: $routeParams.node
  1992. }
  1993. }
  1994. }
  1995. });
  1996. module.controller('AddBuiltinProtocolMapperCtrl', function($scope, realm, client, serverInfo,
  1997. ClientProtocolMappersByProtocol,
  1998. $http, $location, Dialog, Notifications) {
  1999. $scope.realm = realm;
  2000. $scope.client = client;
  2001. if (client.protocol == null) {
  2002. client.protocol = 'openid-connect';
  2003. }
  2004. var protocolMappers = serverInfo.protocolMapperTypes[client.protocol];
  2005. var mapperTypes = {};
  2006. for (var i = 0; i < protocolMappers.length; i++) {
  2007. mapperTypes[protocolMappers[i].id] = protocolMappers[i];
  2008. }
  2009. $scope.mapperTypes = mapperTypes;
  2010. var updateMappers = function() {
  2011. var clientMappers = ClientProtocolMappersByProtocol.query({realm : realm.realm, client : client.id, protocol : client.protocol}, function() {
  2012. var builtinMappers = serverInfo.builtinProtocolMappers[client.protocol];
  2013. for (var i = 0; i < clientMappers.length; i++) {
  2014. for (var j = 0; j < builtinMappers.length; j++) {
  2015. if (builtinMappers[j].name == clientMappers[i].name
  2016. && builtinMappers[j].protocolMapper == clientMappers[i].protocolMapper) {
  2017. builtinMappers.splice(j, 1);
  2018. break;
  2019. }
  2020. }
  2021. }
  2022. $scope.mappers = builtinMappers;
  2023. for (var i = 0; i < $scope.mappers.length; i++) {
  2024. $scope.mappers[i].isChecked = false;
  2025. }
  2026. });
  2027. };
  2028. updateMappers();
  2029. $scope.add = function() {
  2030. var toAdd = [];
  2031. for (var i = 0; i < $scope.mappers.length; i++) {
  2032. if ($scope.mappers[i].isChecked) {
  2033. delete $scope.mappers[i].isChecked;
  2034. toAdd.push($scope.mappers[i]);
  2035. }
  2036. }
  2037. $http.post(authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/protocol-mappers/add-models',
  2038. toAdd).then(function() {
  2039. Notifications.success("Mappers added");
  2040. $location.url('/realms/' + realm.realm + '/clients/' + client.id + '/mappers');
  2041. }).catch(function() {
  2042. Notifications.error("Error adding mappers");
  2043. $location.url('/realms/' + realm.realm + '/clients/' + client.id + '/mappers');
  2044. });
  2045. };
  2046. });
  2047. module.controller('ClientProtocolMapperListCtrl', function($scope, realm, client, serverInfo,
  2048. Client,
  2049. ClientProtocolMappersByProtocol, ClientProtocolMapper,
  2050. $route, Dialog, Notifications) {
  2051. $scope.realm = realm;
  2052. $scope.client = client;
  2053. if (client.protocol == null) {
  2054. client.protocol = 'openid-connect';
  2055. }
  2056. $scope.changeFlag = function() {
  2057. Client.update({
  2058. realm : realm.realm,
  2059. client : client.id
  2060. }, $scope.client, function() {
  2061. $scope.changed = false;
  2062. client = angular.copy($scope.client);
  2063. Notifications.success("Client updated.");
  2064. });
  2065. }
  2066. var protocolMappers = serverInfo.protocolMapperTypes[client.protocol];
  2067. var mapperTypes = {};
  2068. for (var i = 0; i < protocolMappers.length; i++) {
  2069. mapperTypes[protocolMappers[i].id] = protocolMappers[i];
  2070. }
  2071. $scope.mapperTypes = mapperTypes;
  2072. $scope.removeMapper = function(mapper) {
  2073. console.debug(mapper);
  2074. Dialog.confirmDelete(mapper.name, 'mapper', function() {
  2075. ClientProtocolMapper.remove({ realm: realm.realm, client: client.id, id : mapper.id }, function() {
  2076. Notifications.success("The mapper has been deleted.");
  2077. $route.reload();
  2078. });
  2079. });
  2080. };
  2081. $scope.sortMappersByPriority = function(mapper) {
  2082. return $scope.mapperTypes[mapper.protocolMapper].priority;
  2083. }
  2084. var updateMappers = function() {
  2085. $scope.mappers = ClientProtocolMappersByProtocol.query({realm : realm.realm, client : client.id, protocol : client.protocol});
  2086. };
  2087. updateMappers();
  2088. });
  2089. module.controller('ClientProtocolMapperCtrl', function($scope, realm, serverInfo, client, clients, mapper, ClientProtocolMapper, Notifications, Dialog, $location) {
  2090. $scope.realm = realm;
  2091. $scope.clients = clients;
  2092. /*
  2093. $scope.client = client;
  2094. $scope.create = false;
  2095. $scope.protocol = client.protocol;
  2096. $scope.mapper = angular.copy(mapper);
  2097. $scope.changed = false;
  2098. */
  2099. if (client.protocol == null) {
  2100. client.protocol = 'openid-connect';
  2101. }
  2102. $scope.model = {
  2103. realm: realm,
  2104. client: client,
  2105. create: false,
  2106. protocol: client.protocol,
  2107. mapper: angular.copy(mapper),
  2108. changed: false
  2109. };
  2110. var protocolMappers = serverInfo.protocolMapperTypes[client.protocol];
  2111. for (var i = 0; i < protocolMappers.length; i++) {
  2112. if (protocolMappers[i].id === mapper.protocolMapper) {
  2113. $scope.model.mapperType = protocolMappers[i];
  2114. }
  2115. }
  2116. $scope.$watch(function() {
  2117. return $location.path();
  2118. }, function() {
  2119. $scope.path = $location.path().substring(1).split("/");
  2120. });
  2121. $scope.$watch('model.mapper', function() {
  2122. if (!angular.equals($scope.model.mapper, mapper)) {
  2123. $scope.model.changed = true;
  2124. }
  2125. }, true);
  2126. $scope.save = function() {
  2127. ClientProtocolMapper.update({
  2128. realm : realm.realm,
  2129. client: client.id,
  2130. id : $scope.model.mapper.id
  2131. }, $scope.model.mapper, function() {
  2132. $scope.model.changed = false;
  2133. mapper = angular.copy($scope.mapper);
  2134. $location.url("/realms/" + realm.realm + '/clients/' + client.id + "/mappers/" + $scope.model.mapper.id);
  2135. Notifications.success("Your changes have been saved.");
  2136. });
  2137. };
  2138. $scope.reset = function() {
  2139. $scope.model.mapper = angular.copy(mapper);
  2140. $scope.model.changed = false;
  2141. };
  2142. $scope.cancel = function() {
  2143. //$location.url("/realms");
  2144. window.history.back();
  2145. };
  2146. $scope.remove = function() {
  2147. Dialog.confirmDelete($scope.model.mapper.name, 'mapper', function() {
  2148. ClientProtocolMapper.remove({ realm: realm.realm, client: client.id, id : $scope.model.mapper.id }, function() {
  2149. Notifications.success("The mapper has been deleted.");
  2150. $location.url("/realms/" + realm.realm + '/clients/' + client.id + "/mappers");
  2151. });
  2152. });
  2153. };
  2154. });
  2155. module.controller('ClientProtocolMapperCreateCtrl', function($scope, realm, serverInfo, client, clients, ClientProtocolMapper, Notifications, Dialog, $location) {
  2156. $scope.realm = realm;
  2157. $scope.clients = clients;
  2158. if (client.protocol == null) {
  2159. client.protocol = 'openid-connect';
  2160. }
  2161. var protocol = client.protocol;
  2162. /*
  2163. $scope.client = client;
  2164. $scope.create = true;
  2165. $scope.protocol = protocol;
  2166. $scope.mapper = { protocol : client.protocol, config: {}};
  2167. $scope.mapperTypes = serverInfo.protocolMapperTypes[protocol];
  2168. */
  2169. $scope.model = {
  2170. realm: realm,
  2171. client: client,
  2172. create: true,
  2173. protocol: client.protocol,
  2174. mapper: { protocol : client.protocol, config: {}},
  2175. changed: false,
  2176. mapperTypes: serverInfo.protocolMapperTypes[protocol]
  2177. };
  2178. console.log("mapper types: ", $scope.model.mapperTypes);
  2179. // apply default configurations on change for selected protocolmapper type.
  2180. $scope.$watch('model.mapperType', function() {
  2181. var currentMapperType = $scope.model.mapperType;
  2182. var defaultConfig = {};
  2183. if (currentMapperType && Array.isArray(currentMapperType.properties)) {
  2184. for (var i = 0; i < currentMapperType.properties.length; i++) {
  2185. var property = currentMapperType.properties[i];
  2186. if (property && property.name && property.defaultValue) {
  2187. defaultConfig[property.name] = property.defaultValue;
  2188. }
  2189. }
  2190. }
  2191. $scope.model.mapper.config = defaultConfig;
  2192. }, true);
  2193. $scope.model.mapperType = $scope.model.mapperTypes[0];
  2194. $scope.$watch(function() {
  2195. return $location.path();
  2196. }, function() {
  2197. $scope.path = $location.path().substring(1).split("/");
  2198. });
  2199. $scope.save = function() {
  2200. $scope.model.mapper.protocolMapper = $scope.model.mapperType.id;
  2201. ClientProtocolMapper.save({
  2202. realm : realm.realm, client: client.id
  2203. }, $scope.model.mapper, function(data, headers) {
  2204. var l = headers().location;
  2205. var id = l.substring(l.lastIndexOf("/") + 1);
  2206. $location.url("/realms/" + realm.realm + '/clients/' + client.id + "/mappers/" + id);
  2207. Notifications.success("Mapper has been created.");
  2208. });
  2209. };
  2210. $scope.cancel = function() {
  2211. //$location.url("/realms");
  2212. window.history.back();
  2213. };
  2214. });
  2215. module.controller('ClientClientScopesSetupCtrl', function($scope, realm, Realm, client, clientScopes, serverInfo,
  2216. clientDefaultClientScopes, ClientDefaultClientScopes, clientOptionalClientScopes, ClientOptionalClientScopes, $route, Notifications, $location) {
  2217. console.log('ClientClientScopesSetupCtrl');
  2218. $scope.realm = realm;
  2219. $scope.client = client;
  2220. $scope.clientDefaultClientScopes = clientDefaultClientScopes;
  2221. $scope.clientOptionalClientScopes = clientOptionalClientScopes;
  2222. $scope.availableClientScopes = [];
  2223. $scope.selectedDefaultClientScopes = [];
  2224. $scope.selectedDefDefaultClientScopes = [];
  2225. $scope.selectedOptionalClientScopes = [];
  2226. $scope.selectedDefOptionalClientScopes = [];
  2227. // Populate available client scopes. Available client scopes are neither already assigned to 'default' or 'optional'
  2228. for (var i = 0; i < clientScopes.length; i++) {
  2229. var clientScope = clientScopes[i];
  2230. var scopeName = clientScopes[i].name;
  2231. var available = true;
  2232. if (clientScope.protocol != client.protocol) {
  2233. available = false;
  2234. }
  2235. for (var j = 0; j < $scope.clientDefaultClientScopes.length; j++) {
  2236. if (scopeName === $scope.clientDefaultClientScopes[j].name) {
  2237. available = false;
  2238. }
  2239. }
  2240. for (var j = 0; j < $scope.clientOptionalClientScopes.length; j++) {
  2241. if (scopeName === $scope.clientOptionalClientScopes[j].name) {
  2242. available = false;
  2243. }
  2244. }
  2245. if (available) {
  2246. $scope.availableClientScopes.push(clientScope);
  2247. }
  2248. }
  2249. $scope.addDefaultClientScope = function () {
  2250. $scope.selectedDefaultClientScopesToAdd = JSON.parse('[' + $scope.selectedDefaultClientScopes + ']');
  2251. toAdd = $scope.selectedDefaultClientScopesToAdd.length;
  2252. for (var i = 0; i < $scope.selectedDefaultClientScopesToAdd.length; i++) {
  2253. var currentScope = $scope.selectedDefaultClientScopesToAdd[i];
  2254. ClientDefaultClientScopes.update({
  2255. realm : realm.realm,
  2256. client : client.id,
  2257. clientScopeId : currentScope.id
  2258. }, function () {
  2259. toAdd = toAdd - 1;
  2260. if (toAdd === 0) {
  2261. $route.reload();
  2262. Notifications.success("Default scopes updated.");
  2263. }
  2264. });
  2265. }
  2266. $scope.selectedDefaultClientScopesToAdd = [];
  2267. };
  2268. $scope.deleteDefaultClientScope = function () {
  2269. $scope.selectedDefDefaultClientScopesToRemove = JSON.parse('[' + $scope.selectedDefDefaultClientScopes + ']');
  2270. toRemove = $scope.selectedDefDefaultClientScopesToRemove.length;
  2271. for (var i = 0; i < $scope.selectedDefDefaultClientScopesToRemove.length; i++) {
  2272. var currentScope = $scope.selectedDefDefaultClientScopesToRemove[i];
  2273. ClientDefaultClientScopes.remove({
  2274. realm : realm.realm,
  2275. client : client.id,
  2276. clientScopeId : currentScope.id
  2277. }, function () {
  2278. toRemove = toRemove - 1;
  2279. if (toRemove === 0) {
  2280. $route.reload();
  2281. Notifications.success("Default scopes updated.");
  2282. }
  2283. });
  2284. }
  2285. $scope.selectedDefDefaultClientScopesToRemove = [];
  2286. };
  2287. $scope.addOptionalClientScope = function () {
  2288. $scope.selectedOptionalClientScopesToAdd = JSON.parse('[' + $scope.selectedOptionalClientScopes + ']');
  2289. toAdd = $scope.selectedOptionalClientScopesToAdd.length;
  2290. for (var i = 0; i < $scope.selectedOptionalClientScopesToAdd.length; i++) {
  2291. var currentScope = $scope.selectedOptionalClientScopesToAdd[i];
  2292. ClientOptionalClientScopes.update({
  2293. realm : realm.realm,
  2294. client : client.id,
  2295. clientScopeId : currentScope.id
  2296. }, function () {
  2297. toAdd = toAdd - 1;
  2298. if (toAdd === 0) {
  2299. $route.reload();
  2300. Notifications.success("Optional scopes updated.");
  2301. }
  2302. });
  2303. }
  2304. };
  2305. $scope.deleteOptionalClientScope = function () {
  2306. $scope.selectedDefOptionalClientScopesToRemove = JSON.parse('[' + $scope.selectedDefOptionalClientScopes + ']');
  2307. toRemove = $scope.selectedDefOptionalClientScopesToRemove.length;
  2308. for (var i = 0; i < $scope.selectedDefOptionalClientScopesToRemove.length; i++) {
  2309. var currentScope = $scope.selectedDefOptionalClientScopesToRemove[i];
  2310. ClientOptionalClientScopes.remove({
  2311. realm : realm.realm,
  2312. client : client.id,
  2313. clientScopeId : currentScope.id
  2314. }, function () {
  2315. toRemove = toRemove - 1;
  2316. if (toRemove === 0) {
  2317. $route.reload();
  2318. Notifications.success("Optional scopes updated.");
  2319. }
  2320. });
  2321. }
  2322. $scope.selectedDefOptionalClientScopesToRemove = [];
  2323. };
  2324. });
  2325. module.controller('ClientClientScopesEvaluateCtrl', function($scope, Realm, User, ClientEvaluateProtocolMappers, ClientEvaluateGrantedRoles,
  2326. ClientEvaluateNotGrantedRoles, ClientEvaluateGenerateExampleAccessToken, ClientEvaluateGenerateExampleIDToken,
  2327. ClientEvaluateGenerateExampleUserInfo, realm, client, clients, clientScopes, serverInfo, ComponentUtils,
  2328. clientOptionalClientScopes, clientDefaultClientScopes, $route, $routeParams, $http, Notifications, $location,
  2329. Client) {
  2330. console.log('ClientClientScopesEvaluateCtrl');
  2331. var protocolMappers = serverInfo.protocolMapperTypes[client.protocol];
  2332. var mapperTypes = {};
  2333. for (var i = 0; i < protocolMappers.length; i++) {
  2334. mapperTypes[protocolMappers[i].id] = protocolMappers[i];
  2335. }
  2336. $scope.mapperTypes = mapperTypes;
  2337. $scope.realm = realm;
  2338. $scope.client = client;
  2339. $scope.clients = clients;
  2340. $scope.userId = null;
  2341. $scope.availableClientScopes = [];
  2342. $scope.assignedClientScopes = [];
  2343. $scope.selectedClientScopes = [];
  2344. $scope.selectedDefClientScopes = [];
  2345. $scope.effectiveClientScopes = [];
  2346. // Populate available client scopes. Available client scopes are neither already assigned to 'default' or 'optional'
  2347. for (var i = 0; i < clientOptionalClientScopes.length; i++) {
  2348. $scope.availableClientScopes.push(clientOptionalClientScopes[i]);
  2349. }
  2350. function clearEvalResponse() {
  2351. $scope.protocolMappers = null;
  2352. $scope.grantedRealmRoles = null;
  2353. $scope.notGrantedRealmRoles = null;
  2354. $scope.grantedClientRoles = null;
  2355. $scope.notGrantedClientRoles = null;
  2356. $scope.targetClient = null;
  2357. $scope.oidcAccessToken = null;
  2358. $scope.oidcIDToken = null;
  2359. $scope.oidcUserInfo = null;
  2360. $scope.selectedTab = 0;
  2361. }
  2362. function updateState() {
  2363. // Compute scope parameter
  2364. $scope.scopeParam = 'openid';
  2365. for (var i = 0; i < $scope.assignedClientScopes.length; i++) {
  2366. var currentScopeParam = $scope.assignedClientScopes[i].name;
  2367. $scope.scopeParam = $scope.scopeParam + ' ' + currentScopeParam;
  2368. }
  2369. // Compute effective scopes
  2370. $scope.effectiveClientScopes = [];
  2371. for (var i = 0; i < clientDefaultClientScopes.length; i++) {
  2372. var currentScope = clientDefaultClientScopes[i];
  2373. $scope.effectiveClientScopes.push(currentScope);
  2374. }
  2375. for (var i = 0; i < $scope.assignedClientScopes.length; i++) {
  2376. var currentScope = $scope.assignedClientScopes[i];
  2377. $scope.effectiveClientScopes.push(currentScope);
  2378. }
  2379. // Clear the evaluation response
  2380. clearEvalResponse();
  2381. }
  2382. updateState();
  2383. $scope.addAppliedClientScope = function () {
  2384. $scope.selectedClientScopesToAdd = JSON.parse('[' + $scope.selectedClientScopes + ']');
  2385. for (var i = 0; i < $scope.selectedClientScopesToAdd.length; i++) {
  2386. var currentScope = $scope.selectedClientScopesToAdd[i];
  2387. $scope.assignedClientScopes.push(currentScope);
  2388. var index = ComponentUtils.findIndexById($scope.availableClientScopes, currentScope.id);
  2389. if (index > -1) {
  2390. $scope.availableClientScopes.splice(index, 1);
  2391. }
  2392. }
  2393. $scope.selectedClientScopes = [];
  2394. $scope.selectedClientScopesToAdd = [];
  2395. updateState();
  2396. };
  2397. $scope.deleteAppliedClientScope = function () {
  2398. $scope.selectedDefClientScopesToRemove = JSON.parse('[' + $scope.selectedDefClientScopes + ']');
  2399. for (var i = 0; i < $scope.selectedDefClientScopesToRemove.length; i++) {
  2400. var currentScope = $scope.selectedDefClientScopesToRemove[i];
  2401. $scope.availableClientScopes.push(currentScope);
  2402. var index = ComponentUtils.findIndexById($scope.assignedClientScopes, currentScope.id);
  2403. if (index > -1) {
  2404. $scope.assignedClientScopes.splice(index, 1);
  2405. }
  2406. }
  2407. $scope.selectedDefClientScopes = [];
  2408. $scope.selectedDefClientScopesToRemove = [];
  2409. updateState();
  2410. };
  2411. $scope.usersUiSelect = {
  2412. minimumInputLength: 1,
  2413. delay: 500,
  2414. allowClear: true,
  2415. query: function (query) {
  2416. var data = {results: []};
  2417. if ('' == query.term.trim()) {
  2418. query.callback(data);
  2419. return;
  2420. }
  2421. User.query({realm: $route.current.params.realm, search: query.term.trim(), max: 20}, function(response) {
  2422. data.results = response;
  2423. query.callback(data);
  2424. });
  2425. },
  2426. formatResult: function(object, container, query) {
  2427. object.text = object.username;
  2428. return object.username;
  2429. }
  2430. };
  2431. $scope.selectedUser = null;
  2432. $scope.selectUser = function(user) {
  2433. clearEvalResponse();
  2434. if (!user || !user.id) {
  2435. $scope.selectedUser = null;
  2436. $scope.userId = '';
  2437. return;
  2438. }
  2439. $scope.userId = user.id;
  2440. }
  2441. clientSelectControl($scope, $route.current.params.realm, Client);
  2442. $scope.selectedClient = null;
  2443. $scope.selectClient = function(client) {
  2444. console.log("selected client: ", client);
  2445. if (!client || !client.id) {
  2446. $scope.selectedClient = null;
  2447. return;
  2448. }
  2449. $scope.selectedClient = client;
  2450. updateScopeClientRoles();
  2451. }
  2452. $scope.sendEvaluationRequest = function () {
  2453. // Send request for retrieve protocolMappers
  2454. $scope.protocolMappers = ClientEvaluateProtocolMappers.query({
  2455. realm: realm.realm,
  2456. client: client.id,
  2457. scopeParam: $scope.scopeParam
  2458. });
  2459. // Send request for retrieve realmRoles
  2460. updateScopeRealmRoles();
  2461. // Send request for retrieve accessToken (in case user was selected)
  2462. if (client.protocol === 'openid-connect' && $scope.userId != null && $scope.userId !== '') {
  2463. var exampleRequestParams = {
  2464. realm: realm.realm,
  2465. client: client.id,
  2466. userId: $scope.userId,
  2467. scopeParam: $scope.scopeParam
  2468. };
  2469. var accessTokenUrl = ClientEvaluateGenerateExampleAccessToken.url(exampleRequestParams);
  2470. getPrettyJsonResponse(accessTokenUrl).then(function (result) {
  2471. $scope.oidcAccessToken = result;
  2472. });
  2473. var idTokenUrl = ClientEvaluateGenerateExampleIDToken.url(exampleRequestParams);
  2474. getPrettyJsonResponse(idTokenUrl).then(function (result) {
  2475. $scope.oidcIDToken = result;
  2476. });
  2477. var userInfoUrl = ClientEvaluateGenerateExampleUserInfo.url(exampleRequestParams);
  2478. getPrettyJsonResponse(userInfoUrl).then(function (result) {
  2479. $scope.oidcUserInfo = result;
  2480. });
  2481. }
  2482. $scope.showTab(1);
  2483. };
  2484. function getPrettyJsonResponse(url) {
  2485. return $http.get(url).then(function (response) {
  2486. if (response.data) {
  2487. var responseJson = angular.fromJson(response.data);
  2488. return angular.toJson(responseJson, true);
  2489. } else {
  2490. return null;
  2491. }
  2492. });
  2493. }
  2494. $scope.isResponseAvailable = function () {
  2495. return $scope.protocolMappers != null;
  2496. }
  2497. $scope.isAccessTokenAvailable = function () {
  2498. return $scope.oidcAccessToken != null;
  2499. }
  2500. $scope.isIDTokenAvailable = function () {
  2501. return $scope.oidcIDToken != null;
  2502. }
  2503. $scope.isUserInfoAvailable = function () {
  2504. return $scope.oidcUserInfo != null;
  2505. }
  2506. $scope.showTab = function (tab) {
  2507. $scope.selectedTab = tab;
  2508. $scope.tabCss = {
  2509. tab1: getTabCssClass(1, tab),
  2510. tab2: getTabCssClass(2, tab),
  2511. tab3: getTabCssClass(3, tab),
  2512. tab4: getTabCssClass(4, tab),
  2513. tab5: getTabCssClass(5, tab)
  2514. }
  2515. }
  2516. function getTabCssClass(tabNo, selectedTab) {
  2517. return (tabNo === selectedTab) ? 'active' : '';
  2518. }
  2519. $scope.protocolMappersShown = function () {
  2520. return $scope.selectedTab === 1;
  2521. }
  2522. $scope.rolesShown = function () {
  2523. return $scope.selectedTab === 2;
  2524. }
  2525. $scope.exampleTabInfo = function() {
  2526. switch ($scope.selectedTab) {
  2527. case 3:
  2528. return { isShown: true, value: $scope.oidcAccessToken}
  2529. case 4:
  2530. return { isShown: true, value: $scope.oidcIDToken}
  2531. case 5:
  2532. return { isShown: true, value: $scope.oidcUserInfo}
  2533. default:
  2534. return { isShown: false, value: null}
  2535. }
  2536. }
  2537. $scope.sortMappersByPriority = function(mapper) {
  2538. return $scope.mapperTypes[mapper.protocolMapper].priority;
  2539. }
  2540. // Roles
  2541. function updateScopeRealmRoles() {
  2542. $scope.grantedRealmRoles = ClientEvaluateGrantedRoles.query({
  2543. realm: realm.realm,
  2544. client: client.id,
  2545. roleContainer: realm.realm,
  2546. scopeParam: $scope.scopeParam
  2547. });
  2548. $scope.notGrantedRealmRoles = ClientEvaluateNotGrantedRoles.query({
  2549. realm: realm.realm,
  2550. client: client.id,
  2551. roleContainer: realm.realm,
  2552. scopeParam: $scope.scopeParam
  2553. });
  2554. }
  2555. function updateScopeClientRoles() {
  2556. if ($scope.selectedClient) {
  2557. $scope.grantedClientRoles = ClientEvaluateGrantedRoles.query({
  2558. realm: realm.realm,
  2559. client: client.id,
  2560. roleContainer: $scope.selectedClient.id,
  2561. scopeParam: $scope.scopeParam
  2562. });
  2563. $scope.notGrantedClientRoles = ClientEvaluateNotGrantedRoles.query({
  2564. realm: realm.realm,
  2565. client: client.id,
  2566. roleContainer: $scope.selectedClient.id,
  2567. scopeParam: $scope.scopeParam
  2568. });
  2569. } else {
  2570. $scope.grantedClientRoles = null;
  2571. $scope.notGrantedClientRoles = null;
  2572. }
  2573. }
  2574. });
  2575. module.controller('ClientScopeTabCtrl', function(Dialog, $scope, Current, Notifications, $location) {
  2576. $scope.removeClientScope = function() {
  2577. Dialog.confirmDelete($scope.clientScope.name, 'client scope', function() {
  2578. $scope.clientScope.$remove({
  2579. realm : Current.realm.realm,
  2580. clientScope : $scope.clientScope.id
  2581. }, function() {
  2582. $location.url("/realms/" + Current.realm.realm + "/client-scopes");
  2583. Notifications.success("The client scope has been deleted.");
  2584. });
  2585. });
  2586. };
  2587. });
  2588. module.controller('ClientScopeListCtrl', function($scope, realm, clientScopes, ClientScope, serverInfo, $route, Dialog, Notifications, $location) {
  2589. $scope.realm = realm;
  2590. $scope.clientScopes = clientScopes;
  2591. $scope.removeClientScope = function(clientScope) {
  2592. Dialog.confirmDelete(clientScope.name, 'client scope', function() {
  2593. ClientScope.remove({
  2594. realm : realm.realm,
  2595. clientScope : clientScope.id
  2596. }, function() {
  2597. $route.reload();
  2598. Notifications.success("The client scope been deleted.");
  2599. });
  2600. });
  2601. };
  2602. });
  2603. module.controller('ClientScopesRealmDefaultCtrl', function($scope, realm, Realm, clientScopes, realmDefaultClientScopes, RealmDefaultClientScopes,
  2604. realmOptionalClientScopes, RealmOptionalClientScopes, serverInfo, $route, Dialog, Notifications, $location) {
  2605. console.log('ClientScopesRealmDefaultCtrl');
  2606. $scope.realm = realm;
  2607. $scope.realmDefaultClientScopes = realmDefaultClientScopes;
  2608. $scope.realmOptionalClientScopes = realmOptionalClientScopes;
  2609. $scope.availableClientScopes = [];
  2610. $scope.selectedDefaultClientScopes = [];
  2611. $scope.selectedDefDefaultClientScopes = [];
  2612. $scope.selectedOptionalClientScopes = [];
  2613. $scope.selectedDefOptionalClientScopes = [];
  2614. // Populate available client scopes. Available client scopes are neither already assigned to 'default' or 'optional'
  2615. for (var i = 0; i < clientScopes.length; i++) {
  2616. var scopeName = clientScopes[i].name;
  2617. var available = true;
  2618. for (var j = 0; j < $scope.realmDefaultClientScopes.length; j++) {
  2619. if (scopeName === $scope.realmDefaultClientScopes[j].name) {
  2620. available = false;
  2621. }
  2622. }
  2623. for (var j = 0; j < $scope.realmOptionalClientScopes.length; j++) {
  2624. if (scopeName === $scope.realmOptionalClientScopes[j].name) {
  2625. available = false;
  2626. }
  2627. }
  2628. if (available) {
  2629. $scope.availableClientScopes.push(clientScopes[i]);
  2630. }
  2631. }
  2632. $scope.addDefaultClientScope = function () {
  2633. $scope.selectedDefaultClientScopesToAdd = JSON.parse('[' + $scope.selectedDefaultClientScopes + ']');
  2634. toAdd = $scope.selectedDefaultClientScopesToAdd.length;
  2635. for (var i = 0; i < $scope.selectedDefaultClientScopesToAdd.length; i++) {
  2636. var currentScope = $scope.selectedDefaultClientScopesToAdd[i];
  2637. RealmDefaultClientScopes.update({
  2638. realm : realm.realm,
  2639. clientScopeId : currentScope.id
  2640. }, function () {
  2641. toAdd = toAdd - 1;
  2642. console.log('toAdd: ' + toAdd);
  2643. if (toAdd === 0) {
  2644. $route.reload();
  2645. Notifications.success("Realm default scopes updated.");
  2646. }
  2647. });
  2648. }
  2649. $scope.selectedDefaultClientScopesToAdd = [];
  2650. };
  2651. $scope.deleteDefaultClientScope = function () {
  2652. $scope.selectedDefDefaultClientScopesToRemove = JSON.parse('[' + $scope.selectedDefDefaultClientScopes + ']');
  2653. toRemove = $scope.selectedDefDefaultClientScopesToRemove.length;
  2654. for (var i = 0; i < $scope.selectedDefDefaultClientScopesToRemove.length; i++) {
  2655. var currentScope = $scope.selectedDefDefaultClientScopesToRemove[i];
  2656. RealmDefaultClientScopes.remove({
  2657. realm : realm.realm,
  2658. clientScopeId : currentScope.id
  2659. }, function () {
  2660. toRemove = toRemove - 1;
  2661. if (toRemove === 0) {
  2662. $route.reload();
  2663. Notifications.success("Realm default scopes updated.");
  2664. }
  2665. });
  2666. }
  2667. $scope.selectedDefDefaultClientScopesToRemove = [];
  2668. };
  2669. $scope.addOptionalClientScope = function () {
  2670. $scope.selectedOptionalClientScopesToAdd = JSON.parse('[' + $scope.selectedOptionalClientScopes + ']');
  2671. toAdd = $scope.selectedOptionalClientScopesToAdd.length;
  2672. for (var i = 0; i < $scope.selectedOptionalClientScopesToAdd.length; i++) {
  2673. var currentScope = $scope.selectedOptionalClientScopesToAdd[i];
  2674. RealmOptionalClientScopes.update({
  2675. realm : realm.realm,
  2676. clientScopeId : currentScope.id
  2677. }, function () {
  2678. toAdd = toAdd - 1;
  2679. console.log('toAdd: ' + toAdd);
  2680. if (toAdd === 0) {
  2681. $route.reload();
  2682. Notifications.success("Realm optional scopes updated.");
  2683. }
  2684. });
  2685. }
  2686. $scope.selectedOptionalClientScopesToAdd = [];
  2687. };
  2688. $scope.deleteOptionalClientScope = function () {
  2689. $scope.selectedDefOptionalClientScopesToRemove = JSON.parse('[' + $scope.selectedDefOptionalClientScopes + ']');
  2690. toRemove = $scope.selectedDefOptionalClientScopesToRemove.length;
  2691. for (var i = 0; i < $scope.selectedDefOptionalClientScopesToRemove.length; i++) {
  2692. var currentScope = $scope.selectedDefOptionalClientScopesToRemove[i];
  2693. RealmOptionalClientScopes.remove({
  2694. realm : realm.realm,
  2695. clientScopeId : currentScope.id
  2696. }, function () {
  2697. toRemove = toRemove - 1;
  2698. if (toRemove === 0) {
  2699. $route.reload();
  2700. Notifications.success("Realm optional scopes updated.");
  2701. }
  2702. });
  2703. }
  2704. $scope.selectedDefOptionalClientScopesToRemove = [];
  2705. };
  2706. });
  2707. module.controller('ClientScopeDetailCtrl', function($scope, realm, clientScope, $route, serverInfo, ClientScope, $location, $modal, Dialog, Notifications) {
  2708. $scope.protocols = serverInfo.listProviderIds('login-protocol');
  2709. $scope.realm = realm;
  2710. $scope.create = !clientScope.name;
  2711. function updateProperties() {
  2712. if (!$scope.clientScope.attributes) {
  2713. $scope.clientScope.attributes = {};
  2714. }
  2715. if ($scope.clientScope.protocol) {
  2716. $scope.protocol = $scope.protocols[$scope.protocols.indexOf($scope.clientScope.protocol)];
  2717. } else {
  2718. $scope.protocol = $scope.protocols[0];
  2719. }
  2720. if ($scope.clientScope.attributes["display.on.consent.screen"]) {
  2721. if ($scope.clientScope.attributes["display.on.consent.screen"] == "true") {
  2722. $scope.displayOnConsentScreen = true;
  2723. } else {
  2724. $scope.displayOnConsentScreen = false;
  2725. }
  2726. } else {
  2727. $scope.displayOnConsentScreen = true;
  2728. }
  2729. if ($scope.clientScope.attributes["include.in.token.scope"]) {
  2730. if ($scope.clientScope.attributes["include.in.token.scope"] == "true") {
  2731. $scope.includeInTokenScope = true;
  2732. } else {
  2733. $scope.includeInTokenScope = false;
  2734. }
  2735. } else {
  2736. $scope.includeInTokenScope = true;
  2737. }
  2738. }
  2739. if (!$scope.create) {
  2740. $scope.clientScope = angular.copy(clientScope);
  2741. } else {
  2742. $scope.clientScope = {};
  2743. }
  2744. updateProperties();
  2745. $scope.switchChange = function() {
  2746. $scope.changed = true;
  2747. }
  2748. $scope.changeProtocol = function() {
  2749. if ($scope.protocol == "openid-connect") {
  2750. $scope.clientScope.protocol = "openid-connect";
  2751. } else if ($scope.protocol == "saml") {
  2752. $scope.clientScope.protocol = "saml";
  2753. }
  2754. };
  2755. $scope.$watch(function() {
  2756. return $location.path();
  2757. }, function() {
  2758. $scope.path = $location.path().substring(1).split("/");
  2759. });
  2760. function isChanged() {
  2761. if (!angular.equals($scope.clientScope, clientScope)) {
  2762. return true;
  2763. }
  2764. return false;
  2765. }
  2766. $scope.$watch('clientScope', function() {
  2767. $scope.changed = isChanged();
  2768. }, true);
  2769. $scope.save = function() {
  2770. $scope.clientScope.protocol = $scope.protocol;
  2771. if ($scope.displayOnConsentScreen == true) {
  2772. $scope.clientScope.attributes["display.on.consent.screen"] = "true";
  2773. } else {
  2774. $scope.clientScope.attributes["display.on.consent.screen"] = "false";
  2775. }
  2776. if ($scope.includeInTokenScope == true) {
  2777. $scope.clientScope.attributes["include.in.token.scope"] = "true";
  2778. } else {
  2779. $scope.clientScope.attributes["include.in.token.scope"] = "false";
  2780. }
  2781. if ($scope.create) {
  2782. ClientScope.save({
  2783. realm: realm.realm,
  2784. clientScope: ''
  2785. }, $scope.clientScope, function (data, headers) {
  2786. $scope.changed = false;
  2787. var l = headers().location;
  2788. var id = l.substring(l.lastIndexOf("/") + 1);
  2789. $location.url("/realms/" + realm.realm + "/client-scopes/" + id);
  2790. Notifications.success("The client scope has been created.");
  2791. });
  2792. } else {
  2793. ClientScope.update({
  2794. realm : realm.realm,
  2795. clientScope : clientScope.id
  2796. }, $scope.clientScope, function() {
  2797. $scope.changed = false;
  2798. clientScope = angular.copy($scope.clientScope);
  2799. $location.url("/realms/" + realm.realm + "/client-scopes/" + clientScope.id);
  2800. Notifications.success("Your changes have been saved to the client scope.");
  2801. });
  2802. }
  2803. };
  2804. $scope.reset = function() {
  2805. $route.reload();
  2806. };
  2807. $scope.cancel = function() {
  2808. $location.url("/realms/" + realm.realm + "/client-scopes");
  2809. };
  2810. });
  2811. module.controller('ClientScopeProtocolMapperListCtrl', function($scope, realm, clientScope, serverInfo,
  2812. ClientScopeProtocolMappersByProtocol, ClientScopeProtocolMapper,
  2813. $route, Dialog, Notifications) {
  2814. $scope.realm = realm;
  2815. $scope.clientScope = clientScope;
  2816. if (clientScope.protocol == null) {
  2817. clientScope.protocol = 'openid-connect';
  2818. }
  2819. var protocolMappers = serverInfo.protocolMapperTypes[clientScope.protocol];
  2820. var mapperTypes = {};
  2821. for (var i = 0; i < protocolMappers.length; i++) {
  2822. mapperTypes[protocolMappers[i].id] = protocolMappers[i];
  2823. }
  2824. $scope.mapperTypes = mapperTypes;
  2825. $scope.removeMapper = function(mapper) {
  2826. console.debug(mapper);
  2827. Dialog.confirmDelete(mapper.name, 'mapper', function() {
  2828. ClientScopeProtocolMapper.remove({ realm: realm.realm, clientScope: clientScope.id, id : mapper.id }, function() {
  2829. Notifications.success("The mapper has been deleted.");
  2830. $route.reload();
  2831. });
  2832. });
  2833. };
  2834. $scope.sortMappersByPriority = function(mapper) {
  2835. return $scope.mapperTypes[mapper.protocolMapper].priority;
  2836. }
  2837. var updateMappers = function() {
  2838. $scope.mappers = ClientScopeProtocolMappersByProtocol.query({realm : realm.realm, clientScope : clientScope.id, protocol : clientScope.protocol});
  2839. };
  2840. updateMappers();
  2841. });
  2842. module.controller('ClientScopeProtocolMapperCtrl', function($scope, realm, serverInfo, clientScope, mapper, clients, ClientScopeProtocolMapper, Notifications, Dialog, $location, $route) {
  2843. $scope.realm = realm;
  2844. $scope.clients = clients;
  2845. if (clientScope.protocol == null) {
  2846. clientScope.protocol = 'openid-connect';
  2847. }
  2848. $scope.model = {
  2849. realm: realm,
  2850. clientScope: clientScope,
  2851. create: false,
  2852. protocol: clientScope.protocol,
  2853. mapper: angular.copy(mapper),
  2854. changed: false
  2855. }
  2856. var protocolMappers = serverInfo.protocolMapperTypes[clientScope.protocol];
  2857. for (var i = 0; i < protocolMappers.length; i++) {
  2858. if (protocolMappers[i].id == mapper.protocolMapper) {
  2859. $scope.model.mapperType = protocolMappers[i];
  2860. }
  2861. }
  2862. $scope.$watch(function() {
  2863. return $location.path();
  2864. }, function() {
  2865. $scope.path = $location.path().substring(1).split("/");
  2866. });
  2867. $scope.$watch('model.mapper', function() {
  2868. if (!angular.equals($scope.model.mapper, mapper)) {
  2869. $scope.model.changed = true;
  2870. }
  2871. }, true);
  2872. $scope.save = function() {
  2873. ClientScopeProtocolMapper.update({
  2874. realm : realm.realm,
  2875. clientScope: clientScope.id,
  2876. id : mapper.id
  2877. }, $scope.model.mapper, function() {
  2878. $route.reload();
  2879. Notifications.success("Your changes have been saved.");
  2880. });
  2881. };
  2882. $scope.reset = function() {
  2883. $scope.model.mapper = angular.copy(mapper);
  2884. $scope.model.changed = false;
  2885. };
  2886. $scope.cancel = function() {
  2887. //$location.url("/realms");
  2888. window.history.back();
  2889. };
  2890. $scope.remove = function() {
  2891. Dialog.confirmDelete($scope.model.mapper.name, 'mapper', function() {
  2892. ClientScopeProtocolMapper.remove({ realm: realm.realm, clientScope: clientScope.id, id : $scope.model.mapper.id }, function() {
  2893. Notifications.success("The mapper has been deleted.");
  2894. $location.url("/realms/" + realm.realm + '/client-scopes/' + clientScope.id + "/mappers");
  2895. });
  2896. });
  2897. };
  2898. });
  2899. module.controller('ClientScopeProtocolMapperCreateCtrl', function($scope, realm, serverInfo, clientScope, clients, ClientScopeProtocolMapper, Notifications, Dialog, $location) {
  2900. $scope.realm = realm;
  2901. $scope.clients = clients;
  2902. if (clientScope.protocol == null) {
  2903. clientScope.protocol = 'openid-connect';
  2904. }
  2905. var protocol = clientScope.protocol;
  2906. $scope.model = {
  2907. realm: realm,
  2908. clientScope: clientScope,
  2909. create: true,
  2910. protocol: clientScope.protocol,
  2911. mapper: { protocol : clientScope.protocol, config: {}},
  2912. changed: false,
  2913. mapperTypes: serverInfo.protocolMapperTypes[protocol]
  2914. }
  2915. // apply default configurations on change for selected protocolmapper type.
  2916. $scope.$watch('model.mapperType', function() {
  2917. var currentMapperType = $scope.model.mapperType;
  2918. var defaultConfig = {};
  2919. if (currentMapperType && Array.isArray(currentMapperType.properties)) {
  2920. for (var i = 0; i < currentMapperType.properties.length; i++) {
  2921. var property = currentMapperType.properties[i];
  2922. if (property && property.name && property.defaultValue) {
  2923. defaultConfig[property.name] = property.defaultValue;
  2924. }
  2925. }
  2926. }
  2927. $scope.model.mapper.config = defaultConfig;
  2928. }, true);
  2929. $scope.model.mapperType = $scope.model.mapperTypes[0];
  2930. $scope.$watch(function() {
  2931. return $location.path();
  2932. }, function() {
  2933. $scope.path = $location.path().substring(1).split("/");
  2934. });
  2935. $scope.save = function() {
  2936. $scope.model.mapper.protocolMapper = $scope.model.mapperType.id;
  2937. ClientScopeProtocolMapper.save({
  2938. realm : realm.realm, clientScope: clientScope.id
  2939. }, $scope.model.mapper, function(data, headers) {
  2940. var l = headers().location;
  2941. var id = l.substring(l.lastIndexOf("/") + 1);
  2942. $location.url("/realms/" + realm.realm + '/client-scopes/' + clientScope.id + "/mappers/" + id);
  2943. Notifications.success("Mapper has been created.");
  2944. });
  2945. };
  2946. $scope.cancel = function() {
  2947. //$location.url("/realms");
  2948. window.history.back();
  2949. };
  2950. });
  2951. module.controller('ClientScopeAddBuiltinProtocolMapperCtrl', function($scope, realm, clientScope, serverInfo,
  2952. ClientScopeProtocolMappersByProtocol,
  2953. $http, $location, Dialog, Notifications) {
  2954. $scope.realm = realm;
  2955. $scope.clientScope = clientScope;
  2956. if (clientScope.protocol == null) {
  2957. clientScope.protocol = 'openid-connect';
  2958. }
  2959. var protocolMappers = serverInfo.protocolMapperTypes[clientScope.protocol];
  2960. var mapperTypes = {};
  2961. for (var i = 0; i < protocolMappers.length; i++) {
  2962. mapperTypes[protocolMappers[i].id] = protocolMappers[i];
  2963. }
  2964. $scope.mapperTypes = mapperTypes;
  2965. var updateMappers = function() {
  2966. var clientMappers = ClientScopeProtocolMappersByProtocol.query({realm : realm.realm, clientScope : clientScope.id, protocol : clientScope.protocol}, function() {
  2967. var builtinMappers = serverInfo.builtinProtocolMappers[clientScope.protocol];
  2968. for (var i = 0; i < clientMappers.length; i++) {
  2969. for (var j = 0; j < builtinMappers.length; j++) {
  2970. if (builtinMappers[j].name == clientMappers[i].name
  2971. && builtinMappers[j].protocolMapper == clientMappers[i].protocolMapper) {
  2972. builtinMappers.splice(j, 1);
  2973. break;
  2974. }
  2975. }
  2976. }
  2977. $scope.mappers = builtinMappers;
  2978. for (var i = 0; i < $scope.mappers.length; i++) {
  2979. $scope.mappers[i].isChecked = false;
  2980. }
  2981. });
  2982. };
  2983. updateMappers();
  2984. $scope.add = function() {
  2985. var toAdd = [];
  2986. for (var i = 0; i < $scope.mappers.length; i++) {
  2987. if ($scope.mappers[i].isChecked) {
  2988. delete $scope.mappers[i].isChecked;
  2989. toAdd.push($scope.mappers[i]);
  2990. }
  2991. }
  2992. $http.post(authUrl + '/admin/realms/' + realm.realm + '/client-scopes/' + clientScope.id + '/protocol-mappers/add-models',
  2993. toAdd).then(function() {
  2994. Notifications.success("Mappers added");
  2995. $location.url('/realms/' + realm.realm + '/client-scopes/' + clientScope.id + '/mappers');
  2996. }).catch(function() {
  2997. Notifications.error("Error adding mappers");
  2998. $location.url('/realms/' + realm.realm + '/client-scopes/' + clientScope.id + '/mappers');
  2999. });
  3000. };
  3001. });
  3002. module.controller('ClientScopeScopeMappingCtrl', function($scope, $http, $route, realm, clientScope, Notifications,
  3003. ClientScope, Client,
  3004. ClientScopeRealmScopeMapping, ClientScopeClientScopeMapping, ClientRole,
  3005. ClientScopeAvailableRealmScopeMapping, ClientScopeAvailableClientScopeMapping,
  3006. ClientScopeCompositeRealmScopeMapping, ClientScopeCompositeClientScopeMapping) {
  3007. $scope.realm = realm;
  3008. $scope.clientScope = angular.copy(clientScope);
  3009. $scope.selectedRealmRoles = [];
  3010. $scope.selectedRealmMappings = [];
  3011. $scope.realmMappings = [];
  3012. $scope.clientRoles = [];
  3013. $scope.clientComposite = [];
  3014. $scope.selectedClientRoles = [];
  3015. $scope.selectedClientMappings = [];
  3016. $scope.clientMappings = [];
  3017. $scope.dummymodel = [];
  3018. $scope.selectedClient = null;
  3019. function updateScopeRealmRoles() {
  3020. $scope.realmRoles = ClientScopeAvailableRealmScopeMapping.query({realm : realm.realm, clientScope : clientScope.id});
  3021. $scope.realmMappings = ClientScopeRealmScopeMapping.query({realm : realm.realm, clientScope : clientScope.id});
  3022. $scope.realmComposite = ClientScopeCompositeRealmScopeMapping.query({realm : realm.realm, clientScope : clientScope.id});
  3023. }
  3024. function updateScopeClientRoles() {
  3025. if ($scope.selectedClient) {
  3026. $scope.clientRoles = ClientScopeAvailableClientScopeMapping.query({realm : realm.realm, clientScope : clientScope.id, targetClient : $scope.selectedClient.id});
  3027. $scope.clientMappings = ClientScopeClientScopeMapping.query({realm : realm.realm, clientScope : clientScope.id, targetClient : $scope.selectedClient.id});
  3028. $scope.clientComposite = ClientScopeCompositeClientScopeMapping.query({realm : realm.realm, clientScope : clientScope.id, targetClient : $scope.selectedClient.id});
  3029. } else {
  3030. $scope.clientRoles = null;
  3031. $scope.clientMappings = null;
  3032. $scope.clientComposite = null;
  3033. }
  3034. }
  3035. $scope.changeClient = function(client) {
  3036. if (!client || !client.id) {
  3037. $scope.selectedClient = null;
  3038. return;
  3039. }
  3040. $scope.selectedClient = client;
  3041. updateScopeClientRoles();
  3042. };
  3043. $scope.addRealmRole = function() {
  3044. $scope.selectedRealmRolesToAdd = JSON.parse('[' + $scope.selectedRealmRoles + ']');
  3045. $scope.selectedRealmRoles = [];
  3046. $http.post(authUrl + '/admin/realms/' + realm.realm + '/client-scopes/' + clientScope.id + '/scope-mappings/realm',
  3047. $scope.selectedRealmRolesToAdd).then(function() {
  3048. updateScopeRealmRoles();
  3049. $scope.selectedRealmRolesToAdd = [];
  3050. Notifications.success("Scope mappings updated.");
  3051. });
  3052. };
  3053. $scope.deleteRealmRole = function() {
  3054. $scope.selectedRealmMappingsToRemove = JSON.parse('[' + $scope.selectedRealmMappings + ']');
  3055. $scope.selectedRealmMappings = [];
  3056. $http.delete(authUrl + '/admin/realms/' + realm.realm + '/client-scopes/' + clientScope.id + '/scope-mappings/realm',
  3057. {data : $scope.selectedRealmMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function () {
  3058. updateScopeRealmRoles();
  3059. $scope.selectedRealmMappingsToRemove = [];
  3060. Notifications.success("Scope mappings updated.");
  3061. });
  3062. };
  3063. $scope.addClientRole = function() {
  3064. $scope.selectedClientRolesToAdd = JSON.parse('[' + $scope.selectedClientRoles + ']');
  3065. $scope.selectedClientRoles = [];
  3066. $http.post(authUrl + '/admin/realms/' + realm.realm + '/client-scopes/' + clientScope.id + '/scope-mappings/clients/' + $scope.selectedClient.id,
  3067. $scope.selectedClientRolesToAdd).then(function () {
  3068. updateScopeClientRoles();
  3069. $scope.selectedClientRolesToAdd = [];
  3070. Notifications.success("Scope mappings updated.");
  3071. });
  3072. };
  3073. $scope.deleteClientRole = function() {
  3074. $scope.selectedClientMappingsToRemove = JSON.parse('[' + $scope.selectedClientMappings + ']');
  3075. $scope.selectedClientMappings = [];
  3076. $http.delete(authUrl + '/admin/realms/' + realm.realm + '/client-scopes/' + clientScope.id + '/scope-mappings/clients/' + $scope.selectedClient.id,
  3077. {data : $scope.selectedClientMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function () {
  3078. updateScopeClientRoles();
  3079. $scope.selectedClientMappingsToRemove = [];
  3080. Notifications.success("Scope mappings updated.");
  3081. });
  3082. };
  3083. clientSelectControl($scope, $route.current.params.realm, Client);
  3084. updateScopeRealmRoles();
  3085. });
  3086. module.controller('ClientStoresCtrl', function($scope, $location, $route, realm, serverInfo, Components, Notifications, Dialog) {
  3087. console.log('ClientStoresCtrl ++++****');
  3088. $scope.realm = realm;
  3089. $scope.providers = serverInfo.componentTypes['org.keycloak.storage.client.ClientStorageProvider'];
  3090. $scope.clientStorageProviders = serverInfo.componentTypes['org.keycloak.storage.client.ClientStorageProvider'];
  3091. $scope.instancesLoaded = false;
  3092. if (!$scope.providers) $scope.providers = [];
  3093. $scope.addProvider = function(provider) {
  3094. console.log('Add provider: ' + provider.id);
  3095. $location.url("/create/client-storage/" + realm.realm + "/providers/" + provider.id);
  3096. };
  3097. $scope.getInstanceLink = function(instance) {
  3098. return "/realms/" + realm.realm + "/client-storage/providers/" + instance.providerId + "/" + instance.id;
  3099. }
  3100. $scope.getInstanceName = function(instance) {
  3101. return instance.name;
  3102. }
  3103. $scope.getInstanceProvider = function(instance) {
  3104. return instance.providerId;
  3105. }
  3106. $scope.isProviderEnabled = function(instance) {
  3107. return !instance.config['enabled'] || instance.config['enabled'][0] == 'true';
  3108. }
  3109. $scope.getInstancePriority = function(instance) {
  3110. if (!instance.config['priority']) {
  3111. return "0";
  3112. }
  3113. return instance.config['priority'][0];
  3114. }
  3115. Components.query({realm: realm.realm,
  3116. parent: realm.id,
  3117. type: 'org.keycloak.storage.client.ClientStorageProvider'
  3118. }, function(data) {
  3119. $scope.instances = data;
  3120. $scope.instancesLoaded = true;
  3121. });
  3122. $scope.removeInstance = function(instance) {
  3123. Dialog.confirmDelete(instance.name, 'client storage provider', function() {
  3124. Components.remove({
  3125. realm : realm.realm,
  3126. componentId : instance.id
  3127. }, function() {
  3128. $route.reload();
  3129. Notifications.success("The provider has been deleted.");
  3130. });
  3131. });
  3132. };
  3133. });
  3134. module.controller('GenericClientStorageCtrl', function($scope, $location, Notifications, $route, Dialog, realm,
  3135. serverInfo, instance, providerId, Components) {
  3136. console.log('GenericClientStorageCtrl');
  3137. console.log('providerId: ' + providerId);
  3138. $scope.create = !instance.providerId;
  3139. console.log('create: ' + $scope.create);
  3140. var providers = serverInfo.componentTypes['org.keycloak.storage.client.ClientStorageProvider'];
  3141. console.log('providers length ' + providers.length);
  3142. var providerFactory = null;
  3143. for (var i = 0; i < providers.length; i++) {
  3144. var p = providers[i];
  3145. console.log('provider: ' + p.id);
  3146. if (p.id == providerId) {
  3147. $scope.providerFactory = p;
  3148. providerFactory = p;
  3149. break;
  3150. }
  3151. }
  3152. $scope.changed = false;
  3153. console.log("providerFactory: " + providerFactory.id);
  3154. function initClientStorageSettings() {
  3155. if ($scope.create) {
  3156. $scope.changed = true;
  3157. instance.name = providerFactory.id;
  3158. instance.providerId = providerFactory.id;
  3159. instance.providerType = 'org.keycloak.storage.client.ClientStorageProvider';
  3160. instance.parentId = realm.id;
  3161. instance.config = {
  3162. };
  3163. instance.config['priority'] = ["0"];
  3164. instance.config['enabled'] = ["true"];
  3165. $scope.fullSyncEnabled = false;
  3166. $scope.changedSyncEnabled = false;
  3167. instance.config['cachePolicy'] = ['DEFAULT'];
  3168. instance.config['evictionDay'] = [''];
  3169. instance.config['evictionHour'] = [''];
  3170. instance.config['evictionMinute'] = [''];
  3171. instance.config['maxLifespan'] = [''];
  3172. if (providerFactory.properties) {
  3173. for (var i = 0; i < providerFactory.properties.length; i++) {
  3174. var configProperty = providerFactory.properties[i];
  3175. if (configProperty.defaultValue) {
  3176. instance.config[configProperty.name] = [configProperty.defaultValue];
  3177. } else {
  3178. instance.config[configProperty.name] = [''];
  3179. }
  3180. }
  3181. }
  3182. } else {
  3183. $scope.changed = false;
  3184. if (!instance.config['enabled']) {
  3185. instance.config['enabled'] = ['true'];
  3186. }
  3187. if (!instance.config['cachePolicy']) {
  3188. instance.config['cachePolicy'] = ['DEFAULT'];
  3189. }
  3190. if (!instance.config['evictionDay']) {
  3191. instance.config['evictionDay'] = [''];
  3192. }
  3193. if (!instance.config['evictionHour']) {
  3194. instance.config['evictionHour'] = [''];
  3195. }
  3196. if (!instance.config['evictionMinute']) {
  3197. instance.config['evictionMinute'] = [''];
  3198. }
  3199. if (!instance.config['maxLifespan']) {
  3200. instance.config['maxLifespan'] = [''];
  3201. }
  3202. if (!instance.config['priority']) {
  3203. instance.config['priority'] = ['0'];
  3204. }
  3205. if (providerFactory.properties) {
  3206. for (var i = 0; i < providerFactory.properties.length; i++) {
  3207. var configProperty = providerFactory.properties[i];
  3208. if (!instance.config[configProperty.name]) {
  3209. instance.config[configProperty.name] = [''];
  3210. }
  3211. }
  3212. }
  3213. }
  3214. }
  3215. initClientStorageSettings();
  3216. $scope.instance = angular.copy(instance);
  3217. $scope.realm = realm;
  3218. $scope.$watch('instance', function() {
  3219. if (!angular.equals($scope.instance, instance)) {
  3220. $scope.changed = true;
  3221. }
  3222. }, true);
  3223. $scope.save = function() {
  3224. console.log('save provider');
  3225. $scope.changed = false;
  3226. if ($scope.create) {
  3227. console.log('saving new provider');
  3228. Components.save({realm: realm.realm}, $scope.instance, function (data, headers) {
  3229. var l = headers().location;
  3230. var id = l.substring(l.lastIndexOf("/") + 1);
  3231. $location.url("/realms/" + realm.realm + "/client-storage/providers/" + $scope.instance.providerId + "/" + id);
  3232. Notifications.success("The provider has been created.");
  3233. });
  3234. } else {
  3235. console.log('update existing provider');
  3236. Components.update({realm: realm.realm,
  3237. componentId: instance.id
  3238. },
  3239. $scope.instance, function () {
  3240. $route.reload();
  3241. Notifications.success("The provider has been updated.");
  3242. });
  3243. }
  3244. };
  3245. $scope.reset = function() {
  3246. $route.reload();
  3247. };
  3248. $scope.cancel = function() {
  3249. console.log('cancel');
  3250. if ($scope.create) {
  3251. $location.url("/realms/" + realm.realm + "/client-stores");
  3252. } else {
  3253. $route.reload();
  3254. }
  3255. };
  3256. });