/// <summary>
		/// Creates a new PolicyIdReference using the XmlReader instance provided.
		/// </summary>
		/// <param name="reader">The XmlReader positioned at the PolicyIdReference element.</param>
		/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
		public PolicyIdReferenceElementReadWrite( XmlReader reader, XacmlVersion schemaVersion )
			: base( XacmlSchema.Policy, schemaVersion )
		{
            if (reader == null) throw new ArgumentNullException("reader");
			if( reader.LocalName == PolicySchema1.PolicyIdReferenceElement.PolicyIdReference && 
				ValidateSchema( reader, schemaVersion ) )
			{
				if( reader.HasAttributes )
				{
					// Load all the attributes
					while( reader.MoveToNextAttribute() )
					{
						if( reader.LocalName == PolicyReferenceElement.Version )
						{
							_version = reader.GetAttribute( PolicyReferenceElement.Version );
						}
						else if( reader.LocalName == PolicyReferenceElement.EarliestVersion )
						{
							_earliestVersion = reader.GetAttribute( PolicyReferenceElement.EarliestVersion );
						}
						else if( reader.LocalName == PolicyReferenceElement.LatestVersion )
						{
							_latestVersion = reader.GetAttribute( PolicyReferenceElement.LatestVersion );
						}					
					}
					reader.MoveToElement();
				}
				_policyIdReference = reader.ReadElementString();
			}
			else
			{
				throw new Exception( Resource.ResourceManager[ Resource.MessageKey.exc_invalid_node_name, reader.LocalName ] );
			}
		}
 /// <summary>
 /// Creates an instance of the SubjectAttributeDesignator using the provided XmlReader. It also calls the
 /// base class constructor specifying the XmlReader.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the SubjectAttributeDesignator node.</param>
 /// <param name="version">The version of the schema that was used to validate.</param>
 public SubjectAttributeDesignatorElement(XmlReader reader, XacmlVersion version)
     :
     base(reader, version)
 {
     if (reader == null) throw new ArgumentNullException("reader");
     _subjectCategory = reader.GetAttribute(PolicySchema1.SubjectAttributeDesignatorElement.SubjectCategory);
 }
		/// <summary>
		/// Creates a new instance of the Obligation class using the XmlReader instance provided.
		/// </summary>
		/// <param name="reader">The XmlReader positioned at the Obligation node.</param>
		/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
		public ObligationElementReadWrite( XmlReader reader, XacmlVersion schemaVersion )
			: base( XacmlSchema.Policy, schemaVersion )
		{
			if(reader != null)
			{
				if( reader.LocalName == PolicySchema1.ObligationElement.Obligation && 
					ValidateSchema( reader, schemaVersion ) )
				{
					_obligationId = reader.GetAttribute( PolicySchema1.ObligationElement.ObligationId );

					// Parses the Effect attribute value
					_fulfillOn = (Effect)Enum.Parse( 
						typeof(Effect), reader.GetAttribute( PolicySchema1.ObligationElement.FulfillOn ), false );

					// Read all the attribute assignments
					while( reader.Read() )
					{
						switch( reader.LocalName )
						{
							case PolicySchema1.ObligationElement.AttributeAssignment:
								_attributeAssignment.Add( new AttributeAssignmentElementReadWrite( reader, schemaVersion ) );
								break;
						}
						if( reader.LocalName == PolicySchema1.ObligationElement.Obligation && 
							reader.NodeType == XmlNodeType.EndElement )
						{
							break;
						}
					}
				}
			}
			else
				_obligationId = "[TODO]: Add Obligation ID";
		}
 /// <summary>
 /// Creates an instance of the ReadWriteAttributeAssignment using the provided values
 /// </summary>
 /// <param name="attributeId"></param>
 /// <param name="dataType"></param>
 /// <param name="contents"></param>
 /// <param name="version"></param>
 public AttributeAssignmentElementReadWrite(string attributeId, string dataType, string contents, XacmlVersion version) :
     base(XacmlSchema.Policy, version)
 {
     _attributeId = attributeId;
     _dataType = dataType;
     _contents = contents;
 }
 /// <summary>
 /// Creates a new TargetItem instance using the specified XmlReader instance provided, and the node names of 
 /// the "target item list" nodes which are provided by the derived class during construction. 
 /// </summary>
 /// <param name="reader">The XmlReader instance positioned at the "target item list" node.</param>
 /// <param name="itemsNodeName">The name of the "target item list" node.</param>
 /// <param name="anyItemNodeName">The name of the AnyXxxx node for this "target item list" node.</param>
 /// <param name="itemNodeName">The name of the "target item" node that can be defined within this "target 
 /// item list" node.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 protected TargetItemsBaseReadWrite(XmlReader reader, string itemsNodeName, string anyItemNodeName, string itemNodeName, XacmlVersion schemaVersion)
     : this(schemaVersion)
 {
     if (reader == null) throw new ArgumentNullException("reader");
     if (reader.LocalName == itemsNodeName && ValidateSchema(reader, schemaVersion))
     {
         while (reader.Read())
         {
             if (reader.LocalName == anyItemNodeName && ValidateSchema(reader, schemaVersion))
             {
                 _anyItem = true;
             }
             else if (reader.LocalName == itemNodeName && ValidateSchema(reader, schemaVersion))
             {
                 _items.Add((TargetItemBaseReadWrite)CreateTargetItem(reader));
             }
             else if (reader.LocalName == itemsNodeName &&
                 reader.NodeType == XmlNodeType.EndElement)
             {
                 break;
             }
         }
     }
     else
     {
         throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
     }
 }
예제 #6
0
		/// <summary>
		/// Creates a new Policy with the specified arguments.
		/// </summary>
		/// <param name="id">The policy id.</param>
		/// <param name="description">THe policy description.</param>
		/// <param name="target">THe policy target.</param>
		/// <param name="rules">THe rules for this policy.</param>
		/// <param name="ruleCombiningAlgorithm">THe rule combining algorithm.</param>
		/// <param name="obligations">The Obligations for this policy.</param>
		/// <param name="xpathVersion">The XPath version supported.</param>
		/// <param name="combinerParameters">The combiner parameters in this policy.</param>
		/// <param name="ruleCombinerParameters">The rule parameters in this policy.</param>
		/// <param name="variableDefinitions">The variable definitions of this policy.</param>
		/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
		public PolicyElement( string id, string description, TargetElementReadWrite target, RuleReadWriteCollection rules, 
			string ruleCombiningAlgorithm, ObligationReadWriteCollection obligations, string xpathVersion, ArrayList combinerParameters, 
			ArrayList ruleCombinerParameters, IDictionary variableDefinitions, XacmlVersion schemaVersion )
			: base( id, description, target, rules, ruleCombiningAlgorithm, obligations, xpathVersion, 
			combinerParameters, ruleCombinerParameters, variableDefinitions, schemaVersion )
		{
		}
