Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        public Policy(pol.PolicyElementReadWrite policy)
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            LoadingData = true;

            _policy = policy;

            cmbRuleCombiningAlgorithm.Items.Add(RuleCombiningAlgorithms.DenyOverrides);
            cmbRuleCombiningAlgorithm.Items.Add(RuleCombiningAlgorithms.PermitOverrides);
            cmbRuleCombiningAlgorithm.Items.Add(RuleCombiningAlgorithms.FirstApplicable);

            txtDescription.Text  = _policy.Description;
            txtPolicyId.Text     = _policy.Id;
            txtXPathVersion.Text = _policy.XPathVersion;
            cmbRuleCombiningAlgorithm.SelectedText = _policy.RuleCombiningAlgorithm;

            txtDescription.DataBindings.Add("Text", _policy, "Description");
            txtPolicyId.DataBindings.Add("Text", _policy, "Id");
            if (_policy.XPathVersion != null)
            {
                txtXPathVersion.DataBindings.Add("Text", _policy, "XPathVersion");
            }
            cmbRuleCombiningAlgorithm.DataBindings.Add("SelectedValue", policy, "RuleCombiningAlgorithm");

            LoadingData = false;
        }
Esempio n. 2
0
		/// <summary>
		/// 
		/// </summary>
		public Policy( pol.PolicyElementReadWrite policy )
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			LoadingData = true;

			_policy = policy;

			cmbRuleCombiningAlgorithm.Items.Add( RuleCombiningAlgorithms.DenyOverrides );
			cmbRuleCombiningAlgorithm.Items.Add( RuleCombiningAlgorithms.PermitOverrides );
			cmbRuleCombiningAlgorithm.Items.Add( RuleCombiningAlgorithms.FirstApplicable );

			txtDescription.Text = _policy.Description;
			txtPolicyId.Text = _policy.Id;
			txtXPathVersion.Text = _policy.XPathVersion;
			cmbRuleCombiningAlgorithm.SelectedText = _policy.RuleCombiningAlgorithm;

			txtDescription.DataBindings.Add( "Text", _policy, "Description" );
			txtPolicyId.DataBindings.Add( "Text", _policy, "Id" );
			if(_policy.XPathVersion != null)
				txtXPathVersion.DataBindings.Add( "Text", _policy, "XPathVersion" );
			cmbRuleCombiningAlgorithm.DataBindings.Add( "SelectedValue", policy, "RuleCombiningAlgorithm" );

			LoadingData = false;
		}
Esempio n. 3
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="policy"></param>
		public Policy( pol.PolicyElementReadWrite policy )
		{
			_policy = policy;

			this.Text = string.Format( "Policy ( {0} )", policy.Id );

			if( policy.Target == null )
			{
				this.Nodes.Add( new AnyTarget() );
			}
			else
			{
				this.Nodes.Add( new Target( policy.Target ) );
			}

			foreach( pol.RuleElementReadWrite rule in policy.Rules )
			{
				this.Nodes.Add( new Rule( rule ) );
			}
			
			this.Nodes.Add( new Obligations( _policy.Obligations ) );
			this.Expand();
		}
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="policy"></param>
        public Policy(pol.PolicyElementReadWrite policy)
        {
            _policy = policy;

            this.Text = string.Format("Policy ( {0} )", policy.Id);

            if (policy.Target == null)
            {
                this.Nodes.Add(new AnyTarget());
            }
            else
            {
                this.Nodes.Add(new Target(policy.Target));
            }

            foreach (pol.RuleElementReadWrite rule in policy.Rules)
            {
                this.Nodes.Add(new Rule(rule));
            }

            this.Nodes.Add(new Obligations(_policy.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();
                }
            }
        }
Esempio n. 6
0
		/// <summary>
		/// Creates a new policy for the policy document selected.
		/// </summary>
		/// <param name="sender">The mainTree control.</param>
		/// <param name="args">The arguements for the event.</param>
		private void CreatePolicyFromDocument( object sender, EventArgs args )
		{
			PolicyDocument policyDocumentNode = (PolicyDocument)mainTree.SelectedNode;
			pol.PolicyDocumentReadWrite policyDocument = policyDocumentNode.PolicyDocumentDefinition;

			// Create a new policy
			pol.PolicyElementReadWrite newPolicy = new pol.PolicyElementReadWrite( 
				"urn:newpolicy", "[TODO: add a description]", null,
				new pol.RuleReadWriteCollection(), 
				RuleCombiningAlgorithms.FirstApplicable, 
				new pol.ObligationReadWriteCollection(), 
				string.Empty,
				null,
				null,
				null,
				XacmlVersion.Version11 ); //TODO: check version

			
			policyDocument.Policy = newPolicy ;

			// Create a new node
			Policy policyNode = new Policy( newPolicy );

			// Add the tree node.
			policyDocumentNode.Nodes.Add( policyNode );

			// Set the font so the user knows the item was changed
			policyNode.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();
                }
            }
        }