本文整理汇总了C#中Xacml.Core.Runtime.EvaluationEngine类的典型用法代码示例。如果您正苦于以下问题:C# EvaluationEngine类的具体用法?C# EvaluationEngine怎么用?C# EvaluationEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EvaluationEngine类属于Xacml.Core.Runtime命名空间,在下文中一共展示了EvaluationEngine类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IIA001
public void IIA001 ()
{
string[] files = new string[] { "2.IIA001Policy.xml", "2.IIA001Request.xml", "2.IIA001Response.xml" };
Assert.AreEqual( files.Length, 3, "Test incomplete" );FileInfo policyFile = new FileInfo( files[0] );
FileInfo requestFile = new FileInfo( files[1] );
FileInfo ResponseElementFile = new FileInfo( 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 );
NUnit.Framework.Assert.AreEqual( ((ResultElement)res.Results[0]).Obligations.Count, ((ResultElement)ResponseElementDocument.Response.Results[0]).Obligations.Count );
NUnit.Framework.Assert.AreEqual( ResponseElementDocument.Response.Results.Count, res.Results.Count );
NUnit.Framework.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() ) );
NUnit.Framework.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 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();
}
示例3: menuItem8_Click
private void menuItem8_Click(object sender, EventArgs e)
{
if( MessageBox.Show( this,"The policy will be saved. Do you want to proceed?", "Warning", MessageBoxButtons.YesNo ) == DialogResult.Yes )
{
//Loads the request
openFileDialog.Filter = "Request Files|*.xml|All Files|*.*";
if( openFileDialog.ShowDialog() == DialogResult.OK )
{
menuItem9_Click( sender, e );
con.ContextDocumentReadWrite oCon = ContextLoader.LoadContextDocument( openFileDialog.OpenFile(), XacmlVersion.Version11 );
//Gets the policy from the TreeView
Stream stream = new FileStream( _path, FileMode.Open );
pol.PolicyDocumentReadWrite oPol = PolicyLoader.LoadPolicyDocument( stream , XacmlVersion.Version20 );
stream.Close();
//Evaluates the request
EvaluationEngine engine = new EvaluationEngine();
con.ResponseElement res = engine.Evaluate( (pol.PolicyDocument)oPol, (con.ContextDocument)oCon );
//Creates the xml
string path = Path.GetTempFileName();
XmlWriter writer = new XmlTextWriter( path, Encoding.UTF8 );
res.WriteDocument( writer );
writer.Close();
mainPanel.Controls.Clear();
mainPanel.Controls.Add( new XmlViewer( path, ResponseElement.Response ) );
}
}
}
示例4: EvaluationContext
/// <summary>
/// Creates a new instance of the evaluaion context.
/// </summary>
/// <param name="engine">The engine instance.</param>
/// <param name="policyDocument">The policy document instance.</param>
/// <param name="contextDocument">The context document instance.</param>
public EvaluationContext( EvaluationEngine engine, pol.PolicyDocument policyDocument, ctx.ContextDocument contextDocument )
: this()
{
ctx.AttributeReadWriteCollection attributes = new ctx.AttributeReadWriteCollection();
foreach( ctx.AttributeElementReadWrite attribute in contextDocument.Request.Resources[0].Attributes )
{
attributes.Add( new ctx.AttributeElementReadWrite( attribute ) );
}
ctx.ResourceContentElement resourceContent = null;
if( contextDocument.Request.Resources[0].ResourceContent != null )
{
resourceContent = new ctx.ResourceContentElement(
contextDocument.Request.Resources[0].ResourceContent.XmlDocument,
contextDocument.Request.Resources[0].ResourceContent.SchemaVersion );
}
_engine = engine;
_policyDocument = policyDocument;
_contextDocument = contextDocument;
_currentResource = new ctx.ResourceElementReadWrite(
resourceContent,
contextDocument.Request.Resources[0].ResourceScopeValue,
attributes,
contextDocument.Request.Resources[0].SchemaVersion );
}
示例5: PolicySet
/// <summary>
/// Creates a new runtime policy set evaluation.
/// </summary>
/// <param name="engine">The evaluation engine.</param>
/// <param name="policySet">The policy set defined in the policy document.</param>
public PolicySet( EvaluationEngine engine, pol.PolicySetElement policySet )
{
if (engine == null) throw new ArgumentNullException("engine");
if (policySet == null) throw new ArgumentNullException("policySet");
_policySet = policySet;
// Create a runtime target of this policy set.
if( policySet.Target != null )
{
_target = new Target( (pol.TargetElement)policySet.Target );
foreach( pol.ResourceElement resource in policySet.Target.Resources.ItemsList )
{
foreach( pol.ResourceMatchElement rmatch in resource.Match )
{
if( !_allResources.Contains( rmatch.AttributeValue.Contents ) )
{
_allResources.Add( rmatch.AttributeValue.Contents );
}
}
}
}
// Add all the policies (or policy set) inside this policy set.
foreach( object child in policySet.Policies )
{
pol.PolicySetElement childPolicySet = child as pol.PolicySetElement;
pol.PolicyElement childPolicyElement = child as pol.PolicyElement;
pol.PolicySetIdReferenceElement childPolicySetIdReference = child as pol.PolicySetIdReferenceElement;
pol.PolicyIdReferenceElement childPolicyIdReferenceElement = child as pol.PolicyIdReferenceElement;
if (childPolicySet != null)
{
PolicySet policySetEv = new PolicySet(engine, childPolicySet);
foreach( string rName in policySetEv.AllResources )
{
if( !_allResources.Contains( rName ) )
{
_allResources.Add( rName );
}
}
_policies.Add( policySetEv );
}
else if (childPolicyElement!=null)
{
Policy policyEv = new Policy(childPolicyElement);
foreach( string rName in policyEv.AllResources )
{
if( !_allResources.Contains( rName ) )
{
_allResources.Add( rName );
}
}
_policies.Add( policyEv );
}
else if (childPolicySetIdReference!=null)
{
pol.PolicySetElement policySetDefinition = EvaluationEngine.Resolve(childPolicySetIdReference);
if( policySetDefinition != null )
{
PolicySet policySetEv = new PolicySet( engine, policySetDefinition );
foreach( string rName in policySetEv.AllResources )
{
if( !_allResources.Contains( rName ) )
{
_allResources.Add( rName );
}
}
_policies.Add( policySetEv );
}
else
{
throw new EvaluationException( Resource.ResourceManager[ Resource.MessageKey.exc_policyset_reference_not_resolved, ((pol.PolicySetIdReferenceElement)child).PolicySetId ] );
}
}
else if (childPolicyIdReferenceElement!=null)
{
pol.PolicyElement policyDefinition = EvaluationEngine.Resolve(childPolicyIdReferenceElement);
if( policyDefinition != null )
{
Policy policyEv = new Policy( policyDefinition );
foreach( string rName in policyEv.AllResources )
{
if( !_allResources.Contains( rName ) )
{
_allResources.Add( rName );
}
}
_policies.Add( policyEv );
}
else
{
throw new EvaluationException( Resource.ResourceManager[ Resource.MessageKey.exc_policy_reference_not_resolved, ((pol.PolicyIdReferenceElement)child).PolicyId ] );
}
}
}
//.........这里部分代码省略.........