Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAdd_Click(object sender, System.EventArgs e)
 {
     LoadingData = true;
     txtId.Text  = string.Empty;
     lstAttributeAssignments.Items.Clear();
     txtAttributeAssignemnt.Text = string.Empty;
     txtAttributeId.Text         = string.Empty;
     index           = -1;
     obligationIndex = -1;
     pol.ObligationElementReadWrite oObligation = new pol.ObligationElementReadWrite(null, Xacml.XacmlVersion.Version11);
     lstObligations.Items.Add(oObligation);
     _obligations.Add(oObligation);
     LoadingData = false;
 }
Пример #2
0
        /// <summary>
        /// Creates a new PolicySet using the XmlReader instance provided.
        /// </summary>
        /// <param name="reader">The XmlReder positioned at the PolicySet element.</param>
        /// <param name="schemaVersion">The version of the schema that will be used to validate.</param>
        public PolicySetElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
            : base(XacmlSchema.Policy, schemaVersion)
        {
            // Validates the current node name
            if (reader.LocalName == Consts.Schema1.PolicySetElement.PolicySet &&
                ValidateSchema(reader, schemaVersion))
            {
                // Get the attributes
                _id = reader.GetAttribute(Consts.Schema1.PolicySetElement.PolicySetId);
                _policyCombiningAlgorithm = reader.GetAttribute(Consts.Schema1.PolicySetElement.PolicyCombiningAlgorithmId);

                // Read the inner nodes
                while (reader.Read())
                {
                    switch (reader.LocalName)
                    {
                    case Consts.Schema1.PolicySetElement.Description:
                        _description = reader.ReadElementString();
                        break;

                    case Consts.Schema1.PolicySetElement.PolicySetDefaults:
                        if (reader.Read() && reader.Read())
                        {
                            if (reader.LocalName == Consts.Schema1.PolicySetDefaultsElement.XPathVersion &&
                                ValidateSchema(reader, schemaVersion))
                            {
                                _xpathVersion = reader.ReadElementString();
                                if (!string.IsNullOrEmpty(_xpathVersion) && _xpathVersion != Consts.Schema1.Namespaces.XPath10)
                                {
                                    throw new Exception(string.Format(Properties.Resource.exc_unsupported_xpath_version, _xpathVersion));
                                }
                            }
                            reader.Read();
                        }
                        break;

                    case Consts.Schema1.TargetElement.Target:
                        _target = new TargetElementReadWrite(reader, schemaVersion);
                        break;

                    case Consts.Schema1.PolicySetElement.PolicySet:
                        if (!reader.IsEmptyElement && reader.NodeType != XmlNodeType.EndElement)
                        {
                            _policies.Add(new PolicySetElementReadWrite(reader, schemaVersion));
                        }
                        break;

                    case Consts.Schema1.PolicyElement.Policy:
                        _policies.Add(new PolicyElementReadWrite(reader, schemaVersion));
                        break;

                    case Consts.Schema1.PolicySetIdReferenceElement.PolicySetIdReference:
                        _policies.Add(new PolicySetIdReferenceElementReadWrite(reader, schemaVersion));
                        break;

                    case Consts.Schema1.PolicyIdReferenceElement.PolicyIdReference:
                        _policies.Add(new PolicyIdReferenceElement(reader, schemaVersion));
                        break;

                    case Consts.Schema1.PolicySetElement.Obligations:
                        while (reader.Read())
                        {
                            switch (reader.LocalName)
                            {
                            case Consts.Schema1.ObligationElement.Obligation:
                                _obligations.Add(new ObligationElementReadWrite(reader, schemaVersion));
                                break;
                            }
                            if (reader.LocalName == Consts.Schema1.ObligationsElement.Obligations &&
                                reader.NodeType == XmlNodeType.EndElement)
                            {
                                reader.Read();
                                break;
                            }
                        }
                        break;

                    case Consts.Schema2.PolicySetElement.CombinerParameters:
                        // Read all the combiner parameters
                        while (reader.Read())
                        {
                            switch (reader.LocalName)
                            {
                            case Consts.Schema2.CombinerParameterElement.CombinerParameter:
                                _combinerParameters.Add(new CombinerParameterElement(reader, schemaVersion));
                                break;
                            }
                            if (reader.LocalName == Consts.Schema2.PolicySetElement.CombinerParameters &&
                                reader.NodeType == XmlNodeType.EndElement)
                            {
                                reader.Read();
                                break;
                            }
                        }
                        break;

                    case Consts.Schema2.PolicySetElement.PolicyCombinerParameters:
                        // Read all the policy combiner parameters
                        while (reader.Read())
                        {
                            switch (reader.LocalName)
                            {
                            case Consts.Schema2.PolicyCombinerParameterElement.PolicyCombinerParameter:
                                _policyCombinerParameters.Add(new PolicyCombinerParameterElement(reader, schemaVersion));
                                break;
                            }
                            if (reader.LocalName == Consts.Schema2.PolicySetElement.PolicyCombinerParameters &&
                                reader.NodeType == XmlNodeType.EndElement)
                            {
                                reader.Read();
                                break;
                            }
                        }
                        break;

                    case Consts.Schema2.PolicySetElement.PolicySetCombinerParameters:
                        // Read all the policy set combiner parameters
                        while (reader.Read())
                        {
                            switch (reader.LocalName)
                            {
                            case Consts.Schema2.PolicySetCombinerParameterElement.PolicySetCombinerParameter:
                                _policySetCombinerParameters.Add(new PolicySetCombinerParameterElement(reader, schemaVersion));
                                break;
                            }
                            if (reader.LocalName == Consts.Schema2.PolicySetElement.PolicySetCombinerParameters &&
                                reader.NodeType == XmlNodeType.EndElement)
                            {
                                reader.Read();
                                break;
                            }
                        }
                        break;
                    }
                    if (reader.LocalName == Consts.Schema1.PolicySetElement.PolicySet &&
                        reader.NodeType == XmlNodeType.EndElement)
                    {
                        reader.Read();
                        break;
                    }
                }
            }
            else
            {
                throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
            }
        }
