sso.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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="../o2_core/o2.min.js?v=2.0.0"></script>
  8. <script src="../o2_core/compatible.min.js?v=2.0.0"></script>
  9. <script src="../o2_lib/Decimal.js"></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. var locate = window.location;
  55. var protocol = locate.protocol;
  56. if (!port || port=="80"){
  57. uri = protocol+"//"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  58. }else{
  59. uri = protocol+"//"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  60. }
  61. var currenthost = window.location.hostname;
  62. uri = uri.replace(/{source}/g, currenthost);
  63. //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  64. return MWF.restful("get", uri, null, function(json){
  65. var serviceAddressList = json.data;
  66. var addressObj = serviceAddressList["x_organization_assemble_authentication"];
  67. var address = protocol+"//"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+addressObj.context;
  68. if (callback) callback(address);
  69. }.bind(this));
  70. }
  71. o2.addReady(function(){
  72. o2.JSON.get("res/config/config.json", function(config){
  73. getServiceAddress(config, function(address){
  74. var uri = new URI(window.location.toString());
  75. var xtoken = uri.getData("xtoken");
  76. var client = uri.getData("client");
  77. if (xtoken){
  78. var res = new Request.JSON({
  79. //url: "http://hbxa01.bf.ctc.com:20080/x_organization_assemble_authentication/jaxrs/sso",
  80. url: address+"/jaxrs/sso",
  81. secure: false,
  82. method: "POST",
  83. noCache: true,
  84. withCredentials: true,
  85. onSuccess: function(responseJSON, responseText){
  86. window.location = "/";
  87. }.bind(this),
  88. onFailure: function(xhr){
  89. window.location = "/";
  90. }.bind(this),
  91. onError: function(text, error){
  92. window.location = "/";
  93. }.bind(this)
  94. });
  95. res.setHeader("Content-Type", "application/json; charset=utf-8");
  96. var json = {"token": xtoken, "client": client};
  97. res.send(JSON.encode(json));
  98. }else{
  99. window.location = "/"
  100. }
  101. });
  102. });
  103. });
  104. </script>
  105. </head>
  106. <body bgcolor="#faebd7" bgcolor="#ffc0cb">
  107. </body>
  108. </html>