예제 #7
0
 /// <summary>
 /// 根据给定的版本号验证给定的模式。
 /// </summary>
 /// <param name="reader">用于读取命名空间</param>
 /// <param name="version">用于验证版本号</param>
 /// <returns><c>true</c>, 如果命名空间正确</returns>
 protected bool ValidateSchema(XmlReader reader, XacmlVersion version)
 {
     if (reader == null) throw new ArgumentNullException("reader");
     switch (_schema)
     {
         case XacmlSchema.Policy:
             switch (version)
             {
                 case XacmlVersion.Version10:
                 case XacmlVersion.Version11:
                     return (reader.NamespaceURI == Consts.Schema1.Namespaces.Policy);
                 case XacmlVersion.Version20:
                     return (reader.NamespaceURI == Consts.Schema2.Namespaces.Policy);
                 default:
                     throw new EvaluationException("意外的版本号" + version);
             }
             break;
         case XacmlSchema.Context:
             switch (version)
             {
                 case XacmlVersion.Version10:
                 case XacmlVersion.Version11:
                     return (reader.NamespaceURI == Consts.Schema1.Namespaces.Context);
                 case XacmlVersion.Version20:
                     return (reader.NamespaceURI == Consts.Schema2.Namespaces.Context);
                 default:
                     throw new EvaluationException("意外的版本号" + version);
             }
             break;
         default:
             throw new EvaluationException("意外的模式" + _schema);
     }
 }
예제 #8
0
 /// <summary>
 /// Creates a response using the XmlReader instance provided.
 /// </summary>
 /// <remarks>This method is only provided for testing purposes, because it's easy to run the ConformanceTests
 /// comparing the expected response with the response created.</remarks>
 /// <param name="reader">The XmlReader positioned at the Response node.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public ResponseElement(XmlReader reader, XacmlVersion schemaVersion)
     : base(XacmlSchema.Context, schemaVersion)
 {
     if (reader == null) throw new ArgumentNullException("reader");
     _results = new ResultCollection();
     if (reader.LocalName == Consts.ContextSchema.ResponseElement.Response)
     {
         while (reader.Read())
         {
             switch (reader.LocalName)
             {
                 case Consts.ContextSchema.ResultElement.Result:
                     _results.Add(new ResultElement(reader, schemaVersion));
                     break;
             }
             if (reader.LocalName == Consts.ContextSchema.ResponseElement.Response &&
                 reader.NodeType == XmlNodeType.EndElement)
             {
                 break;
             }
         }
     }
     else
     {
         throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
     }
 }
예제 #9
0
 /// <summary>
 /// Creates a Status using the supplied values.
 /// </summary>
 /// <param name="statusCode">The status code.</param>
 /// <param name="statusMessage">The status message.</param>
 /// <param name="statusDetail">The status detail.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public StatusElement(StatusCodeElement statusCode, string statusMessage, string statusDetail, XacmlVersion schemaVersion)
     : base(XacmlSchema.Context, schemaVersion)
 {
     StatusCode = statusCode;
     _statusMessage = statusMessage;
     _statusDetail = statusDetail;
 }
예제 #10
0
		/// <summary>
		/// Creates a StatusCode using an XmlReader instance provided.
		/// </summary>
		/// <param name="reader">The XmlReader instance positioned at the StatusCode node.</param>
		/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
		public StatusCodeElement( XmlReader reader, XacmlVersion schemaVersion )
			: base( XacmlSchema.Context, schemaVersion )
		{
            if (reader == null) throw new ArgumentNullException("reader");
			if( reader.LocalName == ContextSchema.StatusElement.StatusCode )
			{
				_value = reader.GetAttribute( ContextSchema.StatusElement.Value );
				if( !reader.IsEmptyElement )
				{
					while( reader.Read() )
					{
						switch( reader.LocalName )
						{
							case ContextSchema.StatusElement.StatusCode:
								_statusCode = new StatusCodeElement( reader, schemaVersion );
								break;
						}
						if( reader.LocalName == ContextSchema.StatusElement.StatusCode && 
							reader.NodeType == XmlNodeType.EndElement )
						{
							break;
						}
					}
				}
			}
			else
			{
				throw new Exception( Resource.ResourceManager[ Resource.MessageKey.exc_invalid_node_name, reader.LocalName ] );
			}
		}
예제 #11
0
 /// <summary>
 /// Creates a new Status class using the XmlReade instance provided.
 /// </summary>
 /// <param name="reader">The XmlReader instance positioned at the Status node.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public StatusElement(XmlReader reader, XacmlVersion schemaVersion)
     : base(XacmlSchema.Context, schemaVersion)
 {
     if (reader == null) throw new ArgumentNullException("reader");
     if (reader.LocalName != Consts.ContextSchema.StatusElement.Status) return;
     while (reader.Read())
     {
         switch (reader.LocalName)
         {
             case Consts.ContextSchema.StatusElement.StatusCode:
                 StatusCode = new StatusCodeElement(reader, schemaVersion);
                 break;
             case Consts.ContextSchema.StatusElement.StatusMessage:
                 _statusMessage = reader.ReadElementString();
                 break;
             case Consts.ContextSchema.StatusElement.StatusDetail:
                 _statusDetail = reader.ReadElementString();
                 break;
         }
         if (reader.LocalName == Consts.ContextSchema.StatusElement.Status &&
             reader.NodeType == XmlNodeType.EndElement)
         {
             break;
         }
     }
 }
 /// <summary>
 /// Creates an instance of the AttributeValue class using the XmlReader and the name of the node that 
 /// defines the AttributeValue. 
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the node AttributeValue.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public AttributeValueElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     if (reader == null) throw new ArgumentNullException("reader");
     if (reader.LocalName == Consts.Schema1.AttributeValueElement.AttributeValue &&
         ValidateSchema(reader, schemaVersion))
     {
         if (reader.HasAttributes)
         {
             // Load all the attributes
             while (reader.MoveToNextAttribute())
             {
                 if (reader.LocalName == Consts.Schema1.AttributeValueElement.DataType)
                 {
                     _dataType = reader.GetAttribute(Consts.Schema1.AttributeValueElement.DataType);
                 }
             }
             reader.MoveToElement();
         }
         // Load the node contents
         _contents = reader.ReadInnerXml();
     }
     else
     {
         throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
     }
 }
		/// <summary>
		/// Creates an instance of the ReadWriteAttributeAssignment using the provided XmlReader.
		/// </summary>
		/// <param name="reader">The XmlReader positioned at the AttributeAssignament node.</param>
		/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
		public AttributeAssignmentElementReadWrite( XmlReader reader, XacmlVersion schemaVersion )
			: base( XacmlSchema.Policy, schemaVersion )
		{
            if (reader == null) throw new ArgumentNullException("reader");
			if( reader.LocalName == PolicySchema1.ObligationElement.AttributeAssignment && 
				ValidateSchema( reader, schemaVersion ) )
			{
				if( reader.HasAttributes )
				{
					// Load all the attributes
					while( reader.MoveToNextAttribute() )
					{
						if( reader.LocalName == PolicySchema1.AttributeValueElement.DataType )
						{
							_dataType = reader.GetAttribute( PolicySchema1.AttributeValueElement.DataType );
						}
						else if( reader.LocalName == PolicySchema1.AttributeAssignmentElement.AttributeId )
						{
							_attributeId = reader.GetAttribute( PolicySchema1.AttributeAssignmentElement.AttributeId );
						}
					}
					reader.MoveToElement();
				}

				// Load the node contents
				_contents = reader.ReadInnerXml();
			}
			else
			{
				throw new Exception( Resource.ResourceManager[ Resource.MessageKey.exc_invalid_node_name, reader.LocalName ] );
			}
		}
