mvcAuth.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: ps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2011
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  9. // Cognos and the Cognos logo are trademarks of Cognos ULC, (formerly Cognos Incorporated).
  10. //
  11. // MVC
  12. // Entry point to perform simultaneous LOGON/LOGOFF in an MVC environment
  13. //
  14. function mvcCreateAuthFrame(authType) {
  15. var iframeId = "mvcAuthFrame" + authType;
  16. var iframe;
  17. if (g_PS_browser == 'ie') {
  18. iframe = document.createElement("<iframe id='" + iframeId + "' name='"+ iframeId + "'/>");
  19. } else {
  20. iframe = document.createElement("iframe");
  21. iframe.setAttribute("id", iframeId);
  22. iframe.setAttribute("name", iframeId);
  23. }
  24. iframe.style.width = "1px";
  25. iframe.style.height = "1px";
  26. iframe.style.position="absolute";
  27. iframe.style.top = -100 + "px";
  28. iframe.style.left = -100 + "px";
  29. iframe.src = "about:blank";
  30. document.body.appendChild(iframe);
  31. // Register the event to sync...
  32. if (document.addEventListener) {
  33. iframe.addEventListener("load", function(event){authFrameLoaded(event);}, false);
  34. } else if (document.attachEvent) {
  35. iframe.attachEvent("onload", function(event){authFrameLoaded(event);});
  36. }
  37. return iframeId;
  38. }
  39. function authFrameLoaded() {
  40. if (mainAuthForm != null) {
  41. mainAuthForm.submit();
  42. mainAuthForm = null;
  43. }
  44. }
  45. var mainAuthForm = null;
  46. function mvcDoSimultaneousLogin(form) {
  47. function allowParams(e) {
  48. var name = (!e.disabled && e.name != null && (e.name.lastIndexOf("CAM") == 0 || e.name.lastIndexOf("h_CAM") == 0)) ? e.name : null;
  49. return (name != null && name != "");
  50. }
  51. mainAuthForm = form;
  52. if (!g_PS_mvc_disable_autologon) {
  53. var mvcAuthForm = document.createElement("form");
  54. mvcAuthForm.setAttribute("name", "mvcLoginForm");
  55. mvcAuthForm.setAttribute("action", g_PS_mvc_remote_gateway);
  56. mvcAuthForm.setAttribute("method", "POST");
  57. mvcAuthForm.setAttribute("target", mvcCreateAuthFrame("Login"));
  58. mvcAuthForm.style.margin = "0px";
  59. if (form != null) {
  60. for (var i = 0; i < form.elements.length; i++) {
  61. var e = form.elements[i];
  62. if (allowParams(e)) {
  63. var name = null;
  64. var value = null;
  65. switch (e.type) {
  66. case "select-one":
  67. if (e.selectedIndex >= 0) {
  68. name = e.name;
  69. value = e.value;
  70. }
  71. break;
  72. case "text":
  73. case "textarea":
  74. case "password":
  75. case "hidden":
  76. case "submit":
  77. if (e.value != null) {
  78. name = e.name;
  79. value = e.value;
  80. }
  81. break;
  82. case "button":
  83. default:
  84. break;
  85. }
  86. if (name != null) {
  87. var input = document.createElement("input");
  88. input.setAttribute("type", "hidden");
  89. input.setAttribute("name", name);
  90. input.setAttribute("value", value);
  91. mvcAuthForm.appendChild(input);
  92. }
  93. }
  94. }
  95. }
  96. document.body.appendChild(mvcAuthForm);
  97. mvcAuthForm.submit();
  98. } else {
  99. mainAuthForm.submit();
  100. }
  101. }
  102. function mvcDoSimultaneousLogoff(logoffForm) {
  103. var mvcAuthForm = document.createElement("form");
  104. mvcAuthForm.setAttribute("name", "mvcLoginForm");
  105. mvcAuthForm.setAttribute("action", g_PS_mvc_remote_gateway);
  106. mvcAuthForm.setAttribute("method", "POST");
  107. mvcAuthForm.setAttribute("target", mvcCreateAuthFrame("Logoff"));
  108. mvcAuthForm.style.margin = "0px";
  109. for (i in logoffForm) {
  110. var input = document.createElement("input");
  111. input.setAttribute("type", "hidden");
  112. input.setAttribute("name", i);
  113. input.setAttribute("value", logoffForm[i]);
  114. mvcAuthForm.appendChild(input);
  115. }
  116. document.body.appendChild(mvcAuthForm);
  117. mvcAuthForm.submit();
  118. }