Пример #1
0
        static void Main(string[] args)
        {
            var ss = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss:msZ");

            //ss= DateTime.Now.ToUniversalTime().ToString("u");
            //ss = string.Format("{0:u}", DateTime.Now);
            Console.WriteLine(ss);
            Console.WriteLine();

            Console.WriteLine("compose samlrequest test:");
            string res = Composer.GenerateSamlRequest("stress1.0", "https://sts.omr.boc.com/adfs/ls", Guid.NewGuid(), DateTime.Now);

            //string res = Composer.GenerateSamlRequest("https://sts.omr.boc.com", "https://sts.omr.boc.com/adfs/ls",Guid.NewGuid(), DateTime.Now);
            Console.WriteLine(res);
            Console.WriteLine();

            Console.WriteLine("Decode SamlRequest test:");
            var samlRequest = Composer.EncodeSamlRequest(res);

            Console.WriteLine(samlRequest);
            Console.WriteLine();
            var xmlRequest = Composer.DecodeSamlRequest(samlRequest);

            Console.WriteLine(xmlRequest);

            Debug.Assert(res == xmlRequest);
            Console.WriteLine();

            //Console.WriteLine("Decode SamlResponse test:");
            ////SamlResponse为adfs服务返回的html中的samlResponse的值,示例中用到的字符串是adfs返回的一个错误值,这里仅为验证DecodeSamlResponse方法
            var samlResponse    = "PHNhbWxwOlJlc3BvbnNlIElEPSJfZWM1OTdjNzktMWJhZi00NGRkLWJkNTItMmJlMTBkNTZmM2UxIiBWZXJzaW9uPSIyLjAiIElzc3VlSW5zdGFudD0iMjAyMC0wNS0yMlQxMjo0Nzo1OC4yMzVaIiBEZXN0aW5hdGlvbj0iaHR0cHM6Ly9iYWlkdTExMS5jb20vbG9naW4iIENvbnNlbnQ9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDpjb25zZW50OnVuc3BlY2lmaWVkIiBJblJlc3BvbnNlVG89Il8wNzJlYTU4M2IwZjQ0YWE3YmZmYjgwZjI3ZGMyNGRiZiIgeG1sbnM6c2FtbHA9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDpwcm90b2NvbCI+PElzc3VlciB4bWxucz0idXJuOm9hc2l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U+PC9BdHRyaWJ1dGVTdGF0ZW1lbnQ+PEF1dGhuU3RhdGVtZW50IEF1dGhuSW5zdGFudD0iMjAyMC0wNS0yMlQxMjo0Nzo1OC4yMzFaIj48QXV0aG5Db250ZXh0PjxBdXRobkNvbnRleHRDbGFzc1JlZj51cm46ZmVkZXJhdGlvbjphdXRoZW50aWNhdGlvbjp3aW5kb3dzPC9BdXRobkNvbnRleHRDbGFzc1JlZj48L0F1dGhuQ29udGV4dD48L0F1dGhuU3RhdGVtZW50PjwvQXNzZXJ0aW9uPjwvc2FtbHA6UmVzcG9uc2U+";
            var decodedResponse = Composer.DecodeSamlResponse(samlResponse);

            Console.WriteLine(decodedResponse);
            Console.WriteLine();

            Console.WriteLine("*********end*********");
            Console.Read();
        }