예제 #14
0
 /// <summary>
 /// Creates a new Request using the XmlReader instance provided.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the Request node.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public RequestElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
     : base(XacmlSchema.Context, schemaVersion)
 {
     if (reader == null) throw new ArgumentNullException("reader");
     if (reader.LocalName == Consts.ContextSchema.RequestElement.Request)
     {
         while (reader.Read())
         {
             switch (reader.LocalName)
             {
                 case Consts.ContextSchema.RequestElement.Subject:
                     _subjects.Add(new SubjectElementReadWrite(reader, schemaVersion));
                     break;
                 case Consts.ContextSchema.RequestElement.Resource:
                     _resources.Add(new ResourceElementReadWrite(reader, schemaVersion));
                     break;
                 case Consts.ContextSchema.RequestElement.Action:
                     _action = new ActionElementReadWrite(reader, schemaVersion);
                     break;
                 case Consts.ContextSchema.RequestElement.Environment:
                     _environment = new EnvironmentElementReadWrite(reader, schemaVersion);
                     break;
             }
         }
     }
     else
     {
         throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
     }
 }
예제 #15
0
		/// <summary>
		/// Creates a new TargetItem instance using the specified XmlReader instance provided, and the node names of 
		/// the "target item list" nodes which are provided by the derived class during construction. 
		/// </summary>
		/// <param name="reader">The XmlReader instance positioned at the "target item list" node.</param>
		/// <param name="itemsNodeName">The name of the "target item list" node.</param>
		/// <param name="anyItemNodeName">The name of the AnyXxxx node for this "target item list" node.</param>
		/// <param name="itemNodeName">The name of the "target item" node that can be defined within this "target 
		/// item list" node.</param>
		/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
		protected TargetItemsBase( XmlReader reader, string itemsNodeName, string anyItemNodeName, string itemNodeName, XacmlVersion schemaVersion )
			: base( schemaVersion )
		{
            if (reader == null) throw new ArgumentNullException("reader");
			if( reader.LocalName == itemsNodeName && ValidateSchema( reader, schemaVersion ) )
			{
				while( reader.Read() )
				{
					if( reader.LocalName == anyItemNodeName && ValidateSchema( reader, schemaVersion ) )
					{
						base.IsAny = true;
					}
					else if( reader.LocalName == itemNodeName && ValidateSchema( reader, schemaVersion ) )
					{
						base.ItemsList.Add( (TargetItemBase)CreateTargetItem( reader ) );
					}
					else if( reader.LocalName == itemsNodeName && 
						reader.NodeType == XmlNodeType.EndElement )
					{
						break;
					}
				}
			}
			else
			{
				throw new Exception( Resource.ResourceManager[ Resource.MessageKey.exc_invalid_node_name, reader.LocalName ] );
			}
		}
예제 #16
0
 /// <summary>
 /// Creates an instance of a TargetMatchBase with the values specified.
 /// </summary>
 /// <param name="matchId">The match id</param>
 /// <param name="attributeValue">The attribute value instance.</param>
 /// <param name="attributeReference">An attribute reference instance.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 protected TargetMatchBaseReadWrite(string matchId, AttributeValueElementReadWrite attributeValue, AttributeReferenceBase attributeReference, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     _id = matchId;
     _attributeValue = attributeValue;
     _attributeReference = attributeReference;
 }
예제 #17
0
        /// <summary>
        /// Creates an instance of the ApplyBase using the XmlReader positioned in the node and the node name
        /// specifyed by the derived class in the constructor.
        /// </summary>
        /// <param name="reader">The XmlReader positioned at the "nodeName" node.</param>
        /// <param name="nodeName">The name of the node specifies by the derived class.</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        protected ApplyBaseReadWrite(XmlReader reader, string nodeName, XacmlVersion schemaVersion)
            : base(XacmlSchema.Policy, schemaVersion)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (reader.LocalName == nodeName &&
                    ValidateSchema(reader, schemaVersion))
            {
                // Get the id of function. It will be resolved in evaluation time.
                _functionId = reader.GetAttribute(Consts.Schema1.ConditionElement.FunctionId);

                while (reader.Read())
                {
                    switch (reader.LocalName)
                    {
                        case Consts.Schema1.ApplyElement.Apply:
                            // Must validate if the Apply node is not an EndElement because there is a child node
                            // with the same name as the parent node.
                            if (!reader.IsEmptyElement && reader.NodeType != XmlNodeType.EndElement)
                            {
                                _arguments.Add(new ApplyElement(reader, schemaVersion));
                            }
                            break;
                        case Consts.Schema1.FunctionElement.Function:
                            _arguments.Add(new FunctionElementReadWrite(reader, schemaVersion));
                            break;
                        case Consts.Schema1.AttributeValueElement.AttributeValue:
                            _arguments.Add(new AttributeValueElementReadWrite(reader, schemaVersion));
                            break;
                        case Consts.Schema1.SubjectAttributeDesignatorElement.SubjectAttributeDesignator:
                            _arguments.Add(new SubjectAttributeDesignatorElement(reader, schemaVersion));
                            break;
                        case Consts.Schema1.ResourceAttributeDesignatorElement.ResourceAttributeDesignator:
                            _arguments.Add(new ResourceAttributeDesignatorElement(reader, schemaVersion));
                            break;
                        case Consts.Schema1.ActionAttributeDesignatorElement.ActionAttributeDesignator:
                            _arguments.Add(new ActionAttributeDesignatorElement(reader, schemaVersion));
                            break;
                        case Consts.Schema1.EnvironmentAttributeDesignatorElement.EnvironmentAttributeDesignator:
                            _arguments.Add(new EnvironmentAttributeDesignatorElement(reader, schemaVersion));
                            break;
                        case Consts.Schema1.AttributeSelectorElement.AttributeSelector:
                            _arguments.Add(new AttributeSelectorElement(reader, schemaVersion));
                            break;
                        case Consts.Schema2.VariableReferenceElement.VariableReference:
                            _arguments.Add(new VariableReferenceElement(reader, schemaVersion));
                            break;
                    }
                    if (reader.LocalName == nodeName &&
                        reader.NodeType == XmlNodeType.EndElement)
                    {
                        reader.Read();
                        break;
                    }
                }
            }
        }