Пример #3
0
        /// <summary>
        /// Creates a new Policy using the XmlReader instance specified.
        /// </summary>
        /// <param name="reader">The XmlReader instance positioned at the Policy node.</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        public PolicyElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
            : base(XacmlSchema.Policy, schemaVersion)
        {
            if (reader.LocalName == Consts.Schema1.PolicyElement.Policy)
            {
                if (!ValidateSchema(reader, schemaVersion))
                {
                    throw new Exception("ģʽÑé֤ʧ°Ü");
                }
                // Read the policy id
                _id = reader.GetAttribute(Consts.Schema1.PolicyElement.PolicyId);

                // Read the policy combining algorithm
                _ruleCombiningAlgorithm = reader.GetAttribute(Consts.Schema1.PolicyElement.RuleCombiningAlgorithmId);
                while (reader.Read())
                {
                    switch (reader.LocalName)
                    {
                    case Consts.Schema1.PolicyElement.Description:
                        _description = reader.ReadElementString();
                        break;

                    case Consts.Schema1.PolicyElement.PolicyDefaults:
                        // Read all the policy defaults.
                        if (reader.Read() && reader.Read())
                        {
                            if (reader.LocalName == Consts.Schema1.PolicyDefaultsElement.XPathVersion &&
                                ValidateSchema(reader, schemaVersion))
                            {
                                _xpathVersion = reader.ReadElementString();
                                if (!string.IsNullOrEmpty(_xpathVersion) && _xpathVersion != Consts.Schema1.Namespaces.XPath10)
                                {
                                    throw new Exception(string.Format(Properties.Resource.exc_unsupported_xpath_version, _xpathVersion));
                                }
                            }
                            reader.Read();
                        }
                        break;

                    case Consts.Schema1.TargetElement.Target:
                        _target = new TargetElementReadWrite(reader, schemaVersion);
                        break;

                    case Consts.Schema1.RuleElement.Rule:
                        _rules.Add(new RuleElementReadWrite(reader, schemaVersion));
                        break;

                    case Consts.Schema1.PolicyElement.Obligations:
                        // Read all the obligations
                        while (reader.Read())
                        {
                            switch (reader.LocalName)
                            {
                            case Consts.Schema1.ObligationElement.Obligation:
                                _obligations.Add(new ObligationElementReadWrite(reader, schemaVersion));
                                break;
                            }
                            if (reader.LocalName == Consts.Schema1.ObligationsElement.Obligations &&
                                reader.NodeType == XmlNodeType.EndElement)
                            {
                                reader.Read();
                                break;
                            }
                        }
                        break;

                    case Consts.Schema2.PolicyElement.CombinerParameters:
                        // Read all the combiner parameters
                        while (reader.Read())
                        {
                            switch (reader.LocalName)
                            {
                            case Consts.Schema2.CombinerParameterElement.CombinerParameter:
                                _combinerParameters.Add(new CombinerParameterElement(reader, schemaVersion));
                                break;
                            }
                            if (reader.LocalName == Consts.Schema2.PolicyElement.CombinerParameters &&
                                reader.NodeType == XmlNodeType.EndElement)
                            {
                                reader.Read();
                                break;
                            }
                        }
                        break;

                    case Consts.Schema2.PolicyElement.RuleCombinerParameters:
                        // Read all the rule parameters
                        while (reader.Read())
                        {
                            switch (reader.LocalName)
                            {
                            case Consts.Schema2.RuleCombinerParameterElement.RuleCombinerParameter:
                                _ruleCombinerParameters.Add(new RuleCombinerParameterElement(reader, schemaVersion));
                                break;
                            }
                            if (reader.LocalName == Consts.Schema2.PolicyElement.RuleCombinerParameters &&
                                reader.NodeType == XmlNodeType.EndElement)
                            {
                                reader.Read();
                                break;
                            }
                        }
                        break;

                    case Consts.Schema2.PolicyElement.VariableDefinition:
                        var variable = new VariableDefinitionElement(reader, schemaVersion);
                        _variableDefinitions.Add(variable.Id, variable);
                        break;
                    }
                    if (reader.LocalName == Consts.Schema1.PolicyElement.Policy &&
                        reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                }
            }
            else
            {
                throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
            }
        }