/// <summary> /// Creates a new control that points to the policy set element specified. /// </summary> /// <param name="policySet"></param> public PolicySet( pol.PolicySetElementReadWrite policySet ) { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); _policySet = policySet; LoadingData = true; cmbPolicyCombiningAlgorithm.Items.Add( PolicyCombiningAlgorithms.DenyOverrides ); cmbPolicyCombiningAlgorithm.Items.Add( PolicyCombiningAlgorithms.PermitOverrides ); cmbPolicyCombiningAlgorithm.Items.Add( PolicyCombiningAlgorithms.FirstApplicable ); cmbPolicyCombiningAlgorithm.Items.Add( PolicyCombiningAlgorithms.OnlyOneApplicable ); txtDescription.Text = _policySet.Description; txtPolicySetId.Text = _policySet.Id; txtXPathVersion.Text = _policySet.XPathVersion; cmbPolicyCombiningAlgorithm.SelectedText = _policySet.PolicyCombiningAlgorithm; txtDescription.DataBindings.Add( "Text", _policySet, "Description" ); txtPolicySetId.DataBindings.Add( "Text", _policySet, "Id" ); if(_policySet.XPathVersion != null) txtXPathVersion.DataBindings.Add( "Text", _policySet, "XPathVersion" ); cmbPolicyCombiningAlgorithm.DataBindings.Add( "SelectedValue", policySet, "PolicyCombiningAlgorithm" ); LoadingData = false; }
/// <summary> /// Creates a new control that points to the policy set element specified. /// </summary> /// <param name="policySet"></param> public PolicySet(pol.PolicySetElementReadWrite policySet) { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); _policySet = policySet; LoadingData = true; cmbPolicyCombiningAlgorithm.Items.Add(PolicyCombiningAlgorithms.DenyOverrides); cmbPolicyCombiningAlgorithm.Items.Add(PolicyCombiningAlgorithms.PermitOverrides); cmbPolicyCombiningAlgorithm.Items.Add(PolicyCombiningAlgorithms.FirstApplicable); cmbPolicyCombiningAlgorithm.Items.Add(PolicyCombiningAlgorithms.OnlyOneApplicable); txtDescription.Text = _policySet.Description; txtPolicySetId.Text = _policySet.Id; txtXPathVersion.Text = _policySet.XPathVersion; cmbPolicyCombiningAlgorithm.SelectedText = _policySet.PolicyCombiningAlgorithm; txtDescription.DataBindings.Add("Text", _policySet, "Description"); txtPolicySetId.DataBindings.Add("Text", _policySet, "Id"); if (_policySet.XPathVersion != null) { txtXPathVersion.DataBindings.Add("Text", _policySet, "XPathVersion"); } cmbPolicyCombiningAlgorithm.DataBindings.Add("SelectedValue", policySet, "PolicyCombiningAlgorithm"); LoadingData = false; }
/// <summary> /// /// </summary> /// <param name="policySet"></param> public PolicySet( pol.PolicySetElementReadWrite policySet ) { _policySet = policySet; this.Text = string.Format( "PolicySet ( {0} )", _policySet.Id ); if( _policySet.Target == null ) { this.Nodes.Add( new AnyTarget() ); } else { this.Nodes.Add( new Target( _policySet.Target ) ); } foreach( object policy in _policySet.Policies ) { if( policy is pol.PolicyElementReadWrite ) { this.Nodes.Add( new Policy( (pol.PolicyElementReadWrite)policy ) ); } else if( policy is pol.PolicySetElementReadWrite ) { this.Nodes.Add( new PolicySet( (pol.PolicySetElementReadWrite)policy ) ); } else if( policy is pol.PolicyIdReferenceElementReadWrite ) { this.Nodes.Add( new PolicyIdReference( (pol.PolicyIdReferenceElementReadWrite)policy ) ); } else if( policy is pol.PolicySetIdReferenceElementReadWrite ) { this.Nodes.Add( new PolicySetIdReference( (pol.PolicySetIdReferenceElementReadWrite)policy ) ); } } this.Nodes.Add( new Obligations( _policySet.Obligations ) ); this.Expand(); }
/// <summary> /// /// </summary> /// <param name="policySet"></param> public PolicySet(pol.PolicySetElementReadWrite policySet) { _policySet = policySet; this.Text = string.Format("PolicySet ( {0} )", _policySet.Id); if (_policySet.Target == null) { this.Nodes.Add(new AnyTarget()); } else { this.Nodes.Add(new Target(_policySet.Target)); } foreach (object policy in _policySet.Policies) { if (policy is pol.PolicyElementReadWrite) { this.Nodes.Add(new Policy((pol.PolicyElementReadWrite)policy)); } else if (policy is pol.PolicySetElementReadWrite) { this.Nodes.Add(new PolicySet((pol.PolicySetElementReadWrite)policy)); } else if (policy is pol.PolicyIdReferenceElementReadWrite) { this.Nodes.Add(new PolicyIdReference((pol.PolicyIdReferenceElementReadWrite)policy)); } else if (policy is pol.PolicySetIdReferenceElementReadWrite) { this.Nodes.Add(new PolicySetIdReference((pol.PolicySetIdReferenceElementReadWrite)policy)); } } this.Nodes.Add(new Obligations(_policySet.Obligations)); this.Expand(); }
/// <summary> /// Creates a new PolicyDocument using the XmlReader instance provided with the possibility of writing. /// </summary> /// <param name="reader">The XmlReader positioned at the begining of the document.</param> /// <param name="schemaVersion">The version of the schema that will be used to validate.</param> public PolicyDocumentReadWrite(XmlReader reader, XacmlVersion schemaVersion) { // Validate the parameters if (reader == null) { throw new ArgumentNullException("reader"); } _schemaVersion = schemaVersion; // Prepare Xsd validation #if NET10 XmlValidatingReader vreader = new XmlValidatingReader( reader ); #endif #if NET20 ValidationEventHandler validationHandler = vreader_ValidationEventHandler; XmlReaderSettings settings = new XmlReaderSettings {ValidationType = ValidationType.Schema}; settings.ValidationEventHandler += validationHandler; XmlReader vreader = null; #endif try { switch (schemaVersion) { case XacmlVersion.Version10: case XacmlVersion.Version11: { Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml10PolicySchemaResourceName); #if NET10 XmlTextReader schemaReader = new XmlTextReader(schemaStream); vreader.Schemas.Add( PolicySchema1.Namespaces.Policy, schemaReader ); #endif #if NET20 if (_compiledSchemas11 == null) { _compiledSchemas11 = new XmlSchemaSet(); _compiledSchemas11.Add(XmlSchema.Read(schemaStream, validationHandler)); _compiledSchemas11.Compile(); } settings.Schemas.Add(_compiledSchemas11); #endif break; } case XacmlVersion.Version20: { Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml20PolicySchemaResourceName); #if NET10 XmlTextReader schemaReader = new XmlTextReader(schemaStream); vreader.Schemas.Add( PolicySchema2.Namespaces.Policy, schemaReader ); #endif #if NET20 if (_compiledSchemas20 == null) { _compiledSchemas20 = new XmlSchemaSet(); _compiledSchemas20.Add(XmlSchema.Read(schemaStream, validationHandler)); _compiledSchemas20.Compile(); } settings.Schemas.Add(_compiledSchemas20); #endif break; } default: throw new ArgumentException(Resource.ResourceManager[Resource.MessageKey.exc_invalid_version_parameter_value], "version"); } #if NET10 vreader.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler( vreader_ValidationEventHandler ); #endif #if NET20 vreader = XmlReader.Create(reader, settings); #endif // Read and validate the document. while (vreader.Read()) { //Read all the namespaces and keep them in the _namespaces hashtable. if (vreader.HasAttributes) { while (vreader.MoveToNextAttribute()) { if (vreader.LocalName == PolicySchema1.Namespaces.XMLNS) { _namespaces.Add(vreader.Prefix, vreader.Value); } else if (vreader.Prefix == PolicySchema1.Namespaces.XMLNS) { _namespaces.Add(vreader.LocalName, vreader.Value); } } vreader.MoveToElement(); } // Check the first element of the document and proceeds to read the contents // depending on the first node name. switch (vreader.LocalName) { case PolicySchema1.PolicySetElement.PolicySet: { _policySet = new PolicySetElementReadWrite(vreader, schemaVersion); return; } case PolicySchema1.PolicyElement.Policy: { _policy = new PolicyElementReadWrite(vreader, schemaVersion); return; } } } } finally { if (vreader != null) { vreader.Close(); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void CreatePolicySetFromDocument( object sender, EventArgs args ) { PolicyDocument policyDocumentNode = (PolicyDocument)mainTree.SelectedNode; pol.PolicyDocumentReadWrite policyDoc = policyDocumentNode.PolicyDocumentDefinition; // Create a new policy pol.PolicySetElementReadWrite newPolicySet = new pol.PolicySetElementReadWrite( "urn:newpolicy", "[TODO: add a description]", null, new ArrayList(), PolicyCombiningAlgorithms.FirstApplicable, new pol.ObligationReadWriteCollection(), null, XacmlVersion.Version11 ); //TODO: check version policyDoc.PolicySet = newPolicySet; // Create a new node. PolicySet newPolicySetNode = new PolicySet( newPolicySet ); // Add the tree node. policyDocumentNode.Nodes.Add( newPolicySetNode ); // Set the font so the user knows the item was changed newPolicySetNode.NodeFont = new Font( mainTree.Font, FontStyle.Bold ); }
/// <summary> /// Creates a new PolicyDocument using the XmlReader instance provided with the possibility of writing. /// </summary> /// <param name="reader">The XmlReader positioned at the begining of the document.</param> /// <param name="schemaVersion">The version of the schema that will be used to validate.</param> public PolicyDocumentReadWrite(XmlReader reader, XacmlVersion schemaVersion) { // Validate the parameters if (reader == null) { throw new ArgumentNullException("reader"); } _schemaVersion = schemaVersion; // Prepare Xsd validation #if NET10 XmlValidatingReader vreader = new XmlValidatingReader(reader); #endif #if NET20 ValidationEventHandler validationHandler = vreader_ValidationEventHandler; XmlReaderSettings settings = new XmlReaderSettings { ValidationType = ValidationType.Schema }; settings.ValidationEventHandler += validationHandler; XmlReader vreader = null; #endif try { switch (schemaVersion) { case XacmlVersion.Version10: case XacmlVersion.Version11: { Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml10PolicySchemaResourceName); #if NET10 XmlTextReader schemaReader = new XmlTextReader(schemaStream); vreader.Schemas.Add(PolicySchema1.Namespaces.Policy, schemaReader); #endif #if NET20 if (_compiledSchemas11 == null) { _compiledSchemas11 = new XmlSchemaSet(); _compiledSchemas11.Add(XmlSchema.Read(schemaStream, validationHandler)); _compiledSchemas11.Compile(); } settings.Schemas.Add(_compiledSchemas11); #endif break; } case XacmlVersion.Version20: { Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml20PolicySchemaResourceName); #if NET10 XmlTextReader schemaReader = new XmlTextReader(schemaStream); vreader.Schemas.Add(PolicySchema2.Namespaces.Policy, schemaReader); #endif #if NET20 if (_compiledSchemas20 == null) { _compiledSchemas20 = new XmlSchemaSet(); _compiledSchemas20.Add(XmlSchema.Read(schemaStream, validationHandler)); _compiledSchemas20.Compile(); } settings.Schemas.Add(_compiledSchemas20); #endif break; } default: throw new ArgumentException(Resource.ResourceManager[Resource.MessageKey.exc_invalid_version_parameter_value], "version"); } #if NET10 vreader.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(vreader_ValidationEventHandler); #endif #if NET20 vreader = XmlReader.Create(reader, settings); #endif // Read and validate the document. while (vreader.Read()) { //Read all the namespaces and keep them in the _namespaces hashtable. if (vreader.HasAttributes) { while (vreader.MoveToNextAttribute()) { if (vreader.LocalName == PolicySchema1.Namespaces.XMLNS) { _namespaces.Add(vreader.Prefix, vreader.Value); } else if (vreader.Prefix == PolicySchema1.Namespaces.XMLNS) { _namespaces.Add(vreader.LocalName, vreader.Value); } } vreader.MoveToElement(); } // Check the first element of the document and proceeds to read the contents // depending on the first node name. switch (vreader.LocalName) { case PolicySchema1.PolicySetElement.PolicySet: { _policySet = new PolicySetElementReadWrite(vreader, schemaVersion); return; } case PolicySchema1.PolicyElement.Policy: { _policy = new PolicyElementReadWrite(vreader, schemaVersion); return; } } } } finally { if (vreader != null) { vreader.Close(); } } }