예제 #18
0
		/// <summary>
		/// Creates a new Request using the parameters specified.
		/// </summary>
		/// <param name="subjects">The subjects list.</param>
		/// <param name="resources">The resource requested</param>
		/// <param name="action">The action requested.</param>
		/// <param name="environment">Any environment attribute part of the request.</param>
		/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
		public RequestElementReadWrite( SubjectReadWriteCollection subjects, ResourceReadWriteCollection resources, ActionElementReadWrite action, EnvironmentElementReadWrite environment, XacmlVersion schemaVersion )
			: base( XacmlSchema.Context, schemaVersion )
		{
			_subjects = subjects;
			_resources = resources;
			_action = action;
			_environment = environment;
		}
예제 #19
0
		/// <summary>
		/// Creates a new Target with the specified agumetns.
		/// </summary>
		/// <param name="resources">The resources for this target.</param>
		/// <param name="subjects">The subjects for this target.</param>
		/// <param name="actions">The actions for this target.</param>
		/// <param name="environments">The environments for this target.</param>
		/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
		public TargetElementReadWrite(ResourcesElementReadWrite resources, SubjectsElementReadWrite subjects, ActionsElementReadWrite actions, EnvironmentsElementReadWrite environments, XacmlVersion schemaVersion)
			: base(XacmlSchema.Policy, schemaVersion)
		{
			_resources = resources;
			_subjects = subjects;
			_actions = actions;
			_environments = environments;
		}
 /// <summary>
 /// Creates an instance of the element, with the provided values
 /// </summary>
 /// <param name="policyIdReference"></param>
 /// <param name="version"></param>
 /// <param name="earliestVersion"></param>
 /// <param name="latestVersion"></param>
 /// <param name="schemaVersion"></param>
 public PolicyIdReferenceElementReadWrite(string policyIdReference, string version, string earliestVersion, string latestVersion,
     XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     _policyIdReference = policyIdReference;
     _version = version;
     _earliestVersion = earliestVersion;
     _latestVersion = latestVersion;
 }
예제 #21
0
        /// <summary>
        /// Creates a new Target using the XmlReader instance provided.
        /// </summary>
        /// <param name="reader">The XmlReader positioned at the Target node.</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        public TargetElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
            : base(XacmlSchema.Policy, schemaVersion)
        {
            if (reader == null) throw new ArgumentNullException("reader");
            if (reader.LocalName == Consts.Schema1.TargetElement.Target &&
                ValidateSchema(reader, schemaVersion))
            {
                if (!reader.IsEmptyElement)
                {
                    while (reader.Read())
                    {
                        switch (reader.LocalName)
                        {
                            case Consts.Schema1.TargetElement.Subjects:
                                _subjects = new SubjectsElementReadWrite(reader, schemaVersion);
                                break;
                            case Consts.Schema1.TargetElement.Resources:
                                _resources = new ResourcesElementReadWrite(reader, schemaVersion);
                                break;
                            case Consts.Schema1.TargetElement.Actions:
                                _actions = new ActionsElementReadWrite(reader, schemaVersion);
                                break;
                            case Consts.Schema2.TargetElement.Environments:
                                _environments = new EnvironmentsElementReadWrite(reader, schemaVersion);
                                break;
                        }
                        if (reader.LocalName == Consts.Schema1.TargetElement.Target &&
                            reader.NodeType == XmlNodeType.EndElement)
                        {
                            break;
                        }
                    }
                }

                // V2 does not have the All(TargetItem) element, and a missing (TargetItem)s element is considered as
                // Any(TargetItem). In order to mantain the code for both versions 
                if (schemaVersion == XacmlVersion.Version20)
                {
                    if (_subjects == null)
                    {
                        _subjects = new SubjectsElementReadWrite(true, new TargetItemReadWriteCollection(), schemaVersion);
                    }
                    if (_resources == null)
                    {
                        _resources = new ResourcesElementReadWrite(true, new TargetItemReadWriteCollection(), schemaVersion);
                    }
                    if (_actions == null)
                    {
                        _actions = new ActionsElementReadWrite(true, new TargetItemReadWriteCollection(), schemaVersion);
                    }
                }
            }
            else
            {
                throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
            }
        }
예제 #22
0
 /// <summary>
 /// Creates a new Rule using the provided argument values.
 /// </summary>
 /// <param name="id">The rule id.</param>
 /// <param name="description">The rule description.</param>
 /// <param name="target">The target instance for this rule.</param>
 /// <param name="condition">The condition for this rule.</param>
 /// <param name="effect">The effect of this rule.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public RuleElementReadWrite(string id, string description, TargetElementReadWrite target, ConditionElementReadWrite condition, Effect effect, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     _id = id;
     _description = description;
     _target = target;
     _condition = condition;
     _effect = effect;
 }
 /// <summary>
 /// Creates an Attribute with the values specified.
 /// </summary>
 /// <param name="attributeId">The attribute id.</param>
 /// <param name="dataType">The data type id.</param>
 /// <param name="issuer">The issuer name.</param>
 /// <param name="issueInstant">The issuer instant.</param>
 /// <param name="value">The value of the attribute.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public AttributeElementReadWrite(string attributeId, string dataType, string issuer, string issueInstant, string value, XacmlVersion schemaVersion)
     : base(XacmlSchema.Context, schemaVersion)
 {
     _attributeId = attributeId;
     _dataType = dataType;
     _issuer = issuer;
     _issueInstant = issueInstant;
     _attributeValues.Add(new AttributeValueElementReadWrite(value, schemaVersion));
 }
예제 #24
0
        /// <summary>
        /// Creates an instace of the ContextDocument using the stream provided with an Xml document.
        /// </summary>
        /// <param name="xmlDocument">The stream containing an Xml document.</param>
        /// <param name="schemaVersion">The version of the schema used to validate the document.</param>
        /// <returns>An instance of a ContextDocument.</returns>
        public static ContextDocumentReadWrite LoadContextDocument(Stream xmlDocument, XacmlVersion schemaVersion)
        {
            if (xmlDocument == null)
            {
                throw new ArgumentNullException("xmlDocument");
            }

            return LoadContextDocument(new XmlTextReader(new StreamReader(xmlDocument)), schemaVersion);
        }
