sso.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!DOCTYPE html>
  2. <html>
  3. <head lang="en">
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <!--<script src="res/framework/mootools/mootools-core-1.4.5-full-nocompat.js"></script>-->
  7. <!--<script src="res/framework/mootools/mootools-more-1.4.0.1-all_2.js"></script>-->
  8. <script src="res/framework/mootools/mootools-1.6.0.min.js"></script>
  9. <script src="res/common.js?v=0.3.25"></script>
  10. <script>
  11. function getServiceAddress(config, callback){
  12. if (typeOf(config.center)=="object"){
  13. getServiceAddressConfigObject(callback);
  14. }else if (typeOf(config.center)=="array"){
  15. var center = chooseCenter(config);
  16. if (center){
  17. getServiceAddressConfigObject(callback, center);
  18. }else{
  19. getServiceAddressConfigArray(config, callback);
  20. }
  21. //this.getServiceAddressConfigArray(callback);
  22. }
  23. }
  24. function chooseCenter(config){
  25. var host = window.location.host;
  26. var center = null;
  27. for (var i=0; i<config.center.length; i++){
  28. var ct = config.center[i];
  29. if (ct.webHost==host){
  30. center = ct;
  31. break;
  32. }
  33. }
  34. return center;
  35. }
  36. function getServiceAddressConfigArray(config, callback) {
  37. var requests = [];
  38. config.center.each(function(center){
  39. requests.push(
  40. getServiceAddressConfigObject(function(address){
  41. requests.each(function(res){
  42. if (res.isRunning()){res.cancel();}
  43. });
  44. if (callback) callback(address);
  45. }.bind(this), center)
  46. );
  47. }.bind(this));
  48. }
  49. function getServiceAddressConfigObject(callback, center){
  50. var centerConfig = center;
  51. var host = centerConfig.host || window.location.hostname;
  52. var port = centerConfig.port;
  53. var uri = "";
  54. if (!port || port=="80"){
  55. uri = "http://"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  56. }else{
  57. uri = "http://"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  58. }
  59. var currenthost = window.location.hostname;
  60. uri = uri.replace(/{source}/g, currenthost);
  61. //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  62. return MWF.restful("get", uri, null, function(json){
  63. var serviceAddressList = json.data;
  64. var addressObj = serviceAddressList["x_organization_assemble_authentication"];
  65. var address = "http://"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+addressObj.context;
  66. if (callback) callback(address);
  67. }.bind(this));
  68. }
  69. // function getServiceAddress(config, callback){
  70. // var host = config.center.host || window.location.host;
  71. // var port = config.center.port;
  72. // var uri = "";
  73. // if (!port || port=="80"){
  74. // uri = "http://"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  75. // }else{
  76. // uri = "http://"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  77. // }
  78. // var currenthost = window.location.hostname;
  79. // uri = uri.replace(/{source}/g, currenthost);
  80. // //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  81. // MWF.restful("get", uri, null, function(json){
  82. // var serviceAddressList = json.data;
  83. // var addressObj = serviceAddressList["x_organization_assemble_authentication"];
  84. // var address = "http://"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+addressObj.context;
  85. //
  86. // if (callback) callback(address);
  87. // }.bind(this));
  88. // }
  89. COMMON.setContentPath("/x_desktop");
  90. COMMON.AjaxModule.load("mwf", function(){
  91. MWF.getJSON("res/config/config.json", function(config){
  92. getServiceAddress(config, function(address){
  93. var uri = new URI(window.location.toString());
  94. var xtoken = uri.getData("xtoken");
  95. if (xtoken){
  96. var res = new Request.JSON({
  97. //url: "http://hbxa01.bf.ctc.com:20080/x_organization_assemble_authentication/jaxrs/sso",
  98. url: address+"/jaxrs/sso",
  99. secure: false,
  100. method: "POST",
  101. noCache: true,
  102. withCredentials: true,
  103. onSuccess: function(responseJSON, responseText){
  104. window.location = "/";
  105. }.bind(this),
  106. onFailure: function(xhr){
  107. window.location = "/";
  108. }.bind(this),
  109. onError: function(text, error){
  110. window.location = "/";
  111. }.bind(this)
  112. });
  113. res.setHeader("Content-Type", "application/json; charset=utf-8");
  114. var json = {"token": xtoken};
  115. res.send(JSON.encode(json));
  116. }else{
  117. window.location = "/"
  118. }
  119. });
  120. });
  121. // MWF.require("MWF.process.RestActions", function(){
  122. // layout.restActions = new MWF.process.RestActions(Properties.action);
  123. // });
  124. });
  125. </script>
  126. </head>
  127. <body bgcolor="#faebd7" bgcolor="#ffc0cb">
  128. </body>
  129. </html>