示例#1
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="request"></param>
		public Request( con.RequestElementReadWrite request )
		{
			_request = request;

			this.Text = "Request";
			this.SelectedImageIndex = 1;
			this.ImageIndex = 1;

			if( _request.Action != null )
			{
				this.Nodes.Add( new Action( _request.Action ) );
			}
			if( _request.Environment != null )
			{
				this.Nodes.Add( new Environment( _request.Environment ) ) ;
			}
			if( _request.Resources != null )
			{
				foreach( con.ResourceElementReadWrite resource in _request.Resources )
				{
					this.Nodes.Add( new Resource( resource ) );
				}
			}
			if( _request.Subjects != null )
			{
				foreach( con.SubjectElementReadWrite subject in _request.Subjects )
				{
					this.Nodes.Add( new Subject( subject ) );
				}
			}
			this.ExpandAll();
		}
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        public Request(con.RequestElementReadWrite request)
        {
            _request = request;

            this.Text = "Request";
            this.SelectedImageIndex = 1;
            this.ImageIndex         = 1;

            if (_request.Action != null)
            {
                this.Nodes.Add(new Action(_request.Action));
            }
            if (_request.Environment != null)
            {
                this.Nodes.Add(new Environment(_request.Environment));
            }
            if (_request.Resources != null)
            {
                foreach (con.ResourceElementReadWrite resource in _request.Resources)
                {
                    this.Nodes.Add(new Resource(resource));
                }
            }
            if (_request.Subjects != null)
            {
                foreach (con.SubjectElementReadWrite subject in _request.Subjects)
                {
                    this.Nodes.Add(new Subject(subject));
                }
            }
            this.ExpandAll();
        }
        /// <summary>
        /// Creates a new ContextDocumentReadWrite using the XmlReader instance provided.
        /// </summary>
        /// <param name="reader">The XmlReader instance positioned at the begining of the document.</param>
        /// <param name="schemaVersion">The schema used to validate this context document.</param>
        public ContextDocumentReadWrite(XmlReader reader, XacmlVersion schemaVersion)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            // Search for the first element.
            while (reader.Read() && reader.NodeType != XmlNodeType.Element)
            {
            }

            // Keep the contents of the context document.
            // HACK: Due to XPath validation the document must be readed twice, the first time to load the instance
            // and the second one to keep a document to execute XPath sentences.
            _xmlString = reader.ReadOuterXml();

            // Read the contents in a new reader.
#if NET20
            StringReader sreader = new StringReader(_xmlString);
#endif

            // Prepare the validation.

#if NET20
            ValidationEventHandler validationHandler = vreader_ValidationEventHandler;
            XmlReaderSettings      settings          = new XmlReaderSettings {
                ValidationType = ValidationType.Schema
            };
            settings.ValidationEventHandler += validationHandler;
            XmlReader vreader = null;
#endif
            switch (schemaVersion)
            {
            case XacmlVersion.Version10:
            case XacmlVersion.Version11:
            {
                Stream policySchemaStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(pol.PolicyDocument.Xacml10PolicySchemaResourceName);
                Stream contextSchemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml10ContextSchemaResourceName);
#if NET10
                vreader.Schemas.Add(PolicySchema1.Namespaces.Policy, new XmlTextReader(policySchemaStream));
                vreader.Schemas.Add(PolicySchema1.Namespaces.Context, new XmlTextReader(contexSchemaStream));
#endif
#if NET20
                if (_compiledSchemas11 == null)
                {
                    _compiledSchemas11 = new XmlSchemaSet();
                    _compiledSchemas11.Add(XmlSchema.Read(policySchemaStream, validationHandler));
                    _compiledSchemas11.Add(XmlSchema.Read(contextSchemaStream, validationHandler));
                    _compiledSchemas11.Compile();
                }
                settings.Schemas.Add(_compiledSchemas11);
#endif
                break;
            }

            case XacmlVersion.Version20:
            {
                Stream policySchemaStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(pol.PolicyDocumentReadWrite.Xacml20PolicySchemaResourceName);
                Stream contextSchemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml20ContextSchemaResourceName);

                if (_compiledSchemas20 == null)
                {
                    _compiledSchemas20 = new XmlSchemaSet();
                    if (policySchemaStream != null)
                    {
                        _compiledSchemas20.Add(XmlSchema.Read(policySchemaStream, validationHandler));
                    }
                    if (contextSchemaStream != null)
                    {
                        _compiledSchemas20.Add(XmlSchema.Read(contextSchemaStream, validationHandler));
                    }
                    _compiledSchemas20.Compile();
                }
                settings.Schemas.Add(_compiledSchemas20);

                break;
            }

            default:
                throw new ArgumentException(Resource.ResourceManager[Resource.MessageKey.exc_invalid_version_parameter_value], nameof(reader));
            }

#if NET20
            vreader = XmlReader.Create(sreader, settings);