예제 #25
0
        /// <summary>
        /// Creates an instace of the PolicyDocument using the stream provided with an Xml document.
        /// </summary>
        /// <param name="xmlDocument">The stream containing an Xml document.</param>
        /// <param name="version">The version of the schema that will be used to validate.</param>
        /// <param name="access">The type of PolicyDocument</param>
        /// <returns>An instance of a PolicyDocument.</returns>
        public static PolicyDocumentReadWrite LoadPolicyDocument(Stream xmlDocument, XacmlVersion version, DocumentAccess access)
        {
            // Validate the parameters
            if (xmlDocument == null)
            {
                throw new ArgumentNullException("xmlDocument");
            }

            return LoadPolicyDocument(new StreamReader(xmlDocument), version, access);
        }
예제 #26
0
 /// <summary>
 /// Creates an instance of the AttributeDesignator class with the XmlReader instance. The base class 
 /// constructor is also called using the XmlReader.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the begining of the AttributeDesignator node.</param>
 /// <param name="version">The version of the schema that was used to validate.</param>
 protected AttributeDesignatorBase(XmlReader reader, XacmlVersion version)
     : base(reader, version)
 {
     if (reader == null) throw new ArgumentNullException("reader");
     _attributeId = reader.GetAttribute(Consts.Schema1.AttributeDesignatorElement.AttributeId);
     _issuer = reader.GetAttribute(Consts.Schema1.AttributeDesignatorElement.Issuer);
     if (_issuer == null)
     {
         _issuer = String.Empty;
     }
 }
 /// <summary>
 /// Creates a new policySet using the arguments provided.
 /// </summary>
 /// <param name="id">The policy set id.</param>
 /// <param name="description">The description of the policy set.</param>
 /// <param name="target">The target for this policy set.</param>
 /// <param name="policies">All the policies inside this policy set.</param>
 /// <param name="policyCombiningAlgorithm">The policy combining algorithm for this policy set.</param>
 /// <param name="obligations">The obligations.</param>
 /// <param name="xpathVersion">The XPath version supported.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public PolicySetElementReadWrite(string id, string description, TargetElementReadWrite target, ArrayList policies, string policyCombiningAlgorithm,
     ObligationReadWriteCollection obligations, string xpathVersion, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     _id = id;
     _description = description;
     _target = target;
     _policies = policies;
     _policyCombiningAlgorithm = policyCombiningAlgorithm;
     _obligations = obligations;
     _xpathVersion = xpathVersion;
 }
예제 #28
0
 /// <summary>
 /// Create a new Response using the Result list provided.
 /// </summary>
 /// <param name="results">The list of Results that will be contained in this Response.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public ResponseElement(IEnumerable<ResultElement> results, XacmlVersion schemaVersion)
     : base(XacmlSchema.Context, schemaVersion)
 {
     _results = new ResultCollection();
     if (results != null)
     {
         foreach (var result in results)
         {
             _results.Add(result);
         }
     }
 }
예제 #29
0
 /// <summary>
 /// Creates a new instance of the Function class using the XmlReader specified.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the Function node.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public FunctionElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     if (reader.LocalName == Consts.Schema1.FunctionElement.Function &&
         ValidateSchema(reader, schemaVersion))
     {
         _functionId = reader.GetAttribute(Consts.Schema1.FunctionElement.FunctionId);
     }
     else
     {
         throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
     }
 }
예제 #30
0
		/// <summary>
		/// Creates an instance of the AttributeSelector.
		/// </summary>
		/// <param name="reader">The XmlReader positioned at the AttributeSelector node.</param>
		/// <param name="version">The version of the schema that was used to validate.</param>
		public AttributeSelectorElement( XmlReader reader, XacmlVersion version ) 
			: base( reader, version )
		{
			if( reader.LocalName == PolicySchema1.AttributeSelectorElement.AttributeSelector && 
				ValidateSchema( reader, version ) )
			{
				_requestContextPath = reader.GetAttribute( PolicySchema1.AttributeSelectorElement.RequestContextPath );
			}
			else
			{
				throw new Exception( Resource.ResourceManager[ Resource.MessageKey.exc_invalid_node_name, reader.LocalName ] );
			}
		}
예제 #31
0
 /// <summary>
 /// Creates a new instance of the VariableReference class using the XmlReader specified.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the VariableReference node.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public VariableReferenceElement(XmlReader reader, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (reader.LocalName == PolicySchema2.VariableReferenceElement.VariableReference &&
         ValidateSchema(reader, schemaVersion))
     {
         _variableId = reader.GetAttribute(PolicySchema2.VariableReferenceElement.VariableId);
     }
     else
     {
         throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, reader.LocalName]);
     }
 }
예제 #32
0
        /// <summary>
        /// Creates a new "target item" using the XmlReader instance provided and the node name for the derived
        /// "target item".
        /// </summary>
        /// <param name="reader">The XmlReader positioned in the "target item" node.</param>
        /// <param name="itemNodeName">The node if the "target item".</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        protected TargetItemBase(XmlReader reader, string itemNodeName, XacmlVersion schemaVersion)
            : this( schemaVersion )
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (reader.LocalName == itemNodeName)
            {
                // Find all the attributes in the node and notify the derived class about all of them.
                if (reader.HasAttributes)
                {
                    while (reader.MoveToNextAttribute())
                    {
                        AttributeFound(reader.NamespaceURI, reader.LocalName, reader.Value);
                    }
                    reader.MoveToElement();
                }

                // Read all the inner attributes and notify the derived class about any node found
                while (reader.Read())
                {
                    switch (reader.LocalName)
                    {
                    case ContextSchema.AttributeElement.Attribute:
                        _attributes.Add(new AttributeElementReadWrite(reader, schemaVersion));
                        break;

                    default:
                        NodeFound(reader);
                        break;
                    }

                    if (reader.LocalName == itemNodeName &&
                        reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                }
            }
            else
            {
                throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, reader.LocalName]);
            }
        }
예제 #33
0
        public static PolicyDocumentReadWrite Create(XmlReader reader, XacmlVersion version, DocumentAccess access)
        {
            // Validate the parameters
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (access.Equals(DocumentAccess.ReadOnly))
            {
                return(new PolicyDocument(reader, version));
            }
            else if (access.Equals(DocumentAccess.ReadWrite))
            {
                return(new PolicyDocumentReadWrite(reader, version));
            }
            return(null);
        }
예제 #34
0
 /// <summary>
 /// Creates a new ResourceContent using the provided XmlReader instance.
 /// </summary>
 /// <param name="reader">The XmlReader instance positioned at the ResourceContent node.</param>
 /// <param name="schemaVersion">The version of the schema used to validate this document.</param>
 public ResourceContentElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
     : base(XacmlSchema.Context, schemaVersion)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (reader.LocalName == ContextSchema.ResourceElement.ResourceContent)
     {
         // Load the node contents
         _contents  = reader.ReadInnerXml();
         _nameTable = reader.NameTable;
     }
     else
     {
         throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, reader.LocalName]);
     }
 }
 /// <summary>
 /// Creates a new ResourceContent using the provided XmlReader instance.
 /// </summary>
 /// <param name="reader">The XmlReader instance positioned at the ResourceContent node.</param>
 /// <param name="schemaVersion">The version of the schema used to validate this document.</param>
 public ResourceContentElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
     : base(XacmlSchema.Context, schemaVersion)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (reader.LocalName == Consts.ContextSchema.ResourceElement.ResourceContent)
     {
         // Load the node contents
         _contents  = reader.ReadInnerXml();
         _nameTable = reader.NameTable;
     }
     else
     {
         throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
     }
 }
