Beispiel #1
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));
            }
        }
        /// <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));
            }
        }
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="variableDefinition">The variable definition in the policy document.</param>
 public VariableDefinition(VariableDefinitionElement variableDefinition)
 {
     _variableDefinition = variableDefinition;
 }