sso.html 6.2 KB

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