Beispiel #1
0
        public void IIA001()
        {
            string[]      files    = new string[] { "2.IIA001Request.xml" };
            string        tempFile = Path.GetTempFileName();
            XmlTextWriter tw       = new XmlTextWriter(tempFile, System.Text.Encoding.ASCII);

            tw.Namespaces = true;
            tw.Formatting = Formatting.Indented;

            FileInfo requestFile = new FileInfo(Consts.Path + files[0]);

            using (FileStream fs = new FileStream(requestFile.FullName, FileMode.Open, FileAccess.Read))
            {
                // Load Request
                ContextDocumentReadWrite contextDocument = ContextLoader.LoadContextDocument(fs, XacmlVersion.Version20, DocumentAccess.ReadWrite);

                contextDocument.Request.Action.Attributes[0].AttributeId = "UnitTest!!!";

                contextDocument.WriteRequestDocument(tw);
                tw.Close();

                using (FileStream fs1 = new FileStream(tempFile, FileMode.Open, FileAccess.Read))
                {
                    ContextDocument newCon = (ContextDocument)ContextLoader.LoadContextDocument(fs1, XacmlVersion.Version20);

                    Assert.AreEqual(newCon.Request.Action.Attributes[0].AttributeId, contextDocument.Request.Action.Attributes[0].AttributeId);
                }
            }
        }
Beispiel #2
0
        public void IIIF003()
        {
            string[] files = new string[] { "2.IIIF003Policy.xml", "2.IIIF003Request.xml", "2.IIIF003Response.xml" };
            Assert.AreEqual(files.Length, 3); FileInfo policyFile = new FileInfo(Consts.Path + files[0]);
            FileInfo requestFile  = new FileInfo(Consts.Path + files[1]);
            FileInfo responseFile = new FileInfo(Consts.Path + files[2]);

            using (FileStream fs = new FileStream(policyFile.FullName, FileMode.Open, FileAccess.Read))
                using (FileStream fs1 = new FileStream(requestFile.FullName, FileMode.Open, FileAccess.Read))
                    using (FileStream fs2 = new FileStream(responseFile.FullName, FileMode.Open, FileAccess.Read))
                    {
                        // Load Policy
                        PolicyDocument policyDocument = (PolicyDocument)PolicyLoader.LoadPolicyDocument(fs, XacmlVersion.Version20, DocumentAccess.ReadOnly);
                        // Load Request
                        ContextDocumentReadWrite requestDocument = ContextLoader.LoadContextDocument(fs1, XacmlVersion.Version20);
                        // Load ResponseElement
                        ContextDocumentReadWrite responseDocument = ContextLoader.LoadContextDocument(fs2, XacmlVersion.Version20);
                        EvaluationEngine         engine           = new EvaluationEngine();

                        ResponseElement res = engine.Evaluate(policyDocument, (ContextDocument)requestDocument);
                        Assert.AreEqual(((ResultElement)res.Results[0]).Obligations.Count, ((ResultElement)responseDocument.Response.Results[0]).Obligations.Count);
                        Assert.AreEqual(responseDocument.Response.Results.Count, res.Results.Count);
                        Assert.IsTrue(((ResultElement)res.Results[0]).Decision.ToString() == ((ResultElement)responseDocument.Response.Results[0]).Decision.ToString(), string.Format("Decission incorrect Expected:{0} Returned:{1}", ((ResultElement)responseDocument.Response.Results[0]).Decision.ToString(), ((ResultElement)res.Results[0]).Decision.ToString()));
                        Assert.IsTrue(((ResultElement)res.Results[0]).Status.StatusCode.Value == ((ResultElement)responseDocument.Response.Results[0]).Status.StatusCode.Value, String.Format("Status incorrect Expected:{0} Returned:{1}", ((ResultElement)responseDocument.Response.Results[0]).Status.StatusCode.Value, ((ResultElement)res.Results[0]).Status.StatusCode.Value));
                    }
        }
Beispiel #3
0
        /// <summary>
        /// Main method for the tool it receives command line arguments and performs the evaluation.
        /// </summary>
        /// <param name="args">The parsed command line arguments.</param>
        static void Main(string[] args)
        {
            var t = ConfigurationManager.OpenExeConfiguration(@"C:\Git\Xacml.Net\Xacml.Console\bin\Debug\Xacml.Console.exe.config");

            string policy = String.Empty, request = String.Empty;
            bool   verbose = false;

            //foreach (string arg in args)
            //{
            //    if ((arg[0] == '/' || arg[0] == '-'))
            //    {
            //        if (arg[1] == 'p' || arg[1] == 'P')
            //        {
            //            policy = arg.Substring(3);
            //        }

            //        if (arg[1] == 'r' || arg[1] == 'R')
            //        {
            //            request = arg.Substring(3);
            //        }

            //        if (arg[1] == 'v' || arg[1] == 'V')
            //        {
            //            verbose = true;
            //        }
            //    }
            //}

            try
            {
                request = @"C:\Git\Xacml.Net\Samples\requests\IIA001Request.xml";
                //request = @"C:\Git\Xacml.Net\Samples\Request.xml";
                policy = @"C:\Git\Xacml.Net\Samples\Policy.xml";
                if (request.Length != 0 && policy.Length != 0)
                {
                    using (FileStream fs1 = new FileStream(request, FileMode.Open, FileAccess.Read))

                    {
                        // Load Request
                        ContextDocumentReadWrite requestDocument = ContextLoader.LoadContextDocument(fs1, XacmlVersion.Version20);

                        var           res = new EvaluationEngine(verbose).Evaluate((ContextDocument)requestDocument);
                        XmlTextWriter tw  = new XmlTextWriter(System.Console.Out)
                        {
                            Formatting = Formatting.Indented
                        };
                        res.WriteDocument(tw);
                    }
                }
                else
                {
                    throw new Exception("Request or policy file not specified.");
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                System.Console.WriteLine();
                System.Console.WriteLine("Usage:");
                System.Console.WriteLine("\t-p:[policyFilePath]  - The path to the policy file");
                System.Console.WriteLine("\t-r:[requestFilePath] - The path to the request file");
                System.Console.WriteLine("\t-v                   - Makes the execution verbose");
            }

            System.Console.WriteLine("Press Enter to close...");
            System.Console.ReadLine();
        }