sso.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  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"></script>
  8. <script src="../o2_lib/Decimal.js"></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. if (!window.layout) window.layout = {};
  73. window.layout.config = config;
  74. getServiceAddress(config, function(address){
  75. var uri = new URI(window.location.toString());
  76. var xtoken = uri.getData("xtoken");
  77. var client = uri.getData("client");
  78. var redirect = uri.getData("redirect");
  79. if (xtoken){
  80. var res = new Request.JSON({
  81. //url: "http://hbxa01.bf.ctc.com:20080/x_organization_assemble_authentication/jaxrs/sso",
  82. url: o2.filterUrl(address+"/jaxrs/sso"),
  83. secure: false,
  84. method: "POST",
  85. noCache: true,
  86. withCredentials: true,
  87. onSuccess: function(responseJSON, responseText){
  88. if (redirect){
  89. window.location = redirect;
  90. }else{
  91. window.location = "/";
  92. }
  93. }.bind(this),
  94. onFailure: function(xhr){
  95. window.location = "/";
  96. }.bind(this),
  97. onError: function(text, error){
  98. window.location = "/";
  99. }.bind(this)
  100. });
  101. res.setHeader("Content-Type", "application/json; charset=utf-8");
  102. var json = {"token": xtoken, "client": client};
  103. res.send(JSON.encode(json));
  104. }else{
  105. if (redirect){
  106. window.location = redirect;
  107. }else{
  108. window.location = "/";
  109. }
  110. }
  111. });
  112. });
  113. });
  114. </script>
  115. </head>
  116. <body bgcolor="#faebd7" bgcolor="#ffc0cb">
  117. </body>
  118. </html>