sso.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. window.layout = window.layout || {};
  2. function getServiceAddress(config, callback){
  3. window.layout.config = config;
  4. if (config.configMapping && (config.configMapping[window.location.host] || config.configMapping[window.location.hostname])) {
  5. var mapping = config.configMapping[window.location.host] || config.configMapping[window.location.hostname];
  6. if (mapping.servers){
  7. window.layout.serviceAddressList = mapping.servers;
  8. if (mapping.center) center = (o2.typeOf(mapping.center)==="array") ? mapping.center[0] : mapping.center;
  9. window.layout.centerServer = center;
  10. if (callback) callback();
  11. }else{
  12. if (mapping.center) layout.config.center = (o2.typeOf(mapping.center)==="array") ? mapping.center : [mapping.center];
  13. getServiceAddressConfigArray(layout.config, callback);
  14. }
  15. }else{
  16. if (typeOf(config.center)=="object"){
  17. getServiceAddressConfigObject(callback);
  18. }else if (typeOf(config.center)=="array"){
  19. // var center = chooseCenter(config);
  20. // if (center){
  21. // getServiceAddressConfigObject(callback, center);
  22. // }else{
  23. getServiceAddressConfigArray(config, callback);
  24. // }
  25. }
  26. }
  27. }
  28. function chooseCenter(config){
  29. var host = window.location.host;
  30. var center = null;
  31. for (var i=0; i<config.center.length; i++){
  32. var ct = config.center[i];
  33. if (ct.webHost==host){
  34. center = ct;
  35. break;
  36. }
  37. }
  38. return center;
  39. }
  40. function getServiceAddressConfigArray(config, callback) {
  41. var requests = [];
  42. config.center.each(function(center){
  43. requests.push(
  44. getServiceAddressConfigObject(function(){
  45. requests.each(function(res){
  46. if (res.res && res.res.isRunning && res.res.isRunning()){res.res.cancel();}
  47. });
  48. if (callback) callback();
  49. }.bind(this), center)
  50. );
  51. }.bind(this));
  52. }
  53. function getServiceAddressConfigObject(callback, center){
  54. var centerConfig = center;
  55. var host = centerConfig.host || window.location.hostname;
  56. var port = centerConfig.port;
  57. var uri = "";
  58. var locate = window.location;
  59. var protocol = locate.protocol;
  60. if (!port || port=="80"){
  61. uri = protocol+"//"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  62. }else{
  63. uri = protocol+"//"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  64. }
  65. var currenthost = window.location.hostname;
  66. uri = uri.replace(/{source}/g, currenthost);
  67. //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  68. return MWF.restful("get", uri, null, function(json){
  69. window.layout.serviceAddressList = json.data;
  70. window.layout.centerServer = center;
  71. // var serviceAddressList = json.data;
  72. // var addressObj = serviceAddressList["x_organization_assemble_authentication"];
  73. // var address = protocol+"//"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+"/z_sso_control/jaxrs/sso/smplogin";
  74. if (callback) callback();
  75. }.bind(this));
  76. }