예제 #36
0
 /// <summary>
 /// Creates an instance of the Resource class using the XmlReader instance provided.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the Subject node.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public ResourceElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
     : base(reader, ContextSchema.RequestElement.Resource, schemaVersion)
 {
     // Search for a hierarchical node mark
     foreach (AttributeElementReadWrite attribute in Attributes)
     {
         if (attribute.AttributeId == ContextSchema.ResourceScope.ResourceScopeAttributeId)
         {
             foreach (AttributeValueElementReadWrite element in attribute.AttributeValues)
             {
                 if (element.Contents != ContextSchema.ResourceScope.Immediate)
                 {
                     _resourceScope = (ResourceScope)Enum.Parse(typeof(ResourceScope), element.Contents, false);
                     return;
                 }
             }
         }
     }
 }
예제 #37
0
        /// <summary>
        /// Creates an instance of the AttributeReference using the XmlNode specified.
        /// </summary>
        /// <param name="reader">The XmlReader positioned at the attribute reference node.</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        protected AttributeReferenceBase(XmlReader reader, XacmlVersion schemaVersion)
            : base(XacmlSchema.Policy, schemaVersion)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            _dataType = reader.GetAttribute(PolicySchema1.AttributeSelectorElement.DataType);
            string mustBePresent = reader.GetAttribute(PolicySchema1.AttributeSelectorElement.MustBePresent);

            if (mustBePresent == null || mustBePresent.Length == 0)
            {
                _mustBePresent = false;
            }
            else
            {
                _mustBePresent = bool.Parse(mustBePresent);
            }
        }
예제 #38
0
        /// <summary>
        /// Creates an instance of the AttributeReference using the XmlNode specified.
        /// </summary>
        /// <param name="reader">The XmlReader positioned at the attribute reference node.</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        protected AttributeReferenceBase(XmlReader reader, XacmlVersion schemaVersion)
            : base(XacmlSchema.Policy, schemaVersion)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            DataType = reader.GetAttribute(Consts.Schema1.AttributeSelectorElement.DataType);
            string mustBePresent = reader.GetAttribute(Consts.Schema1.AttributeSelectorElement.MustBePresent);

            if (string.IsNullOrEmpty(mustBePresent))
            {
                MustBePresent = false;
            }
            else
            {
                MustBePresent = bool.Parse(mustBePresent);
            }
        }
예제 #39
0
        /// <summary>
        /// 根据给定的版本号验证给定的模式。
        /// </summary>
        /// <param name="reader">用于读取命名空间</param>
        /// <param name="version">用于验证版本号</param>
        /// <returns><c>true</c>, 如果命名空间正确</returns>
        protected bool ValidateSchema(XmlReader reader, XacmlVersion version)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            switch (_schema)
            {
            case XacmlSchema.Policy:
                switch (version)
                {
                case XacmlVersion.Version10:
                case XacmlVersion.Version11:
                    return(reader.NamespaceURI == Consts.Schema1.Namespaces.Policy);

                case XacmlVersion.Version20:
                    return(reader.NamespaceURI == Consts.Schema2.Namespaces.Policy);

                default:
                    throw new EvaluationException("意外的版本号" + version);
                }
                break;

            case XacmlSchema.Context:
                switch (version)
                {
                case XacmlVersion.Version10:
                case XacmlVersion.Version11:
                    return(reader.NamespaceURI == Consts.Schema1.Namespaces.Context);

                case XacmlVersion.Version20:
                    return(reader.NamespaceURI == Consts.Schema2.Namespaces.Context);

                default:
                    throw new EvaluationException("意外的版本号" + version);
                }
                break;

            default:
                throw new EvaluationException("意外的模式" + _schema);
            }
        }
예제 #40
0
        /// <summary>
        /// Creates a read-only instace of the PolicyDocument using the stream provided with an Xml document.
        /// </summary>
        /// <param name="xmlDocument">The stream containing an Xml document.</param>
        /// <returns>An instance of a PolicyDocument.</returns>
        public static PolicyDocumentReadWrite LoadPolicyDocument(Stream xmlDocument)
        {
            // Validate the parameters
            if (xmlDocument == null)
            {
                throw new ArgumentNullException("xmlDocument");
            }

            // Validate the stream
            if (!xmlDocument.CanSeek)
            {
                throw new ArgumentException(Properties.Resource.exc_invalid_stream_parameter_canseek, "xmlDocument");
            }

            // Read the document to determine the version of the schema used.
            XacmlVersion version = GetXacmlVersion(new StreamReader(xmlDocument));

            xmlDocument.Position = 0;

            return(LoadPolicyDocument(new StreamReader(xmlDocument), version));
        }
예제 #41
0
        /// <summary>
        /// Creates an instace of the PolicyDocument using the stream provided with an Xml document.
        /// </summary>
        /// <param name="xmlDocument">The stream containing an Xml document.</param>
        /// <param name="access">The type of PolicyDocument</param>
        /// <returns>An instance of a PolicyDocument.</returns>
        public static pol.PolicyDocumentReadWrite LoadPolicyDocument(Stream xmlDocument, DocumentAccess access)
        {
            // Validate the parameters
            if (xmlDocument == null)
            {
                throw new ArgumentNullException(nameof(xmlDocument));
            }

            // Validate the stream
            if (!xmlDocument.CanSeek)
            {
                throw new ArgumentException(Resource.ResourceManager[Resource.MessageKey.exc_invalid_stream_parameter_canseek], nameof(xmlDocument));
            }

            // Read the document to determine the version of the schema used.
            XacmlVersion version = GetXacmlVersion(new StreamReader(xmlDocument));

            xmlDocument.Position = 0;

            return(LoadPolicyDocument(new StreamReader(xmlDocument), version, access));
        }
