Exemple #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( Consts.Schema1.RuleCombiningAlgorithms.DenyOverrides );
            cmbRuleCombiningAlgorithm.Items.Add( Consts.Schema1.RuleCombiningAlgorithms.PermitOverrides );
            cmbRuleCombiningAlgorithm.Items.Add( Consts.Schema1.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;
        }
Exemple #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(Consts.Schema1.RuleCombiningAlgorithms.DenyOverrides);
            cmbRuleCombiningAlgorithm.Items.Add(Consts.Schema1.RuleCombiningAlgorithms.PermitOverrides);
            cmbRuleCombiningAlgorithm.Items.Add(Consts.Schema1.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;
        }
Exemple #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();
        }
Exemple #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();
        }
Exemple #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();
                }
            }
        }