sso.html 5.1 KB
Newer Older
NoSubject's avatar
NoSubject 已提交
1
<!DOCTYPE html>
R
roo00 已提交
2 3
<html lang="zh-CN">
<head>
NoSubject's avatar
NoSubject 已提交
4 5 6
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta charset="UTF-8">
    <title></title>
R
roo00 已提交
7
    <script src="../o2_core/o2.min.js"></script>
NoSubject's avatar
NoSubject 已提交
8
    <script src="../o2_lib/Decimal.js"></script>
NoSubject's avatar
NoSubject 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    <script>
        function getServiceAddress(config, callback){
            if (typeOf(config.center)=="object"){
                getServiceAddressConfigObject(callback);
            }else if (typeOf(config.center)=="array"){
                var center = chooseCenter(config);
                if (center){
                    getServiceAddressConfigObject(callback, center);
                }else{
                    getServiceAddressConfigArray(config, callback);
                }
                //this.getServiceAddressConfigArray(callback);
            }
        }
        function chooseCenter(config){
            var host = window.location.host;
            var center = null;
            for (var i=0; i<config.center.length; i++){
                var ct = config.center[i];
                if (ct.webHost==host){
                    center = ct;
                    break;
                }
            }
            return center;
        }
        function getServiceAddressConfigArray(config, callback) {
            var requests = [];
            config.center.each(function(center){
                requests.push(
                        getServiceAddressConfigObject(function(address){
                            requests.each(function(res){
                                if (res.isRunning()){res.cancel();}
                            });
                            if (callback) callback(address);
                        }.bind(this), center)
                );
            }.bind(this));
        }
        function getServiceAddressConfigObject(callback, center){
            var centerConfig = center;
            var host = centerConfig.host || window.location.hostname;
            var port = centerConfig.port;
            var uri = "";
            var locate = window.location;
            var protocol = locate.protocol;
            if (!port || port=="80"){
                uri = protocol+"//"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
            }else{
                uri = protocol+"//"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
            }
            var currenthost = window.location.hostname;
            uri = uri.replace(/{source}/g, currenthost);
            //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
            return MWF.restful("get", uri, null, function(json){
                var serviceAddressList = json.data;
                var addressObj = serviceAddressList["x_organization_assemble_authentication"];
                var address = protocol+"//"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+addressObj.context;

                if (callback) callback(address);
            }.bind(this));
        }

NoSubject's avatar
NoSubject 已提交
72 73
        o2.addReady(function(){
            o2.JSON.get("res/config/config.json", function(config){
NoSubject's avatar
NoSubject 已提交
74 75 76 77
                getServiceAddress(config, function(address){
                    var uri = new URI(window.location.toString());
                    var xtoken = uri.getData("xtoken");
                    var client = uri.getData("client");
NoSubject's avatar
NoSubject 已提交
78
                    var redirect = uri.getData("redirect");
NoSubject's avatar
NoSubject 已提交
79 80 81
                    if (xtoken){
                        var res = new Request.JSON({
                            //url: "http://hbxa01.bf.ctc.com:20080/x_organization_assemble_authentication/jaxrs/sso",
NoSubject's avatar
NoSubject 已提交
82
                            url: o2.filterUrl(address+"/jaxrs/sso"),
NoSubject's avatar
NoSubject 已提交
83 84 85 86 87
                            secure: false,
                            method: "POST",
                            noCache: true,
                            withCredentials: true,
                            onSuccess: function(responseJSON, responseText){
NoSubject's avatar
NoSubject 已提交
88 89 90 91 92
                                if (redirect){
                                    window.location = redirect;
                                }else{
                                    window.location = "/";
                                }
NoSubject's avatar
NoSubject 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105
                            }.bind(this),
                            onFailure: function(xhr){
                                window.location = "/";
                            }.bind(this),
                            onError: function(text, error){
                                window.location = "/";
                            }.bind(this)
                        });
                        res.setHeader("Content-Type", "application/json; charset=utf-8");
                        var json = {"token": xtoken, "client": client};

                        res.send(JSON.encode(json));
                    }else{
NoSubject's avatar
NoSubject 已提交
106 107 108 109 110
                        if (redirect){
                            window.location = redirect;
                        }else{
                            window.location = "/";
                        }
NoSubject's avatar
NoSubject 已提交
111 112 113 114 115 116 117 118 119 120 121
                    }
                });
            });

        });

    </script>
</head>
<body bgcolor="#faebd7" bgcolor="#ffc0cb">

</body>
R
roo00 已提交
122
</html>