#endif
            while (vreader.Read())
            {
                //Read all the namespaces and keep them in the _namespaces hashtable.
                if (vreader.HasAttributes)
                {
                    while (vreader.MoveToNextAttribute())
                    {
                        if (vreader.LocalName == PolicySchema1.Namespaces.XMLNS)
                        {
                            _namespaces.Add(vreader.Prefix, vreader.Value);
                        }
                        else if (vreader.Prefix == PolicySchema1.Namespaces.XMLNS)
                        {
                            _namespaces.Add(vreader.LocalName, vreader.Value);
                        }
                    }
                    vreader.MoveToElement();
                }
                switch (vreader.LocalName)
                {
                case ContextSchema.RequestElement.Request:
                    _request = new RequestElementReadWrite(vreader, schemaVersion);
                    break;

                case ContextSchema.ResponseElement.Response:
                    _response = new ResponseElement(vreader, schemaVersion);
                    break;
                }
            }
        }
示例#4
0
		private void CreateContextRequest( object sender, EventArgs args )
		{
			con.RequestElementReadWrite newRequest = new con.RequestElementReadWrite(null,null,null,null,XacmlVersion.Version11);
			Context contextNode = (Context)mainTree.SelectedNode;
			Request requestNode = new Request( newRequest );
			con.ContextDocumentReadWrite context = contextNode.ContextDefinition;

			context.Request = newRequest;
			contextNode.Nodes.Add( requestNode );
		}
        /// <summary>
        /// Creates a new ContextDocumentReadWrite using the XmlReader instance provided.
        /// </summary>
        /// <param name="reader">The XmlReader instance positioned at the begining of the document.</param>
        /// <param name="schemaVersion">The schema used to validate this context document.</param>
        public ContextDocumentReadWrite(XmlReader reader, XacmlVersion schemaVersion)
        {
            if (reader == null) throw new ArgumentNullException(nameof(reader));
            // Search for the first element.
            while (reader.Read() && reader.NodeType != XmlNodeType.Element)
            { }

            // Keep the contents of the context document.
            // HACK: Due to XPath validation the document must be readed twice, the first time to load the instance
            // and the second one to keep a document to execute XPath sentences.
            _xmlString = reader.ReadOuterXml();

            // Read the contents in a new reader.
#if NET20
            StringReader sreader = new StringReader(_xmlString);
#endif

            // Prepare the validation.

#if NET20
            ValidationEventHandler validationHandler = vreader_ValidationEventHandler;
            XmlReaderSettings settings = new XmlReaderSettings {ValidationType = ValidationType.Schema};
            settings.ValidationEventHandler += validationHandler;
            XmlReader vreader = null;
#endif
            switch (schemaVersion)
            {
                case XacmlVersion.Version10:
                case XacmlVersion.Version11:
                    {
                        Stream policySchemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(pol.PolicyDocument.Xacml10PolicySchemaResourceName);
                        Stream contextSchemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml10ContextSchemaResourceName);
#if NET10
					    vreader.Schemas.Add( PolicySchema1.Namespaces.Policy, new XmlTextReader( policySchemaStream ) );
					    vreader.Schemas.Add( PolicySchema1.Namespaces.Context, new XmlTextReader( contexSchemaStream ) );
#endif
#if NET20
                        if (_compiledSchemas11 == null)
                        {
                            _compiledSchemas11 = new XmlSchemaSet();
                            _compiledSchemas11.Add(XmlSchema.Read(policySchemaStream, validationHandler));
                            _compiledSchemas11.Add(XmlSchema.Read(contextSchemaStream, validationHandler));
                            _compiledSchemas11.Compile();
                        }
                        settings.Schemas.Add(_compiledSchemas11);
#endif
                        break;
                    }
                case XacmlVersion.Version20:
                    {
                        Stream policySchemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(pol.PolicyDocumentReadWrite.Xacml20PolicySchemaResourceName);
                        Stream contextSchemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Xacml20ContextSchemaResourceName);

                        if (_compiledSchemas20 == null)
                        {
                            _compiledSchemas20 = new XmlSchemaSet();
                            if (policySchemaStream != null)
                                _compiledSchemas20.Add(XmlSchema.Read(policySchemaStream, validationHandler));
                            if (contextSchemaStream != null)
                                _compiledSchemas20.Add(XmlSchema.Read(contextSchemaStream, validationHandler));
                            _compiledSchemas20.Compile();
                        }
                        settings.Schemas.Add(_compiledSchemas20);

                        break;
                    }
                default:
                    throw new ArgumentException(Resource.ResourceManager[Resource.MessageKey.exc_invalid_version_parameter_value], nameof(reader));
            }

#if NET20
            vreader = XmlReader.Create(sreader, settings);
#endif
            while (vreader.Read())
            {
                //Read all the namespaces and keep them in the _namespaces hashtable.
                if (vreader.HasAttributes)
                {
                    while (vreader.MoveToNextAttribute())
                    {
                        if (vreader.LocalName == PolicySchema1.Namespaces.XMLNS)
                        {
                            _namespaces.Add(vreader.Prefix, vreader.Value);
                        }
                        else if (vreader.Prefix == PolicySchema1.Namespaces.XMLNS)
                        {
                            _namespaces.Add(vreader.LocalName, vreader.Value);
                        }
                    }
                    vreader.MoveToElement();
                }
                switch (vreader.LocalName)
                {
                    case ContextSchema.RequestElement.Request:
                        _request = new RequestElementReadWrite(vreader, schemaVersion);
                        break;
                    case ContextSchema.ResponseElement.Response:
                        _response = new ResponseElement(vreader, schemaVersion);
                        break;
                }
            }
        }