public void IID002() { string[] files = new string[] { "2.IID002Policy.xml", "2.IID002Request.xml", "2.IID002Response.xml" }; Assert.AreEqual(files.Length, 3); FileInfo policyFile = new FileInfo(Consts.Path + files[0]); FileInfo requestFile = new FileInfo(Consts.Path + files[1]); FileInfo ResponseElementFile = 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(ResponseElementFile.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 ResponseElementDocument = 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)ResponseElementDocument.Response.Results[0]).Obligations.Count); Assert.AreEqual(ResponseElementDocument.Response.Results.Count, res.Results.Count); Assert.IsTrue(((ResultElement)res.Results[0]).Decision.ToString() == ((ResultElement)ResponseElementDocument.Response.Results[0]).Decision.ToString(), string.Format("Decission incorrect Expected:{0} Returned:{1}", ((ResultElement)ResponseElementDocument.Response.Results[0]).Decision.ToString(), ((ResultElement)res.Results[0]).Decision.ToString())); Assert.IsTrue(((ResultElement)res.Results[0]).Status.StatusCode.Value == ((ResultElement)ResponseElementDocument.Response.Results[0]).Status.StatusCode.Value, String.Format("Status incorrect Expected:{0} Returned:{1}", ((ResultElement)ResponseElementDocument.Response.Results[0]).Status.StatusCode.Value, ((ResultElement)res.Results[0]).Status.StatusCode.Value)); } }
/// <summary> /// Main method. /// </summary> /// <param name="args">The command line arguments.</param> public static void Main(string[] args) { var evaluationEngine = new EvaluationEngine(); evaluationEngine.SetLogExtension(new ConsoleLogger()); var questioner = new Questioner(evaluationEngine); var answerer = new Answerer(evaluationEngine); answerer.PrepareAnswers(); questioner.Ask(); Console.ReadLine(); }
public override bool CheckAccess(AuthorizationContext context) { if (!context.Principal.Identity.IsAuthenticated) return true; FileStream policyStream = null; FileStream requestSteam = null; try { string requestFileName = "~/Xacml/AccessLinkOne Request.xml"; var rc = context.Resource.FirstOrDefault(); if (rc.Value.ToLower() == "http://localhost/StsClient/home/AccessLinkTwo".ToLower()) requestFileName = "~/Xacml/AccessLinkTwo Request.xml"; policyStream = File.Open(HttpContext.Current.Server.MapPath("~/Xacml/1.IIA001Policy.xml"), FileMode.Open, FileAccess.Read, FileShare.Read); requestSteam = File.Open(HttpContext.Current.Server.MapPath(requestFileName), FileMode.Open, FileAccess.Read, FileShare.Read); var r = new EvaluationEngine().Evaluate((PolicyDocument)PolicyLoader.LoadPolicyDocument(policyStream), (ContextDocument) ContextLoader.LoadContextDocument(requestSteam)); if (r != null && r.Results != null && r.Results.Count > 0) return r.Results[0].Decision == Decision.Permit; } catch (Exception e) { Debug.WriteLine(e.Message); } finally { if(policyStream!=null) policyStream.Close(); policyStream = null; if(requestSteam!=null) requestSteam.Close(); requestSteam = null; } return base.CheckAccess(context); }