예제 #42
0
        /// <summary>
        /// Creates a new instance of the Obligation class using the XmlReader instance provided.
        /// </summary>
        /// <param name="reader">The XmlReader positioned at the Obligation node.</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        public ObligationElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
            : base(XacmlSchema.Policy, schemaVersion)
        {
            if (reader != null)
            {
                if (reader.LocalName == Consts.Schema1.ObligationElement.Obligation &&
                    ValidateSchema(reader, schemaVersion))
                {
                    _obligationId = reader.GetAttribute(Consts.Schema1.ObligationElement.ObligationId);

                    // Parses the Effect attribute value
                    var attrValue = reader.GetAttribute(Consts.Schema1.ObligationElement.FulfillOn);
                    Debug.Assert(!string.IsNullOrEmpty(attrValue));
                    _fulfillOn = (Effect)Enum.Parse(
                        typeof(Effect), attrValue, false);

                    // Read all the attribute assignments
                    while (reader.Read())
                    {
                        switch (reader.LocalName)
                        {
                        case Consts.Schema1.ObligationElement.AttributeAssignment:
                            _attributeAssignment.Add(new AttributeAssignmentElementReadWrite(reader, schemaVersion));
                            break;
                        }
                        if (reader.LocalName == Consts.Schema1.ObligationElement.Obligation &&
                            reader.NodeType == XmlNodeType.EndElement)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                _obligationId = "[TODO]: Add Obligation Id";
            }
        }
 /// <summary>
 /// Creates a new PolicyIdReference using the XmlReader instance provided.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the PolicyIdReference element.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public PolicyIdReferenceElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (reader.LocalName == PolicySchema1.PolicyIdReferenceElement.PolicyIdReference &&
         ValidateSchema(reader, schemaVersion))
     {
         if (reader.HasAttributes)
         {
             // Load all the attributes
             while (reader.MoveToNextAttribute())
             {
                 if (reader.LocalName == PolicyReferenceElement.Version)
                 {
                     _version = reader.GetAttribute(PolicyReferenceElement.Version);
                 }
                 else if (reader.LocalName == PolicyReferenceElement.EarliestVersion)
                 {
                     _earliestVersion = reader.GetAttribute(PolicyReferenceElement.EarliestVersion);
                 }
                 else if (reader.LocalName == PolicyReferenceElement.LatestVersion)
                 {
                     _latestVersion = reader.GetAttribute(PolicyReferenceElement.LatestVersion);
                 }
             }
             reader.MoveToElement();
         }
         _policyIdReference = reader.ReadElementString();
     }
     else
     {
         throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, reader.LocalName]);
     }
 }
예제 #44
0
        /// <summary>
        /// Creates a new Request using the XmlReader instance provided.
        /// </summary>
        /// <param name="reader">The XmlReader positioned at the Request node.</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        public RequestElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
            : base(XacmlSchema.Context, schemaVersion)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (reader.LocalName == Consts.ContextSchema.RequestElement.Request)
            {
                while (reader.Read())
                {
                    switch (reader.LocalName)
                    {
                    case Consts.ContextSchema.RequestElement.Subject:
                        _subjects.Add(new SubjectElementReadWrite(reader, schemaVersion));
                        break;

                    case Consts.ContextSchema.RequestElement.Resource:
                        _resources.Add(new ResourceElementReadWrite(reader, schemaVersion));
                        break;

                    case Consts.ContextSchema.RequestElement.Action:
                        _action = new ActionElementReadWrite(reader, schemaVersion);
                        break;

                    case Consts.ContextSchema.RequestElement.Environment:
                        _environment = new EnvironmentElementReadWrite(reader, schemaVersion);
                        break;
                    }
                }
            }
            else
            {
                throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
            }
        }
예제 #45
0
        /// <summary>
        /// Creates an Attribute instance using the XmlReader provided.
        /// </summary>
        /// <param name="reader">The XmlReader instance positioned at the Attribute node.</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        public AttributeElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
            : base(XacmlSchema.Context, schemaVersion)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (reader.LocalName == Consts.ContextSchema.AttributeElement.Attribute &&
                ValidateSchema(reader, schemaVersion))
            {
                // Read the attributes
                _attributeId = reader.GetAttribute(Consts.ContextSchema.AttributeElement.AttributeId);
                _dataType    = reader.GetAttribute(Consts.ContextSchema.AttributeElement.DataType);
                _issuer      = reader.GetAttribute(Consts.ContextSchema.AttributeElement.Issuer);
                if (schemaVersion == XacmlVersion.Version10 || schemaVersion == XacmlVersion.Version11)
                {
                    _issueInstant = reader.GetAttribute(Consts.ContextSchema.AttributeElement.IssueInstant);
                }

                // Read the contents
                while (reader.Read())
                {
                    switch (reader.LocalName)
                    {
                    case Consts.ContextSchema.AttributeElement.AttributeValue:
                        _attributeValues.Add(new AttributeValueElementReadWrite(reader, schemaVersion));
                        break;
                    }
                    if (reader.LocalName == Consts.ContextSchema.AttributeElement.Attribute &&
                        reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                }
            }
        }
 /// <summary>
 /// Creates an instance of the Condition class using the specified XmlReader. The base class constructor is
 /// also called with the XmlReader and the node name of Condition node.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the Condition node.</param>
 /// <param name="version">The version of the schema that was used to validate.</param>
 public ConditionElementReadWrite(XmlReader reader, XacmlVersion version)
     : base(reader, PolicySchema1.RuleElement.Condition, version)
 {
 }
예제 #47
0
        /// <summary>
        /// Creates an instance of the ApplyBase using the XmlReader positioned in the node and the node name
        /// specifyed by the derived class in the constructor.
        /// </summary>
        /// <param name="reader">The XmlReader positioned at the "nodeName" node.</param>
        /// <param name="nodeName">The name of the node specifies by the derived class.</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        protected ApplyBaseReadWrite(XmlReader reader, string nodeName, XacmlVersion schemaVersion)
            : base(XacmlSchema.Policy, schemaVersion)
        {
            if (reader != null)
            {
                if (reader.LocalName == nodeName &&
                    ValidateSchema(reader, schemaVersion))
                {
                    // Get the id of function. It will be resolved in evaluation time.
                    _functionId = reader.GetAttribute(PolicySchema1.ConditionElement.FunctionId);

                    while (reader.Read())
                    {
                        switch (reader.LocalName)
                        {
                        case PolicySchema1.ApplyElement.Apply:
                            // Must validate if the Apply node is not an EndElement because there is a child node
                            // with the same name as the parent node.
                            if (!reader.IsEmptyElement && reader.NodeType != XmlNodeType.EndElement)
                            {
                                _arguments.Add(new ApplyElement(reader, schemaVersion));
                            }
                            break;

                        case PolicySchema1.FunctionElement.Function:
                            _arguments.Add(new FunctionElementReadWrite(reader, schemaVersion));
                            break;

                        case PolicySchema1.AttributeValueElement.AttributeValue:
                            _arguments.Add(new AttributeValueElementReadWrite(reader, schemaVersion));
                            break;

                        case PolicySchema1.SubjectAttributeDesignatorElement.SubjectAttributeDesignator:
                            _arguments.Add(new SubjectAttributeDesignatorElement(reader, schemaVersion));
                            break;

                        case PolicySchema1.ResourceAttributeDesignatorElement.ResourceAttributeDesignator:
                            _arguments.Add(new ResourceAttributeDesignatorElement(reader, schemaVersion));
                            break;

                        case PolicySchema1.ActionAttributeDesignatorElement.ActionAttributeDesignator:
                            _arguments.Add(new ActionAttributeDesignatorElement(reader, schemaVersion));
                            break;

                        case PolicySchema1.EnvironmentAttributeDesignatorElement.EnvironmentAttributeDesignator:
                            _arguments.Add(new EnvironmentAttributeDesignatorElement(reader, schemaVersion));
                            break;

                        case PolicySchema1.AttributeSelectorElement.AttributeSelector:
                            _arguments.Add(new AttributeSelectorElement(reader, schemaVersion));
                            break;

                        case PolicySchema2.VariableReferenceElement.VariableReference:
                            _arguments.Add(new VariableReferenceElement(reader, schemaVersion));
                            break;
                        }
                        if (reader.LocalName == nodeName &&
                            reader.NodeType == XmlNodeType.EndElement)
                        {
                            reader.Read();
                            break;
                        }
                    }
                }
            }
            else
            {
                throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, reader.LocalName]);
            }
        }
