Example #1
0
        /// <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(Consts.Schema1.PolicyCombiningAlgorithms.DenyOverrides);
            cmbPolicyCombiningAlgorithm.Items.Add(Consts.Schema1.PolicyCombiningAlgorithms.PermitOverrides);
            cmbPolicyCombiningAlgorithm.Items.Add(Consts.Schema1.PolicyCombiningAlgorithms.FirstApplicable);
            cmbPolicyCombiningAlgorithm.Items.Add(Consts.Schema1.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;
        }
Example #2
0
        /// <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( Consts.Schema1.PolicyCombiningAlgorithms.DenyOverrides );
            cmbPolicyCombiningAlgorithm.Items.Add( Consts.Schema1.PolicyCombiningAlgorithms.PermitOverrides );
            cmbPolicyCombiningAlgorithm.Items.Add( Consts.Schema1.PolicyCombiningAlgorithms.FirstApplicable );
            cmbPolicyCombiningAlgorithm.Items.Add( Consts.Schema1.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;
        }
Example #3
0
        /// <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();
        }
Example #4
0
        /// <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();
        }
Example #5
0
        /// <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)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            _schemaVersion = schemaVersion;

            // Prepare Xsd validation
            var validationHandler = new ValidationEventHandler(vreader_ValidationEventHandler);
            var settings          = new XmlReaderSettings {
                ValidationType = ValidationType.Schema
            };

            settings.ValidationEventHandler += validationHandler;
            XmlReader vreader = null;

            try
            {
                switch (schemaVersion)
                {
                case XacmlVersion.Version10:
                case XacmlVersion.Version11:
                {
                    if (_compiledSchemas11 == null)
                    {
                        Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml10PolicySchemaResourceName);
                        _compiledSchemas11 = new XmlSchemaSet();
                        Debug.Assert(schemaStream != null, "schemaStream != null");
                        _compiledSchemas11.Add(XmlSchema.Read(schemaStream, validationHandler));
                        _compiledSchemas11.Compile();
                    }
                    settings.Schemas.Add(_compiledSchemas11);
                    break;
                }

                case XacmlVersion.Version20:
                {
                    if (_compiledSchemas20 == null)
                    {
                        Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml20PolicySchemaResourceName);
                        _compiledSchemas20 = new XmlSchemaSet();
                        Debug.Assert(schemaStream != null, "schemaStream != null");
                        _compiledSchemas20.Add(XmlSchema.Read(schemaStream, validationHandler));
                        _compiledSchemas20.Compile();
                    }
                    settings.Schemas.Add(_compiledSchemas20);
                    break;
                }

                default:
                    throw new ArgumentException("意外的xacml模式版本号:" + schemaVersion);
                }
                vreader = XmlReader.Create(reader, settings);
                // 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 == Consts.Schema1.Namespaces.Xmlns)
                            {
                                _namespaces.Add(vreader.Prefix, vreader.Value);
                            }
                            else if (vreader.Prefix == Consts.Schema1.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 Consts.Schema1.PolicySetElement.PolicySet:
                    {
                        _policySet = new PolicySetElementReadWrite(vreader, schemaVersion);
                        return;
                    }

                    case Consts.Schema1.PolicyElement.Policy:
                    {
                        _policy = new PolicyElementReadWrite(vreader, schemaVersion);
                        return;
                    }
                    }
                }
            }
            finally
            {
                if (vreader != null)
                {
                    vreader.Close();
                }
            }
        }
        /// <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)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            _schemaVersion = schemaVersion;

            // Prepare Xsd validation
            var validationHandler = new ValidationEventHandler(vreader_ValidationEventHandler);
            var settings = new XmlReaderSettings { ValidationType = ValidationType.Schema };
            settings.ValidationEventHandler += validationHandler;
            XmlReader vreader = null;
            try
            {
                switch (schemaVersion)
                {
                    case XacmlVersion.Version10:
                    case XacmlVersion.Version11:
                        {
                            if (_compiledSchemas11 == null)
                            {
                                Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml10PolicySchemaResourceName);
                                _compiledSchemas11 = new XmlSchemaSet();
                                Debug.Assert(schemaStream != null, "schemaStream != null");
                                _compiledSchemas11.Add(XmlSchema.Read(schemaStream, validationHandler));
                                _compiledSchemas11.Compile();
                            }
                            settings.Schemas.Add(_compiledSchemas11);
                            break;
                        }
                    case XacmlVersion.Version20:
                        {
                            if (_compiledSchemas20 == null)
                            {
                                Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml20PolicySchemaResourceName);
                                _compiledSchemas20 = new XmlSchemaSet();
                                Debug.Assert(schemaStream != null, "schemaStream != null");
                                _compiledSchemas20.Add(XmlSchema.Read(schemaStream, validationHandler));
                                _compiledSchemas20.Compile();
                            }
                            settings.Schemas.Add(_compiledSchemas20);
                            break;
                        }
                    default:
                        throw new ArgumentException("意外的xacml模式版本号:" + schemaVersion);
                }
                vreader = XmlReader.Create(reader, settings);
                // 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 == Consts.Schema1.Namespaces.Xmlns)
                            {
                                _namespaces.Add(vreader.Prefix, vreader.Value);
                            }
                            else if (vreader.Prefix == Consts.Schema1.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 Consts.Schema1.PolicySetElement.PolicySet:
                            {
                                _policySet = new PolicySetElementReadWrite(vreader, schemaVersion);
                                return;
                            }
                        case Consts.Schema1.PolicyElement.Policy:
                            {
                                _policy = new PolicyElementReadWrite(vreader, schemaVersion);
                                return;
                            }
                    }
                }
            }
            finally
            {
                if (vreader != null)
                {
                    vreader.Close();
                }
            }
        }