本文整理汇总了C#中EvaluationEngine类的典型用法代码示例。如果您正苦于以下问题:C# EvaluationEngine类的具体用法?C# EvaluationEngine怎么用?C# EvaluationEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EvaluationEngine类属于命名空间,在下文中一共展示了EvaluationEngine类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IID002
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));
}
}
示例2: Main
/// <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();
}
示例3: CheckAccess
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);
}