예제 #48
0
 /// <summary>
 /// Creates a ConditionElement with the given parameters
 /// </summary>
 /// <param name="functionId"></param>
 /// <param name="arguments"></param>
 /// <param name="schemaVersion"></param>
 protected ApplyBaseReadWrite(string functionId, IExpressionReadWriteCollection arguments, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     _functionId = functionId;
     _arguments  = arguments;
 }
예제 #49
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 PolicySetElement(XmlReader reader, XacmlVersion schemaVersion)
     : base(reader, schemaVersion)
 {
 }
예제 #50
0
 /// <summary>
 /// Creates a new policySet using the arguments provided.
 /// </summary>
 /// <param name="id">The policy set id.</param>
 /// <param name="description">The description of the policy set.</param>
 /// <param name="target">The target for this policy set.</param>
 /// <param name="policies">All the policies inside this policy set.</param>
 /// <param name="policyCombiningAlgorithm">The policy combining algorithm for this policy set.</param>
 /// <param name="obligations">The obligations.</param>
 /// <param name="xpathVersion">The XPath version supported.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public PolicySetElement(string id, string description, TargetElementReadWrite target, ArrayList policies, string policyCombiningAlgorithm,
                         ObligationReadWriteCollection obligations, string xpathVersion, XacmlVersion schemaVersion)
     : base(id, description, target, policies, policyCombiningAlgorithm, obligations, xpathVersion, schemaVersion)
 {
 }
예제 #51
0
 /// <summary>
 /// Creates a Subject using the specified arguments.
 /// </summary>
 /// <param name="subjectCategory">The subject category.</param>
 /// <param name="attributes">The attribute list.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public SubjectElementReadWrite(string subjectCategory, AttributeReadWriteCollection attributes, XacmlVersion schemaVersion)
     : base(attributes, schemaVersion)
 {
     _subjectCategory = subjectCategory;
 }
예제 #52
0
 /// <summary>
 /// Creates an instance of the TargetItem using the XmlReader instance provided and the node names provided
 /// by the extended class which allows this code being independent of the node names.
 /// </summary>
 /// <param name="reader">The XmlReader instance positioned at the "target item" node (Resource, Action or
 /// Subject).</param>
 /// <param name="targetItemNodeName">The name of the node that represents the "target item".</param>
 /// <param name="matchNodeName">The name of the node that represents the Match element for the "target item"
 /// being loaded.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 protected TargetItemBase(XmlReader reader, string targetItemNodeName, string matchNodeName, XacmlVersion schemaVersion)
     : base(reader, targetItemNodeName, matchNodeName, schemaVersion)
 {
 }
예제 #53
0
 /// <summary>
 /// Creates a new instance of TargetItem using the specified arguments.
 /// </summary>
 /// <param name="match">The collection of target item matchs.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 protected TargetItemBase(TargetMatchReadWriteCollection match, XacmlVersion schemaVersion)
     : base(match, schemaVersion)
 {
 }
예제 #54
0
 /// <summary>
 /// Private default constructor to avoid default instantiation.
 /// </summary>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 protected TargetItemBase(XacmlVersion schemaVersion)
     : base(schemaVersion)
 {
 }
예제 #55
0
 /// <summary>
 /// Creates a new Request using the XmlReader instance provided.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the Request node.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public RequestElement(XmlReader reader, XacmlVersion schemaVersion)
     : base(reader, schemaVersion)
 {
 }
예제 #56
0
 /// <summary>
 /// Creates a new Request using the parameters specified.
 /// </summary>
 /// <param name="subjects">The subjects list.</param>
 /// <param name="resources">The resource requested</param>
 /// <param name="action">The action requested.</param>
 /// <param name="environment">Any environment attribute part of the request.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public RequestElement(SubjectCollection subjects, ResourceCollection resources, ActionElement action, EnvironmentElement environment, XacmlVersion schemaVersion)
     : base(subjects, resources, action, environment, schemaVersion)
 {
 }
 /// <summary>
 /// Creates a ConditionElement with the given parameters
 /// </summary>
 /// <param name="functionId"></param>
 /// <param name="arguments"></param>
 /// <param name="schemaVersion"></param>
 public ConditionElementReadWrite(string functionId, IExpressionReadWriteCollection arguments, XacmlVersion schemaVersion)
     : base(functionId, arguments, schemaVersion)
 {
 }
예제 #58
0
 /// <summary>
 /// Creates an instance of the Actions class using the XmlReader instance provided.
 /// </summary>
 /// <remarks>
 /// This constructor is also calling the base class constructor specifying the XmlReader
 /// and the node names that defines this TargetItmes extended class.
 /// </remarks>
 /// <param name="reader">The XmlReader positioned at the Actions node.</param>
 /// <param name="version">The version of the schema that was used to validate.</param>
 public ActionsElementReadWrite(XmlReader reader, XacmlVersion version)
     : base(reader, Consts.Schema1.TargetElement.Actions, Consts.Schema1.ActionElement.AnyAction, Consts.Schema1.ActionElement.Action, version)
 {
 }
예제 #59
0
 /// <summary>
 /// Creates an instance of the Subject class using the XmlReader instance provided.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the Subject node.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public SubjectElementReadWrite(XmlReader reader, XacmlVersion schemaVersion) :
     base(reader, Consts.ContextSchema.RequestElement.Subject, schemaVersion)
 {
 }
 /// <summary>
 /// Creates a new AttributeValue using the data type and the contents provided.
 /// </summary>
 /// <param name="dataType">The data type id.</param>
 /// <param name="contents">The contents of the attribute value.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public AttributeValueElementReadWrite(string dataType, string contents, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     _dataType = dataType;
     _contents = contents;
 }