sso.js 3.4 KB

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