sso.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.js?v=2.0.0"></script>
  8. <script src="../o2_core/compatible.js?v=2.0.0"></script>
  9. <script>
  10. function getServiceAddress(config, callback){
  11. if (typeOf(config.center)=="object"){
  12. getServiceAddressConfigObject(callback);
  13. }else if (typeOf(config.center)=="array"){
  14. var center = chooseCenter(config);
  15. if (center){
  16. getServiceAddressConfigObject(callback, center);
  17. }else{
  18. getServiceAddressConfigArray(config, callback);
  19. }
  20. //this.getServiceAddressConfigArray(callback);
  21. }
  22. }
  23. function chooseCenter(config){
  24. var host = window.location.host;
  25. var center = null;
  26. for (var i=0; i<config.center.length; i++){
  27. var ct = config.center[i];
  28. if (ct.webHost==host){
  29. center = ct;
  30. break;
  31. }
  32. }
  33. return center;
  34. }
  35. function getServiceAddressConfigArray(config, callback) {
  36. var requests = [];
  37. config.center.each(function(center){
  38. requests.push(
  39. getServiceAddressConfigObject(function(address){
  40. requests.each(function(res){
  41. if (res.isRunning()){res.cancel();}
  42. });
  43. if (callback) callback(address);
  44. }.bind(this), center)
  45. );
  46. }.bind(this));
  47. }
  48. function getServiceAddressConfigObject(callback, center){
  49. var centerConfig = center;
  50. var host = centerConfig.host || window.location.hostname;
  51. var port = centerConfig.port;
  52. var uri = "";
  53. var locate = window.location;
  54. var protocol = locate.protocol;
  55. if (!port || port=="80"){
  56. uri = protocol+"//"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  57. }else{
  58. uri = protocol+"//"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  59. }
  60. var currenthost = window.location.hostname;
  61. uri = uri.replace(/{source}/g, currenthost);
  62. //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  63. return MWF.restful("get", uri, null, function(json){
  64. var serviceAddressList = json.data;
  65. var addressObj = serviceAddressList["x_organization_assemble_authentication"];
  66. var address = protocol+"//"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+addressObj.context;
  67. if (callback) callback(address);
  68. }.bind(this));
  69. }
  70. o2.addReady(function(){
  71. o2.JSON.get("res/config/config.json", function(config){
  72. getServiceAddress(config, function(address){
  73. var uri = new URI(window.location.toString());
  74. var xtoken = uri.getData("xtoken");
  75. var client = uri.getData("client");
  76. if (xtoken){
  77. var res = new Request.JSON({
  78. //url: "http://hbxa01.bf.ctc.com:20080/x_organization_assemble_authentication/jaxrs/sso",
  79. url: address+"/jaxrs/sso",
  80. secure: false,
  81. method: "POST",
  82. noCache: true,
  83. withCredentials: true,
  84. onSuccess: function(responseJSON, responseText){
  85. window.location = "/";
  86. }.bind(this),
  87. onFailure: function(xhr){
  88. window.location = "/";
  89. }.bind(this),
  90. onError: function(text, error){
  91. window.location = "/";
  92. }.bind(this)
  93. });
  94. res.setHeader("Content-Type", "application/json; charset=utf-8");
  95. var json = {"token": xtoken, "client": client};
  96. res.send(JSON.encode(json));
  97. }else{
  98. window.location = "/"
  99. }
  100. });
  101. });
  102. });
  103. </script>
  104. </head>
  105. <body bgcolor="#faebd7" bgcolor="#ffc0cb">
  106. </body>
  107. </html>